postgreSQL中的@@ Fetch_status

时间:2015-06-02 20:29:37

标签: sql postgresql plpgsql

我将我的数据库从MS SQL Server转移到PostgreSQL,我对此触发器有疑问:

CREATE TRIGGER added_clients ON client
FOR INSERT
AS
BEGIN
DECLARE cursor_inserted CURSOR
FOR SELECT name, surname FROM inserted;
OPEN cursor_inserted
DECLARE @name varchar(15), @surname varchar(20)
FETCH NEXT FROM cursor_inserted INTO @name, @surname
WHILE @@FETCH_STATUS = 0
BEGIN
print 'Added: '+@name+' '+ @surname
FETCH NEXT FROM cursor_inserted INTO @name, @surname
END
CLOSE cursor_inserted
DEALLOCATE cursor_inserted
END
GO

postgreSQL中@@ FETCH_STATUS的等价物是什么?

2 个答案:

答案 0 :(得分:2)

PostgreSQL中的@@ fetch_status相当于FOUND。

您可以在此处找到更多信息:https://www.postgresql.org/docs/9.1/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-DIAGNOSTICS

在触发器中,您只需要编写WHILE(FOUND)而不是@@ fetch_status = 0.

我希望你找到有用的答案。

答案 1 :(得分:1)

这是PostgreSQL的Cursor文档

http://www.postgresql.org/docs/current/static/plpgsql-cursors.html

循环游标:

[ <<label>> ]
FOR recordvar IN bound_cursorvar [ ( [ argument_name := ] argument_value [, ...] ) ] LOOP
    statements
END LOOP [ label ];