我有一个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
我正在处理的代码是:
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;
/
当它给出'标识符错误'时,我尝试删除此过程,我收到错误:
SQL> DROP PROCEDURE MAXINUM;
DROP PROCEDURE MAXINUM
*
ERROR at line 1:
ORA-04043: object MAXINUM does not exist
答案 0 :(得分:4)
您编写了一个带有本地过程MAXINUM()
的匿名块。可以在该块中调用此过程,但不在该块之外。因此,您无法独立调用它。
如果要在其他地方使用该过程,则需要将其创建为第一类数据库对象:
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;
/
现在您可以在代码中调用它,如下所示:
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;
/
注意事项:
顺便提一下,我假设您将此作为练习,因为它是an existing Oracle built-in function, greatest()
的重新实现。