问题描述
我有一个包含SQL SELECT
语句的字符串.
我不知道如何在屏幕上输出该语句的执行结果,该执行将使用本机动态SQL (EXECUTE IMMEDIATE
)完成.
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
).
示例:
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/
推荐答案
如果可以将立即执行更改为dbms_sql游标,则以下解决方案应该可以为您提供帮助,因为您可以从dbms_sql获取列名.光标:
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
这篇关于如何输出使用本机动态SQL执行的SELECT语句的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!