云数据库 GaussDB-数组:示例

时间:2023-11-01 16:18:34

示例

 1 2 3 4 5 6 7 8 9101112131415161718192021222324252627282930313233343536
--演示在存储过程中对数组进行操作。gaussdb=# CREATE OR REPLACE PROCEDURE array_proc ASDECLARE        TYPE ARRAY_INTEGER IS VARRAY(1024) OF INTEGER;--定义数组类型       ARRINT ARRAY_INTEGER := ARRAY_INTEGER();  --声明数组类型的变量 BEGIN        ARRINT.extend(10);         FOR I IN 1..10 LOOP                 ARRINT(I) := I;        END LOOP;        DBE_OUTPUT.PRINT_LINE(ARRINT.COUNT);         DBE_OUTPUT.PRINT_LINE(ARRINT(1));         DBE_OUTPUT.PRINT_LINE(ARRINT(10));        DBE_OUTPUT.PRINT_LINE(ARRINT(ARRINT.FIRST));        DBE_OUTPUT.PRINT_LINE(ARRINT(ARRINT.LAST));       DBE_OUTPUT.PRINT_LINE(ARRINT(ARRINT.NEXT(ARRINT.FIRST)));       DBE_OUTPUT.PRINT_LINE(ARRINT(ARRINT.PRIOR(ARRINT.LAST)));       ARRINT.TRIM();              IF ARRINT.EXISTS(10) THEN           DBE_OUTPUT.PRINT_LINE('Exist 10th element');       ELSE           DBE_OUTPUT.PRINT_LINE('Not exist 10th element');       END IF;       DBE_OUTPUT.PRINT_LINE(ARRINT.COUNT);       DBE_OUTPUT.PRINT_LINE(ARRINT(ARRINT.FIRST));        DBE_OUTPUT.PRINT_LINE(ARRINT(ARRINT.LAST));       ARRINT.DELETE();END;  /--调用该存储过程。gaussdb=# CALL array_proc();--删除存储过程。gaussdb=# DROP PROCEDURE array_proc;
support.huaweicloud.com/centralized-devg-v3-opengauss/gaussdb-12-0727.html