获取影响行数

最近更新时间: 2024-06-12 15:06:00

postgres=# CREATE OR REPLACE FUNCTION f27(a_id INTEGER) RETURNS VOID AS
postgres-# $$  
postgres$# DECLARE
postgres$#     v_mc TEXT; 
postgres$#     v_row_count BIGINT;
postgres$# BEGIN          
postgres$#     SELECT mc INTO v_mc FROM t WHERE id=a_id;
postgres$#     GET DIAGNOSTICS v_row_count = ROW_COUNT;
postgres$#     RAISE NOTICE '查询到的记录数为 % ',v_row_count;
postgres$# END;
postgres$# $$
postgres-# LANGUAGE plpgsql;
CREATE FUNCTION
postgres=# SELECT f27(1);
NOTICE:  查询到的记录数为 1 
 f27 
----- 
(1 row)
postgres=# SELECT f27(3);
NOTICE:  查询到的记录数为 0 
 f27 
-----
(1 row)