为什么使用 EXECUTE IMMEDIATE 运行此查询会导致它失败?
我正在编写一个 PL/SQL 过程,需要动态生成一些查询,其中之一涉及使用查询结果作为参数创建临时表。
CREATE OR REPLACE PROCEDURE sqlout(query IN VARCHAR2)
IS
BEGIN
EXECUTE IMMEDIATE 'CREATE GLOBAL TEMPORARY TABLE tmp_tab AS (' || query || ');';
END;
它可以正确编译,但即使使用非常简单的查询,例如:
BEGIN
sqlout('SELECT * FROM DUAL');
END;
IT 也会抛出 ORA-00911:无效字符
。 如果我手动运行创建的查询,它将正确运行。 此时我能够确定导致问题的原因。
I am writing a PL/SQL procedure that needs to to dynamically generate some queries, one of which involves creating a temporary table using results from a query taken as a parameter.
CREATE OR REPLACE PROCEDURE sqlout(query IN VARCHAR2)
IS
BEGIN
EXECUTE IMMEDIATE 'CREATE GLOBAL TEMPORARY TABLE tmp_tab AS (' || query || ');';
END;
It compiles correctly, but even with very simple queries such as with:
BEGIN
sqlout('SELECT * FROM DUAL');
END;
IT throws ORA-00911: invalid character
. If I run the created query manually it runs correctly. At this point I am able to determine what is causing the problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试去掉“;” 从您立即执行的字符串内部。
Try to lose the ";" from inside the string that you Execute Immediate.