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/
If you can change that execute immediate into a dbms_sql cursor, then the following solution should be able to help you, as you can get the column names from a dbms_sql cursor:
https://forums.oracle.com/forums/thread.jspa?threadID=700648
If you are on Oracle 12c with a 12c client, this should work:
Yes we can execute select statement dynamically.
Let say we have a table
test
. It has four columnRow_id,Name,Rank
etc When we doselect * from test;
Result will beNow we can use DBMS_SQL package to execute dynamically SELECT Sql Statament.
Code is below: