【问题标题】:Error(5,1): PLS-00103: Encountered the symbol "CREATE" error while creating function错误(5,1):PLS-00103:创建函数时遇到符号“CREATE”错误
【发布时间】:2015-03-10 09:47:04
【问题描述】:
Error(5,1): PLS-00103: 

Encountered the symbol "CREATE" when expecting one of the following:     

( begin case declare exit for goto if loop mod null pragma    raise return select update while with <an identifier>    <a double-quoted delimited-identifier> <a bind variable> <<    continue close current delete fetch lock insert open rollback    savepoint set sql execute commit forall merge pipe purge 

在我写的代码下面。

CREATE OR replace FUNCTION First_three_records
  RETURN NUMBER AS
  BEGIN
    CREATE TEMPORARY TABLE temp_emp ON COMMIT DROP AS
    SELECT *
    FROM   emp
    WHERE  deptno=20;

    INSERT INTO tgt
    SELECT *
    FROM   temp_emp;

  END;

【问题讨论】:

  • 你有什么问题?
  • dba.stackexchange.com/questions/37362/… -- 如果要创建临时表,则需要使用动态 SQL。
  • 不要在函数中创建临时表。 Oracle 只有全局临时表,没有像其他 RDBMS 那样的本地临时表。

标签: oracle function plsql


【解决方案1】:

Oracle 没有本地临时表,除非使用动态 SQL,否则不能在 PL/SQL 块中创建对象;而且很少有必要或一个好主意。您的架构应该以受控方式创建,而不是动态创建。

您可以使用集合代替,但这里没有意义,您可以这样做:

INSERT INTO tgt
SELECT *
FROM   emp
WHERE  deptno=20;

我不确定你为什么要把它包装在一个函数中;您的函数也被声明为返回一个数字,但您没有 return 语句。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-10
    • 2018-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多