執行的函數我定義的函數如下錯誤,而與光標
CREATE OR REPLACE FUNCTION processActivityCommentTable() RETURNS INTEGER AS $$
DECLARE
activityCommentRow RECORD;
i RECORD;
activityId integer;
attachments text;
attachmentId integer;
cur1 CURSOR FOR SELECT ac.id, ac.attachments from activitycomment ac where ac.attachments is not null;
BEGIN
OPEN cur1;
FOR activityCommentRow in cur1
LOOP
RAISE NOTICE 'currently processing for %s ...', activityCommentRow.id;
-- can do some processing here
activityId = activityCommentRow.id;
attachments = activityCommentRow.attachments;
SELECT foo FROM regexp_split_to_table(attachments,E'{"id":') as foo;
FOR i in select * from foo
LOOP
select regexp_replace(i,'(,"name").*','') into attachmentId;
EXECUTE 'INSERT INTO attachment (activity_comment_id) values(' || attachmentId ||') where id= ' activityId;
END LOOP;
END LOOP;
CLOSE cur1;
END;
$$ LANGUAGE plpgsql;
在執行它
select processActivityCommentTable();
它給了我下面的錯誤
錯誤:已在使用光標「CUR1」 SQL狀態:42P03 上下文:PL/pgSQL函數processactivitycommenttable()第12行FOR FOR over光標
任何人都可以請幫忙嗎?