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

时间:2024-11-02 18:49:41

示例

gaussdb=# DROP TABLE IF EXISTS customers;
gaussdb=# CREATE TABLE customers(id int,name varchar);
gaussdb=# INSERT INTO customers VALUES(1,'ab');
gaussdb=# DECLARE
    my_id integer;
BEGIN
    select id into my_id from customers limit 1; -- 赋值
END;
/
ANONYMOUS BLOCK EXECUTE
gaussdb=# DECLARE
    id_arr int[];
BEGIN
    select id bulk collect into id_arr from customers order by id DESC limit 20; -- 批量赋值
END;
/
ANONYMOUS BLOCK EXECUTE
gaussdb=#  DECLARE
    id_arr int[];
    sql_qry varchar2(150);
BEGIN
    sql_qry := 'SELECT id FROM customers ORDER BY id DESC LIMIT 20';
    EXECUTE IMMEDIATE sql_qry BULK COLLECT INTO id_arr; -- 批量赋值
END;
/
ANONYMOUS BLOCK EXECUTE
support.huaweicloud.com/distributed-devg-v8-gaussdb/gaussdb-12-0776.html