数据仓库服务 GAUSSDB(DWS)-游标循环:示例
时间:2025-04-17 09:46:56
示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
BEGIN FOR ROW_TRANS IN SELECT first_name FROM staffs LOOP DBMS_OUTPUT.PUT_LINE (ROW_TRANS.first_name ); END LOOP; END; / --创建表 CREATE TABLE integerTable1( A INTEGER) DISTRIBUTE BY hash(A); CREATE TABLE integerTable2( B INTEGER) DISTRIBUTE BY hash(B); INSERT INTO integerTable2 VALUES(2); --多游标共享游标属性的标量 DECLARE CURSOR C1 IS SELECT A FROM integerTable1;--声明游标 CURSOR C2 IS SELECT B FROM integerTable2; PI_A INTEGER; PI_B INTEGER; BEGIN OPEN C1;--打开游标 OPEN C2; FETCH C1 INTO PI_A; ---- C1%FOUND 和 C2%FOUND 值为 FALSE FETCH C2 INTO PI_B; ---- C1%FOUND 和 C2%FOUND 的值都为 TRUE --判断游标状态 IF C1%FOUND THEN IF C2%FOUND THEN DBMS_OUTPUT.PUT_LINE('Dual cursor share paremeter.'); END IF; END IF; CLOSE C1;--关闭游标 CLOSE C2; END; / --删除临时表 DROP TABLE integerTable1; DROP TABLE integerTable2; |
support.huaweicloud.com/devg-dws/dws_04_0549.html
推荐文章