什么是高级?这就叫高级—openGauss(100)

17 阅读1分钟

#openGauss #入门 #安装 #数据库 #开源

知识来源:docs-opengauss.osinfra.cn/zh/

  • WITH HOLD游标的使用。

    --开启事务。
    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
    

#openGauss #入门 #安装 #数据库 #开源

知识来源:docs-opengauss.osinfra.cn/zh/