--创建函数
CREATE FUNCTION countdown() RETURNS void AS $$
DECLARE counter integer := (select count(*) from hc_user) as num;
DECLARE idx integer := 0;
DECLARE ids varchar := '0';
DECLARE IsExit varchar := '0';
BEGIN
WHILE idx <= counter LOOP
ids := (select user_id from hc_user limit 1 offset idx) as h_id ;
--输出查看 RAISE NOTICE
RAISE NOTICE 'idx: %', idx;
RAISE NOTICE 'ids: %', ids;
IsExit := (select user_id from hc_member where user_id = ids ) as h_id1;
IF IsExit != '0' THEN
RAISE NOTICE 'duide: %', IsExit;
--执行update操作
RAISE NOTICE '我执行修改了要。';
END IF;
counter := counter - 1;
idx := idx+1;
END LOOP;
END;
$$ LANGUAGE plpgsql;
SELECT countdown();