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 语句的结果?
基础教程推荐
- 是否可以执行按位分组功能? 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 无法解决整理冲突 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
