oracle PLS-00201:标识符必须在程序中声明

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45952610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:27:29  来源:igfitidea点击:

PLS-00201: identifier must be declared in Procedure

oraclestored-proceduresplsql

提问by Minhaj Patel

I have a PL/SQL Procedure code, which runs when it is /, but doesn't runs when it's executed. The error message I get is

我有一个 PL/SQL 过程代码,它在运行时运行/,但在执行时不运行。我得到的错误信息是

SQL> EXECUTE MAXINUM;
BEGIN MAXINUM; END;

      *
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00201: identifier 'MAXINUM' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

The code which I'm working on is :

我正在处理的代码是:

DECLARE
    N NUMBER;
    M NUMBER;
    O NUMBER;
    P NUMBER;
    X NUMBER;
PROCEDURE MAXINUM(N IN NUMBER, M IN NUMBER, O IN NUMBER, P IN NUMBER, X OUT NUMBER) IS
    BEGIN
    IF N>M AND N>O AND N>P THEN
        X:=N;
    ELSIF M>N AND M>O AND M>P THEN
        X:=M;
    ELSIF O>N AND O>M AND O>P THEN
        X:=O;
    ELSIF P>N AND P>M AND P>O  THEN
        X:=P;
    END IF;
    END;

BEGIN
    N:=&NUMBER;    
    M:=&NUMBER;
    O:=&NUMBER;
    P:=&NUMBER;
    MAXINUM(N,M,O,P,X);
    DBMS_OUTPUT.PUT_LINE('HIGHEST NUMBER = '||X);
END;
/

When it gave the 'identifier error', I tried dropping this procedure I got the error:

当它给出“标识符错误”时,我尝试删除此过程,但出现错误:

SQL> DROP PROCEDURE MAXINUM;
DROP PROCEDURE MAXINUM
*
ERROR at line 1:
ORA-04043: object MAXINUM does not exist

I have so far read this, this, thissolutions and other solutions some what related to this error.

到目前为止,我已经阅读了这个这个这个解决方案和其他一些与这个错误相关的解决方案。

回答by APC

You have written an anonymous block with a local procedure MAXINUM(). This procedure can be called within that block but does not exist outside that block. Consequently you cannot call it independently.

您已经用本地过程编写了一个匿名块MAXINUM()。该过程可以在该块内调用,但在该块外不存在。因此你不能独立调用它。

If you want to use the procedure elsewhere you need to create it as a first class database object:

如果您想在其他地方使用该过程,您需要将其创建为一级数据库对象:

create or replace procedure MAXINUM
   (N IN NUMBER, M IN NUMBER, O IN NUMBER, P IN NUMBER, X OUT NUMBER)
is 
BEGIN
    IF N>M AND N>O AND N>P THEN
        X:=N;
    ELSIF M>N AND M>O AND M>P THEN
        X:=M;
    ELSIF O>N AND O>M AND O>P THEN
        X:=O;
    ELSIF P>N AND P>M AND P>O  THEN
        X:=P;
    END IF;
END;
/

Now you can call it in your code, like this:

现在您可以在代码中调用它,如下所示:

DECLARE
    N NUMBER;
    M NUMBER;
    O NUMBER;
    P NUMBER;
    X NUMBER;
BEGIN
    N:=&NUMBER;    
    M:=&NUMBER;
    O:=&NUMBER;
    P:=&NUMBER;
    MAXINUM(N,M,O,P,X);
    DBMS_OUTPUT.PUT_LINE('HIGHEST NUMBER = '||X);
END;
/

Points to note:

注意事项:

  1. what happens if a parameter is null?
  2. what happens if two arguments have the same value?
  3. the convention would be to declare this as a function and return the highest value instead of setting an OUT parameter.
  1. 如果参数为空会发生什么?
  2. 如果两个参数具有相同的值会发生什么?
  3. 约定是将其声明为函数并返回最高值而不是设置 OUT 参数。


Incidentally I assume you're doing this as an exercise, as it is a re-implementation of an existing Oracle built-in function, greatest().

顺便说一句,我假设您是作为练习来做这件事的,因为它是对现有 Oracle 内置函数greatest().