使用SQL Developer创建包的问题

[英]Package creation issues using SQL Developer


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...

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


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...

当我运行它时,它会吐出这个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;

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?

我真的不知道发生了什么,这对我来说都是一个全新的领域。我尝试创建一个刚刚从数据库中选择一些东西的主体,但没有任何东西像我脑子里想象的那样工作。任何人都可以给我任何洞察力吗?

2 个解决方案

#1


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;

#2


An Oracle PL/SQL package has 2 parts:

Oracle PL / SQL包有两部分:

  • 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.

您的第一段代码声明了包规范(JUMPTO)。您声明了一个类型(t_locations)和一个没有输入的过程(procGetLocations),但是输出了一个类型为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).

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

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2009/01/08/d32295db9162141f24026c62b5849687.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告