2016-11-18 84 views
3

我想创建这样的功能:为什么在尝试创建这个简单功能时收到PLS-00103?

create or replace function g(sN int) return char(3) as 
     t char(3); 
    begin 
    select pt into t from (
     select pTT as pt, pC 
     from ple 
     order by pC asc 
    ) where sN <= pC and rownum <= 1; 

    return t; 
    end; 
    /

我收到此以下错误:

LINE/COL ERROR 
-------- ----------------------------------------------------------------- 
1/31  PLS-00103: Encountered the symbol "(" when expecting one of the 
    following: 
    ; is authid as cluster order using external varying character 
    large deterministic parallel_enable pipelined aggregate 
    result_cache accessible 

2/9 PLS-00103: Encountered the symbol "CHAR" when expecting one of 
    the following: 
    , from into bulk 
    The symbol "," was substituted for "CHAR" to continue. 


LINE/COL ERROR 
-------- ----------------------------------------------------------------- 
2/16  PLS-00103: Encountered the symbol ";" when expecting one of the 
    following: 
    . (, * % & - +/at mod remainder rem <an identifier> 
    <a double-quoted delimited-identifier> <an exponent (**)> as 
    from into || multiset bulk 

11/8  PLS-00103: Encountered the symbol "end-of-file" when expecting 
    one of the following: 
    end not pragma final instantiable order overriding static 
    member constructor map 

我的问题:

  1. 在一般情况下,为什么这些错误发生,或者意味着什么?
  2. 更具体地说,为什么我收到此错误?

我的研究: 在SO上有许多涉及PLS-00103的问题,但它们都不符合我的功能。

,我看到的,使得引起了一些问题PLS-00103是:

  1. 意外使用的保留字,像最大或最小的,作为变量名。
  2. 不正确地使用循环结构关键字,例如使用EXIT LOOP结束 循环,而不是END LOOP。
  3. 将值错误地赋值给变量,如x + 9 = x。

当然,这并不是我列为PLS-00103的问题的全面列表,但我认为我的功能不适用于我所见过的任何一个。

回答

6

参数只能指定基本类型,而不是精度,小数,长度等

return char(3) 

应该是

return char 

或也许更好,

return ple.ptt%type 

顺便说一句char是几乎从来不是一个好主意。它不会避免一些人似乎认为可变长度字符串的一些开销,并且它不能确保诸如3字母ISO货币代码的值将具有预期的字母数量。它所要做的就是将空格添加到非空值的末尾,有时候当你不期望它时,会导致不明确的错误。它仅仅是出于ANSI兼容性的原因而添加的,并且您实际上不应该使用它来开发使用Oracle的新系统。

+0

非常感谢。 – TheHumblePedestrian

相关问题