Question

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?

Was it helpful?

Solution

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;

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top