为什么我在尝试创建这个简单的函数时会收到PLS-00103?

The*_*ian 3 sql oracle plsql

我正在尝试创建此功能:

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;
    /
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

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
Run Code Online (Sandbox Code Playgroud)

我的问题:

  1. 一般来说,为什么这些错误会发生或表示?
  2. 更具体地说,为什么我收到此错误?

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

我在SO上看到的导致PLS-00103的一些问题是:

  1. 意外使用保留字,如max或min,作为变量名.
  2. 循环结构关键字的错误使用,例如使用EXIT LOOP结束循环而不是END LOOP.
  3. 错误地为变量赋值,例如x + 9 = x.

当然,这不是我已经表示为PLS-00103的问题的综合列表,但我不认为我的功能适用于我见过的任何问题.

Wil*_*son 6

参数只能指定基本类型,而不能指定精度,比例,长度等.

return char(3)
Run Code Online (Sandbox Code Playgroud)

应该

return char
Run Code Online (Sandbox Code Playgroud)

或者更好,

return ple.ptt%type
Run Code Online (Sandbox Code Playgroud)

顺便说char一下,这几乎不是一个好主意.有些人似乎认为,它不会避免一些可变长度字符串的开销,并且它不能确保诸如3个字母的ISO货币代码之类的值具有预期的字母数.它所要做的就是在非空值的末尾添加空格,有时当你不期望它时,会导致模糊的错误.它仅为了ANSI兼容性原因而添加,并且您不应该在使用Oracle开发新系统时使用它.