Assignment Statements
Variable Syntax
Figure 1 shows the syntax diagram for assigning a value to a variable.
The above syntax diagram is explained as follows:
- variable_name: specifies the name of a variable.
- value can be a value or an expression. The type of value must be compatible with the type of variable_name.
Variable Value Assignment Example
1 2 3 4 5 6 7 |
openGauss=# DECLARE emp_id INTEGER := 7788; --Assignment BEGIN emp_id := 5; --Assignment emp_id := 5*7784; END; / |
INTO/BULK COLLECT INTO
INTO and BULK COLLECT INTO store values returned by statements in a stored procedure to variables. BULK COLLECT INTO allows some or all returned values to be temporarily stored in an array.
Example
openGauss=# DECLARE my_id integer; BEGIN select id into my_id from customers limit 1; -- Assign a value. END; / openGauss=# DECLARE type id_list is varray(6) of customers.id%type; id_arr id_list; BEGIN select id bulk collect into id_arr from customers order by id DESC limit 20; -- Assign values in batches. END; /
BULK COLLECT INTO can only assign values to arrays in batches. Use LIMIT properly to prevent performance deterioration caused by excessive operations on data.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot