github.com/mithrandie/csvq@v1.18.1/docs/_posts/2006-01-02-variable.md (about) 1 --- 2 layout: default 3 title: Variable - Reference Manual - csvq 4 category: reference 5 --- 6 7 # Variable 8 9 A variable has a value. 10 11 Naming restriction: [Parsing - Statements]({{ '/reference/statement.html#parsing' | relative_url }}) 12 13 * [Declare Variable](#declare) 14 * [Substitute](#substitution) 15 * [SELECT INTO Statement](#select-into) 16 * [Dispose Variable](#dispose) 17 18 ## Declare Variable 19 {: #declare} 20 21 ```sql 22 variable_declaration 23 : DECLARE variable_assignment [, variable_assignment...]; 24 | VAR variable_assignment [, variable_assignment...]; 25 26 variable_assignment 27 : @varname 28 | @varname := initial_value 29 ``` 30 31 _initial_value_ 32 : [value]({{ '/reference/value.html' | relative_url }}) 33 34 35 _VAR_ is an alias of _DECLARE_. 36 37 If the _initial_value_ is not specified, then a null is set to the variable. 38 39 ## Substitute 40 {: #substitution} 41 42 A variable subsitution expression returns the substituted value. 43 44 ```sql 45 @varname := value 46 ``` 47 48 _value_ 49 : [value]({{ '/reference/value.html' | relative_url }}) 50 51 52 The variable substitution expression can be used in query statements such as update queries, select clauses in select queries. 53 If this expression exists in the other than select clauses of a select query, then no error occurs, but the order of the operation is not guranteed. 54 55 ## SELECT INTO Statement 56 {: #select-into} 57 58 SELECT INTO statement substitutes the result into the _variables_. 59 The result set of the query must be at most 1 record. 60 61 ``` 62 select_into_statement 63 : [with_clause] 64 select_clause 65 INTO variable [, variable ...] 66 [from_clause] 67 [where_clause] 68 [group_by_clause] 69 [having_clause] 70 [order_by_clause] 71 [limit_clause] 72 [offset_clause] 73 [FOR UPDATE] 74 ``` 75 76 _with_clause_ 77 : [With Clause]({{ '/reference/select-query.html#with_clause' | relative_url }}) 78 79 _select_clause_ 80 : [Select Clause]({{ '/reference/select-query.html#select_clause' | relative_url }}) 81 82 _variable_ 83 : [Variable]({{ '/reference/variable.html' | relative_url }}) 84 85 _from_clause_ 86 : [From Clause]({{ '/reference/select-query.html#from_clause' | relative_url }}) 87 88 _where_clause_ 89 : [Where Clause]({{ '/reference/select-query.html#where_clause' | relative_url }}) 90 91 _group_by_clause_ 92 : [Group By Clause]({{ '/reference/select-query.html#group_by_clause' | relative_url }}) 93 94 _having_clause_ 95 : [Having Clause]({{ '/reference/select-query.html#having_clause' | relative_url }}) 96 97 _order_by_clause_ 98 : [Order By Clause]({{ '/reference/select-query.html#order_by_clause' | relative_url }}) 99 100 _limit_clause_ 101 : [Limit Clause]({{ '/reference/select-query.html#limit_clause' | relative_url }}) 102 103 _offset_clause_ 104 : [Offset Clause]({{ '/reference/select-query.html#offset_clause' | relative_url }}) 105 106 ## Dispose Variable 107 {: #dispose} 108 109 ```sql 110 DISPOSE @varname; 111 ```