views:

1207

answers:

3

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?

+1  A: 

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;
FerranB
Awesome, thanks. I tried your first comment before the edit and found that it wasn't working but it was a step closer it seemed. Then I realized that the issue at that point was that it needed a body. I think I understand what was going on now.
Carter
+1  A: 

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

ropable
A: 

i did n't get the how to exccute the package and what is the location in declare section.

srinivad