How to output result of SELECT statement which is executed using native dynamic SQL?

oracle, plsql

Solution

If you are on Oracle 12c with a 12c client, this should work:

declare
    rc sys_refcursor;
begin
    open rc for 'select * from dual';
    dbms_sql.return_result(rc);
end;

Problem

I have a string which contains SQL `SELECT` statement. I wonder how can I output result of the execution of that statement on the screen, execution will be done using native dynamic SQL (`EXECUTE IMMEDIATE`). example: ``` DECLARE v_stmt VARCHAR2 := 'SELECT * FROM employees'; BEGIN EXECUTE IMMEDIATE v_stmt; -- ??? how to output result of that select on the screen. END; ``` Important remark: structure of table can be any. I have to write a procedure which accepts name of the table as parameter, so I can't hardcode a table structure and don't want to do it. Thanks for responses. Any ideas very appreciated/

Original source

Related problems