云数据库 GaussDB-RETURN NEXT及RETURN QUERY:示例

时间:2025-01-26 10:39:51

示例

 1 2 3 4 5 6 7 8 91011121314151617181920212223242526272829303132333435363738394041424344
openGauss=# CREATE TABLE t1(a int);openGauss=# INSERT INTO t1 VALUES(1),(10);--RETURN NEXTopenGauss=# CREATE OR REPLACE FUNCTION fun_for_return_next() RETURNS SETOF t1 AS $$DECLARE   r t1%ROWTYPE;BEGIN   FOR r IN select * from t1   LOOP      RETURN NEXT r;   END LOOP;   RETURN;END;$$ LANGUAGE plpgsql;openGauss=# call fun_for_return_next(); a--- 1 10(2 rows)-- RETURN QUERYopenGauss=# CREATE OR REPLACE FUNCTION fun_for_return_query() RETURNS SETOF t1 AS $$DECLARE   r t1%ROWTYPE;BEGIN   RETURN QUERY select * from t1;END;$$language plpgsql;openGauss=# call fun_for_return_next(); a--- 1 10(2 rows)openGauss=# DROP PROCEDURE IF EXISTS fun_for_return_next();DROP PROCEDUREopenGauss=# DROP FUNCTION IF EXISTS fun_for_return_query();DROP FUNCTIONopenGauss=# DROP TABLE t1;DROP TABLE
support.huaweicloud.com/distributed-devg-v2-gaussdb/gaussdb-12-0529.html