如何输出使用本机动态 SQL 执行的 SELECT 语句的结果? [英] How to output result of SELECT statement which is executed using native dynamic SQL?

查看:23
本文介绍了如何输出使用本机动态 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 语句的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆