Unable to find problem in simple package [message #540564] |
Tue, 24 January 2012 09:26 |
|
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 #540568 is a reply to message #540567] |
Tue, 24 January 2012 09:49 |
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 #540570 is a reply to message #540569] |
Tue, 24 January 2012 10:17 |
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 #540573 is a reply to message #540572] |
Tue, 24 January 2012 11:00 |
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.
|
|
|
|
|