0

所以我从来没有使用过存储过程,也没有很多数据库经验,我被分配了一个需要我创建一个包的任务,我被困住了。

使用 SQL Developer,我正在尝试使用此代码创建一个名为 JUMPTO 的包...


create or replace package JUMPTO is
  type t_locations is ref cursor;

  procedure procGetLocations(locations out t_locations);

end JUMPTO;

当我运行它时,它会吐出这个 PL/SQL 代码块......


DECLARE
  LOCATIONS APPLICATION.JUMPTO.t_locations;
BEGIN

  JUMPTO.PROCGET_LOCATIONS(
    LOCATIONS => LOCATIONS
  );
  -- Modify the code to output the variable
  -- DBMS_OUTPUT.PUT_LINE('LOCATIONS = ' || LOCATIONS);
END;

我发现的一个教程说要删除那里第二行的评论。我试过有和没有评论。

当我点击“确定”时,我得到了错误......


ORA-06550: line 2, column 32:
PLS-00302: component 'JUMPTO' must be declared
ORA-06550: line 2, column 13:
PL/SQL: item ignored
ORA-06550: line 6, column 18:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: line 5, column 3:
PL/SQL: Statement ignored
ORA-06512: at line 58

我真的不知道发生了什么,这对我来说是全新的领域。我尝试创建一个刚从数据库中选择一些东西的主体,但没有任何东西以我脑海中看起来应该的方式工作。谁能给我任何见解?

4

2 回答 2

2

首先你需要声明一个包体,例如:

create or replace package body JUMPTO is

  procedure procGetLocations(locations out t_locations)
  is
  begin
    locations := null; -- Need code here
  end;

end JUMPTO;

编译需要这个:

 DECLARE
     LOCATIONS JUMPTO.t_locations;
   BEGIN
     JUMPTO.PROCGETLOCATIONS(
       LOCATIONS => LOCATIONS
     );
   END;
于 2009-01-08T23:03:18.120 回答
2

Oracle PL/SQL 包有 2 个部分:

  • 包规范(公共部分,其中列出了可全局访问的常量、函数、过程、变量等)。
  • 包体(代码所在的位置以实现包规范)。

您的第一段代码声明了包规范(JUMPTO)。您声明了一个类型 ( t_locations ) 和一个过程 ( procGetLocations ),它们没有输入,但输出一个 t_locations 类型的变量 ( locations )。

首先编译包规范(就像你做的那样),然后像这样编译包体:

create or replace package body JUMPTO is  
procedure procGetLocations(locations out t_locations) is  
begin    
locations := null; -- Your code goes here
end procGetLocations;
end JUMPTO;

现在您可以在其他 PL/SQL 块(匿名或其他)中调用过程procGetLocations 。

于 2009-01-15T01:44:26.787 回答