Oracle语句获取错误

Oracle语句获取错误

本文介绍了执行`EXECUTE IMMEDIATE` Oracle语句获取错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Oracle的NewBie.当我执行以下语句

I am NewBie to Oracle. When I Execute Following Statement

BEGIN
 EXECUTE IMMEDIATE  'SELECT * FROM DUAL;';
END;
 /

我遇到错误

错误报告-ORA-00911:无效 字符ORA-06512:在第2行 00911. 00000-无效字符" *原因:标识符不得以除ASCII以外的任何ASCII字符开头 字母和数字. $#_也可以在第一个之后 特点.用双引号引起来的标识符可能包含 除双引号外的任何字符.替代报价 (q'#...#')不能将空格,制表符或回车符用作 定界符.对于所有其他上下文,请查阅SQL语言. 参考手册. *动作:

Error report - ORA-00911: invalid character ORA-06512: at line 2 00911. 00000 - "invalid character" *Cause: identifiers may not start with any ASCII character other than letters and numbers. $#_ are also allowed after the first character. Identifiers enclosed by doublequotes may contain any character other than a doublequote. Alternative quotes (q'#...#') cannot use spaces, tabs, or carriage returns as delimiters. For all other contexts, consult the SQL Language Reference Manual. *Action:

推荐答案

问题是'SELECT * FROM DUAL;'中的;字符.

来自文档:

execute_immediate_statement ::=
EXECUTE_IMMEDIATE dynamic_string
 {
    INTO { define_variable [, define_variable ...] | record_name }
  | BULK COLLECT INTO { collection_name [, collection_name ...] | :host_array_name }
 }
   [ USING [ IN | OUT | IN OUT ] bind_argument
   [, [ IN | OUT | IN OUT ] bind_argument] ... ] [ returning_clause ] ;

...,其中dynamic_string是(强调我的):

... where dynamic_string is (emphasis mine):

由于除非将它们括在单个PL/SQL块中,否则它不会接受多个语句,因此不希望使用;分隔符.

Since it won't accept multiple statements unless you enclose them in a single PL/SQL block, the ; separator is not expected.

使用EXECUTE IMMEDIATE语句中有更好的解释在PL/SQL中:

这篇关于执行`EXECUTE IMMEDIATE` Oracle语句获取错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 15:44