Home » SQL & PL/SQL » SQL & PL/SQL » Unable to find problem in simple package (Mac, SQL Developer for Mac, Oracle 10g on XP virtual machine)
Unable to find problem in simple package [message #540564] Tue, 24 January 2012 09:26 Go to next message
mallethead@verizon.net
Messages: 10
Registered: January 2012
Location: New Jersey
Junior Member
Hello,

I'm re-learning Stored Procedures and trying very simple packages/procedures to call from the ColdFusion side for web pages. I don't understand what is wrong with the following. It is a simple query that should return 30 rows of course names.

I have also included some code for checking for errors at the top and bottom that I found on a website. Including or not including this error checking code does not have an effect on the outcome.

set echo on
-- *** @RetrieveCourse.sql ***
-- *** NOTE: Logon using the student schema ***
spool RetrieveCourse.txt
-- ***
-- *** Create script for PACKAGE: RetrieveCourse ***
-- ***

CREATE OR REPLACE PACKAGE pkg_CourseList AS

  TYPE recCourse IS RECORD (
    vCourseDesc   Course.Description%TYPE,
    vCourseCost   Course.Cost%TYPE
  );
  
  TYPE curCourseList IS REF CURSOR RETURN recCourse;
  
  PROCEDURE sp_getCourseList (
    rsCourses OUT curCourseList
  );
END pkg_CourseList;
/
CREATE OR REPLACE PACKAGE BODY pkg_CourseList AS

  PROCEDURE sp_getCourseList (
    rsCourses OUT curCourseList
  )
  AS
  BEGIN
    OPEN rsCourses FOR
      SELECT
        course.DESCRIPTION,
        course.COST
      FROM course;
  END sp_getCourseList;
  
END pkg_CourseList;
/
    
-- ********************* VERIFY PACKAGE ****************************
set echo off
set pages 80
set lines 80
set heading on
column line format 9999
column name format a20
column object_name format a20
column object_type format a15
column position format 9999
column status format a10
column text format a30
--
select object_name, object_type, status
   from user_objects
   where object_name =
      (UPPER('pkg_CourseList')) ;
set echo on
-- ********************* CHECK ERROR FILE **************************
set echo off
select name, line, position, text
   from user_errors
   where name =
      (UPPER('pkg_CourseList')) ;
spool off


The result appears to be successful....

...
.
PACKAGE pkg_CourseList compiled
...
.
PACKAGE BODY pkg_CourseList compiled
> -- ********************* VERIFY PACKAGE ****************************
OBJECT_NAME          OBJECT_TYPE     STATUS  
-------------------- --------------- ----------
PKG_COURSELIST       PACKAGE         VALID     
PKG_COURSELIST       PACKAGE BODY    VALID     

> -- ********************* CHECK ERROR FILE **************************
no rows selected


... but when I try to run it like the following or from ColdFusion I get errors:

Command line: exec pkg_CourseList; (can I not do this??)

Error starting at line 1 in command:
EXEC pkg_CourseList
Error report:
ORA-06550: line 1, column 7:
PLS-00221: 'PKG_COURSELIST' is not a procedure or is undefined
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:


... or from ColdFusion

Quote:

[Macromedia][Oracle JDBC Driver][Oracle]ORA-04047: object specified is incompatible with the flag specified ORA-06512: at "SYS.DBMS_UTILITY", line 114 ORA-06512: at line 1


Thanks,
mallethead

[Updated on: Tue, 24 January 2012 10:02] by Moderator

Report message to a moderator

Re: Unable to find problem in simple package [message #540565 is a reply to message #540564] Tue, 24 January 2012 09:35 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
You don't execute packages. You execute procedures/functions in packages.
You need to tell oracle what procedure you want to call and you need to pass the appropriate parameters.
Re: Unable to find problem in simple package [message #540566 is a reply to message #540565] Tue, 24 January 2012 09:39 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
procedure has an OUT parameter which needs to be included in the call
Re: Unable to find problem in simple package [message #540567 is a reply to message #540566] Tue, 24 January 2012 09:46 Go to previous messageGo to next message
mallethead@verizon.net
Messages: 10
Registered: January 2012
Location: New Jersey
Junior Member
Thanks all. So, I found the ColdFusion problem about 10 seconds after I posted.

I understand now that I don't call packages as cookiemonster stated.

Can someone tell me the proper way to test or call this to see the 30 rows of course list should be? In SQL Developer and/or in SQL*Plus - probably it is the same.

Sorry for the baby steps, I'm trying to cram for a new job and am trying to review lots - very fast.

Thanks, mallethead
Re: Unable to find problem in simple package [message #540568 is a reply to message #540567] Tue, 24 January 2012 09:49 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
Something like this:
SQL> create or replace procedure curtest (a out sys_refcursor) as
  2  begin
  3  open a for select 1 from dual;
  4  end;
  5  /

Procedure created.

SQL> var x refcursor
SQL> exec curtest(:x);

PL/SQL procedure successfully completed.

SQL> print :x

         1
----------
         1

SQL> 
Re: Unable to find problem in simple package [message #540569 is a reply to message #540568] Tue, 24 January 2012 10:08 Go to previous messageGo to next message
mallethead@verizon.net
Messages: 10
Registered: January 2012
Location: New Jersey
Junior Member
cookiemonster,

Great, makes sense for a procedure but what if it's a procedure in a package?

It doesn't take any parameters. I had tried the following but get "invalid identifier."

select pkg_CourseList.sp_getCourseList from dual; (saw this somewhere)

I guess that what I'm not sure of is the difference between checking the result of a package versus checking the result of a stored procedure.

THanks
Re: Unable to find problem in simple package [message #540570 is a reply to message #540569] Tue, 24 January 2012 10:17 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
I think you're over analyzing what packages are. They are containers for groups of functions and procedures.
The only difference in calling a stand alone procedure and a packaged procudure is that you have to specify the package name in the call to the packaged procedure. That's it.

As for the select - that only works for functions (packaged or stand alone). You can not select procedures.

And yes it does take parameters. what do you think this is?
(
    rsCourses OUT curCourseList
  );



And a further point on terminology. Stored procedures are procedures stored in the DB. Procedures in packages are stored in the DB. So they're stored procedures as well.
Re: Unable to find problem in simple package [message #540571 is a reply to message #540569] Tue, 24 January 2012 10:18 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
You can't
select package.PROCEDURE from dual
but you can
select package.FUNCTION from dual


Procedures are just executed:
begin
  package.PROCEDURE;
end;
Re: Unable to find problem in simple package [message #540572 is a reply to message #540571] Tue, 24 January 2012 10:47 Go to previous messageGo to next message
mallethead@verizon.net
Messages: 10
Registered: January 2012
Location: New Jersey
Junior Member
All, thanks for sticking with me on this. Obviously there's just something that's not clear.

In the end, I want to see some result from the stored procedure in the SQL Developer tool that I'm working in. Or even in SQL*Plus. I ca see that package/procedure is working from ColdFusion since I'm outputting the result over there. But I've tried the following (and several other) variations and never see the 30 courses listed as a Query Result in SQL Developer or SQL* Plus.

BEGIN
pkg_CourseList.sp_GetCourseList(rsCourses);
END;

BEGIN
pkg_CourseList.sp_GetCourseList(curCourseList);
END;

BEGIN
pkg_CourseList.sp_GetCourseList();
END;

BEGIN
pkg_CourseList.sp_GetCourseList;
END;

mallethead
Re: Unable to find problem in simple package [message #540573 is a reply to message #540572] Tue, 24 January 2012 11:00 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
I showed how to do it sqlplus above.
You need to pass a parameter for the ref cursor.
Then you need to tell sqlplus to fetch and print the contents of the ref cursor - the print command does this in sqlplus.

Executing the procedure opens the ref cursor and passes it back to the caller, nothing more.
Re: Unable to find problem in simple package [message #540574 is a reply to message #540572] Tue, 24 January 2012 11:03 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Some good readings for you:

PL/SQL User's Guide and Reference
Application Developer's Guide - Fundamentals
SQL*PlusĀ® User's Guide and Reference

Regards
Michel
Re: Unable to find problem in simple package [message #540576 is a reply to message #540574] Tue, 24 January 2012 11:16 Go to previous message
mallethead@verizon.net
Messages: 10
Registered: January 2012
Location: New Jersey
Junior Member
OK, I think I've got it now. Thanks to everyone. I appreciate it.

Mallethead
Previous Topic: ora-00972 identifier is too long
Next Topic: Concate String into tablename
Goto Forum:
  


Current Time: Thu Apr 25 23:51:06 CDT 2024