`
weigang.gao
  • 浏览: 467384 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

PLS-00313: 'XXXXX' not declared in this scope

 
阅读更多

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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics