Source: https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/variable-definition/ Documentation version: v5.3.2 # Variables In GQL, a variable is an [identifier](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/overview/keywords-identifiers/) assigned to a collection of values of a specific data type. Variables can be used to hold values for data retrieval and manipulation within [procedures](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/procedures/create/). ## Categories of variables by role in pattern matching - Node variable: Represents nodes in the graph. For more information, see [Node patterns](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/patterns/node-patterns/). - Edge variable: Represents edges in the graph. For more information, see [Edge patterns](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/patterns/edge-patterns/). - Path variable: Represents paths in the graph. For more information, see [Path patterns](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/patterns/path-patterns/). ## Categories of variables by declaration types - Primitive value variable: Stores and manipulates values. For more information, see [Primitive value variables](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/variable-definition/value-variable/). - Aggregator value variable: Stores and aggregates values. For more information, see [Aggregator value variables](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/variable-definition/agg/). - Active set variable: Stores the set of nodes to be processed. For more information, see [Active set variables](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/variable-definition/active-set-variable/). - Graph variable: Stores and manipulates subgraphs. For more information, see [Graph variables](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/variable-definition/graph-variable/). - Table variable: Stores and manipulates tabular data. For more information, see [Table variables](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/variable-definition/table-variable/). - File variable: Defines file-based data sources and destinations. For more information, see [File variables](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/variable-definition/file-variable/). ### Variable scopes In GQL, curly brackets (`{}`) are used to create blocks in procedures. Blocks can be nested within each other, allowing for structured control flow and variable management. Variables can have two types of scopes depending on the block in which they are declared: - Block scoping - Global scoping #### Block scoping A block-scoped variable is declared inside a nested block and can only be accessed within that block. Note A block-scoped variable cannot have duplicate names as variables already declared in the outer block. Only primitive value variables support block scoping. #### Global scoping A global-scoped variable must be declared at the global scope, that is, at the top level of a procedure body, outside of any nested blocks. The following types of variables support global scoping: - Primitive value variables - Aggregator value variables, including global aggregator value variables and node-attached aggregator value variables - Active set variables - Graph variables - Table variables - File variables After declaration, node-attached aggregator value variables can be accessed for aggregation operations only within [`per_block`](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/match-compute/#per_block) clauses in match compute statements, whereas all other global-scoped variables can be accessed from any part of the procedure.