云数据库 GAUSSDB-赋值语句:示例

时间:2024-11-02 18:51:57

示例

openGauss=# DROP TABLE IF EXISTS customers;
openGauss=# CREATE TABLE customers(id int,name varchar);
openGauss=# INSERT INTO customers VALUES(1,'ab');
openGauss=# DECLARE
    my_id integer;
BEGIN
    select id into my_id from customers limit 1; -- 赋值
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; -- 批量赋值
END;
/

BULK COLLECT INTO 只支持批量赋值给数组。合理使用LIMIT字段避免操作过量数据导致性能下降。

support.huaweicloud.com/distributed-devg-v2-gaussdb/gaussdb-12-0519.html