Am trying to execute the variable t_ord which has statement "REVOKE role_test FROM test" . My requirement is to execute the variable t_ord and store the result msg successfull or fail in the variable ret . But am getting the below error ,
ERROR: INTO used with a command that cannot return data CONTEXT: PL/pgSQL function inline_code_block line 9 at EXECUTE
DO $$
declare
t_ord varchar(500):= NULL;
cursor_name numeric;
ret varchar(500):= NULL;
begin
SELECT 'REVOKE '||'role_test'||' FROM '||'test' INTO STRICT t_ord ;
raise notice 't_ord %',t_ord;
/*
cursor_name := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(cursor_name, t_ord, DBMS_SQL.V7);
ret := DBMS_SQL.EXECUTE(cursor_name);
DBMS_SQL.CLOSE_CURSOR(cursor_name);
*/
EXECUTE t_ord ; -- > not getting desired results as commented code above , cursor_name should be used which is required later in exception block
EXCEPTION
/* WHEN err THEN
RAISE EXCEPTION '%', t_msg;
WHEN OTHERS THEN
IF DBMS_SQL.IS_OPEN(cursor_name) THEN
DBMS_SQL.CLOSE_CURSOR(cursor_name);
END IF;
RAISE;
*/
WHEN SQLSTATE '50001' THEN
RAISE NOTICE '%', t_msg;
WHEN OTHERS THEN
IF EXISTS(SELECT * FROM pg_cursors WHERE name = 'cursor_name') THEN
CLOSE cursor_name;
END IF;
END;
end $$;
And , How can i implement cursor_name the same way in oracle so that it can be used in exception block ..