我正在尝试执行以下代码,但是由于 cursor v1_cur不存在,34000 ,我遇到了错误。有人可以让我知道错误在哪里吗?
CREATE OR REPLACE FUNCTION data_del(
OUT p_message_out CHARACTER VARYING,
OUT p_sqlstate_out CHARACTER VARYING
)
RETURNS RECORD AS
$BODY$
DECLARE
v_msg CHARACTER VARYING(160);
v_sqlstate CHARACTER VARYING(6);
v1_cur RECORD;
c1_cur CURSOR FOR SELECT * FROM mydata WHERE event_timestamp<=CURRENT_TIMESTAMP - INTERVAL '15 Days';
BEGIN
OPEN c1_cur;
LOOP
FETCH c1_cur INTO v1_cur;
EXIT WHEN NOT FOUND;
DELETE FROM mydata WHERE CURRENT OF v1_cur;
END LOOP;
CLOSE c1_cur;
v_msg = 'Data deleted successfully.';
v_sqlstate = 1;
p_message_out = v_msg;
p_sqlstate_out = v_sqlstate;
EXCEPTION WHEN OTHERS THEN
p_message_out=SQLERRM;
p_sqlstate_out=SQLSTATE;
END;
$BODY$
LANGUAGE plpgsql VOLATILE SECURITY DEFINER
答案 0 :(得分:1)
CURRENT OF
后面必须是游标名称(c1_cur
),而不是记录。