为什么使用EXECUTE IMMEDIATE运行此查询会导致查询失败? [英] Why does running this query with EXECUTE IMMEDIATE cause it to fail?

查看:139
本文介绍了为什么使用EXECUTE IMMEDIATE运行此查询会导致查询失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个PL/SQL过程,该过程需要动态生成一些查询,其中之一涉及使用查询结果作为参数来创建临时表.

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抛出ORA-00911: invalid character.如果我手动运行创建的查询,它将正确运行.至此,我可以确定是什么导致了问题.

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.

推荐答案

尝试丢失;"从您立即执行的字符串内部.

Try to lose the ";" from inside the string that you Execute Immediate.

EXECUTE IMMEDIATE  'CREATE GLOBAL TEMPORARY TABLE tmp_tab AS (' || query || ')';

这篇关于为什么使用EXECUTE IMMEDIATE运行此查询会导致查询失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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