How to output result of SELECT statement which is executed using native dynamic SQL?(如何输出使用本机动态 SQL 执行的 SELECT 语句的结果?)
问题描述
我有一个包含 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 语句的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何输出使用本机动态 SQL 执行的 SELECT 语句的结果?


基础教程推荐
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01