PostgreSQL支持无需创建出来即可执行的function,关键字是
do language plpgsql $$
declare
begin
...
..
.
end $$;
示例如下:
do
$$
DECLARE
d_news_id numeric;
d_tag_id numeric;
cur_list CURSOR FOR
select flu.id,fcm.id
FROM
a fcm,
b frr,
c flur,
d flu
WHERE
fcm.create_id = frr.relation_id
AND flur.ID = frr.role_id
AND flu.id = flur.login_user_id
AND fcm.create_id IS NOT NULL
AND flur.role_type = 1
AND flur.status = 1
AND frr. TYPE = 1;
BEGIN
OPEN cur_list;
LOOP
FETCH cur_list INTO d_news_id,d_tag_id;
EXIT WHEN NOT FOUND;
--插入数据
UPDATE a SET login_user_id = d_news_id where id = d_tag_id;
END LOOP;
CLOSE cur_list;
END;
$$