openGauss学习笔记38 openGauss 高级数据管理游标

--开启事务。
openGauss=# START TRANSACTION;

--创建一个with hold游标。
openGauss=# DECLARE cursor1 CURSOR WITH HOLD FOR SELECT * FROM customer_t1;

--抓取头2行到游标cursor1里。
openGauss=# FETCH FORWARD 2 FROM cursor1;
c_customer_sk | c_customer_id | c_first_name | c_last_name | amount
---------------+---------------+--------------+-------------+--------
         3769 |               | Grace       |             |
         3769 | hello         |             |             |
(2 rows)

--结束事务。
openGauss=# END;
COMMIT

--抓取下一行到游标cursor1里。
openGauss=# FETCH FORWARD 1 FROM cursor1;
c_customer_sk | c_customer_id | c_first_name | c_last_name | amount
---------------+---------------+--------------+-------------+--------
         6885 | maps         | Joes         |             |   2200
(1 row)

--关闭游标。
openGauss=# CLOSE cursor1;
CLOSE CURSOR