简体   繁体   English

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

[英]PLS-00201: identifier must be declared in Procedure

I have a PL/SQL Procedure code, which runs when it is / , but doesn't runs when it's executed.我有一个 PL/SQL 过程代码,它在/时运行,但在执行时不运行。 The error message I get is我得到的错误信息是

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 , this solutions and other solutions some what related to this error.到目前为止,我已经阅读了这个这个这个解决方案和其他一些与这个错误相关的解决方案。

You have written an anonymous block with a local procedure MAXINUM() .您已经使用本地过程MAXINUM()编写了一个匿名块。 This procedure can be called within that block but does not exist outside that block.该过程可以在该块内调用,但在该块外不存在。 Consequently you cannot call it independently.因此你不能独立调用它。

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.约定是将其声明为函数并返回最高值,而不是设置 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()的重新实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM