I have been using Oracle (10g.2) as a PHP programmer for almost 3 years, but when I gave the assignment, I first tried using cursors and link types. And I I searched the Internet when I ran into problems, and this error ora-00932 really overloaded me. I need help from an old hand.
Here is what I was doing with. I want to select rows from a table and put them in the cursor, and then use the record type to collect them in an associative array. And again from this associative array, make the cursor. Do not ask me why, I write such complex code, because I need it for a more complex purpose. Maybe I'm embarrassing you, so let me show you my codes.
I have 2 types defined under the types tab in Toad. One of them is the type of object:
CREATE OR REPLACE TYPE R_TYPE AS OBJECT(sqn number,firstname VARCHAR2(30), lastname VARCHAR2(30));
Another is the collection type, which uses the object type created above:
CREATE OR REPLACE TYPE tr_type AS TABLE OF r_type;
Then I create the package:
CREATE OR REPLACE PACKAGE MYPACK_PKG IS TYPE MY_REF_CURSOR IS REF CURSOR; PROCEDURE MY_PROC(r_cursor OUT MY_REF_CURSOR); END MYPACK_PKG;
Packing case:
CREATE OR REPLACE PACKAGE BODY MYPACK_PKG AS PROCEDURE MY_PROC(r_cursor OUT MY_REF_CURSOR) AS rcur MYPACK_PKG.MY_REF_CURSOR; sql_stmt VARCHAR2(1000); l_rarray tr_type := tr_type(); l_rec r_type; BEGIN sql_stmt := 'SELECT 1,e.first_name,e.last_name FROM hr.employees e '; OPEN rcur FOR sql_stmt; LOOP fetch rcur into l_rec; exit when rcur%notfound; l_rarray := tr_type( l_rec ); END LOOP; CLOSE rcur;
I commented on the last line where I open the cursor. Since this causes another error when starting the procedure in the Toad SQL Editor, and this is the second question I will ask. And finally, I run the code in Toad:
variable r refcursor declare r_out MYPACK_PKG.MY_REF_CURSOR; begin MYPACK_PKG.MY_PROC(r_out); :r := r_out; end; print :r
There I get error ora-00932.