使用 SQL Developer 创建包的问题

发布于 2024-07-12 11:31:47 字数 1093 浏览 6 评论 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

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

So I've never worked with stored procedures and have not a whole lot of DB experience in general and I've been assigned a task that requires I create a package and I'm stuck.

Using SQL Developer, I'm trying to create a package called JUMPTO with this code...


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

  procedure procGetLocations(locations out t_locations);

end JUMPTO;

When I run it, it spits out this PL/SQL code block...


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;

A tutorial I found said to take out the comment for that second line there. I've tried with and without the comment.

When I hit "ok" I get the error...


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

I really don't have any idea what's going on, this is all completely new territory for me. I tried creating a body that just selected some stuff from the database but nothing is working the way it seems like it should in my head. Can anyone give me any insight into this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

满天都是小星星 2024-07-19 11:31:47

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

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;

First of all you need to declare a package body, for instance:

create or replace package body JUMPTO is

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

end JUMPTO;

To compile need this:

 DECLARE
     LOCATIONS JUMPTO.t_locations;
   BEGIN
     JUMPTO.PROCGETLOCATIONS(
       LOCATIONS => LOCATIONS
     );
   END;
怪我太投入 2024-07-19 11:31:47

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

An Oracle PL/SQL package has 2 parts:

  • A package specification (the public part, where globally accessible constants, functions, procedures, variables, etc are listed).
  • A package body (where the code resides to implement the package spec).

Your first piece of code declared the package specification (JUMPTO). You declared a type (t_locations) and a procedure (procGetLocations) that has no inputs, but outputs one variable (locations) of type t_locations.

First compile the package spec (as you did), then compile the package body like so:

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;

Now you can call the procedure procGetLocations in other PL/SQL blocks (anonymous or otherwise).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文