Package中私人的Procedure/Function(沒在Package Specification聲明)需要注意放置的位置
比如下面的Package,Procedure A 想要調用 Procedure B,
CREATE OR REPLACE PACKAGE AAAAA AUTHID CURRENT_USER AS PROCEDURE A;END AAAAA;
CREATE OR REPLACE PACKAGE BODY AAAAA AS PROCEDURE A IS BEGIN B; END; PROCEDURE B IS BEGIN dbms_output.put_line('In PROCEDURE B'); END ;END AAAAA;會報錯: PLS-00313: 'B' not declared in this scope
原因: B不是Public的Procedure,如果A想調用B,那麼B的定義必須放在A的前邊。
PLS-00313: "string" not declared in this scope
Cause: There is no declaration for the given identifier within the scope of reference. The identifier might be misspelled, its declaration might be faulty, or the declaration might be placed incorrectly in the block structure.
Action: Check the spelling and declaration of the identifier. Also confirm that the declaration is placed correctly in the block structure.
所以正確的寫法是:
CREATE OR REPLACE PACKAGE BODY AAAAA AS PROCEDURE B IS BEGIN dbms_output.put_line('In PROCEDURE B'); END ; PROCEDURE A IS BEGIN B; END; END AAAAA;或者,如果確實想把B放到後邊,那麼可以在前面聲明下,這樣後邊不過誰調用,也不會報錯,這也是一個很好的習慣。
CREATE OR REPLACE PACKAGE BODY AAAAA AS PROCEDURE B; PROCEDURE A IS BEGIN B; END; PROCEDURE B IS BEGIN dbms_output.put_line('In PROCEDURE B'); END ;END AAAAA;
Reference:http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:11471812249709