因此,我从未使用过存储过程,并且总体上没有很多数据库经验,并且我被分配了一项需要我创建包的任务,但我陷入了困境。

使用 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

我真的不知道发生了什么,这对我来说是全新的领域。我尝试创建一个刚刚从数据库中选择一些内容的主体,但没有任何东西像我想象的那样工作。谁能给我对此的任何见解?

有帮助吗?

解决方案

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

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;

其他提示

Oracle PL/SQL 包由 2 部分组成:

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

您的第一段代码声明了包规范(跳到)。您声明了一个类型 (t_地点)和一个过程(过程获取位置)没有输入,但输出一个变量(地点) 类型为 t_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 块中(匿名或其他方式)。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top