REF CURSOR ERROR
I get the following error when you try to select using a ref cursor
SQL error: ORA-06504: PL/SQL: return variables of the game results or the query types do not match
Here are the steps that I have followeed. Can someone tell me what I did wrong.
-CREATE AN OBJECT
create or replace type rsn_rec as object ( rsn_cd varchar2(10), rsn_desc varchar2(30) );
-CREATES A TABLE OF OBJECT
create or replace type rsn_tbl as table of rsn_rec;
PACKAGE/CREATED FUNCTION
create or replace package pkg_rept_test as type refcur is ref cursor; function get_rsn return rsn_tbl pipelined; end pkg_rept_test; create or replace package body pkg_rept_test as function get_rsn return rsn_tbl pipelined is o_cursor refcur; rec rsn%ROWTYPE; begin open o_cursor for select rsn_cd, rsn_desc from rsn; loop fetch o_cursor into rec; exit when (o_cursor%notfound); pipe row(rsn_rec(rec.rsn_cd, rec.rsn_desc) ); end loop; return; end; end pkg_rept_test;
-THE TABLE SELECTION
select * from table(pkg_rept_test.get_rsn)
-ERROR
SQL error: ORA-06504: PL/SQL: return variables of the game results or the query types do not match
Your code works for me just as you posted.
Connected to:
Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production
With partitioning, OLAP, Data Mining and Real Application Testing options
SQL > create table rsn (rsn_cd varchar2 (10), rsn_desc varchar2 (30));
Table created.
SQL > insert into rsn values ("cd test", "test description");
1 line of creation.
SQL > commit;
Validation complete.
SQL > create or replace the rsn_rec as an object type
2 (
3 rsn_cd varchar2 (10),
rsn_desc 4 varchar2 (30)
5 );
6.
Type of creation.
SQL > create or replace type rsn_tbl in the rsn_rec table;
2.
Type of creation.
SQL > create or replace package pkg_rept_test as
2 type refcur is ref cursor;
3 function get_rsn return rsn_tbl in pipeline;
4 end pkg_rept_test;
5.
Package created.
SQL > create or replace package body pkg_rept_test as
2 function get_rsn
3 return rsn_tbl pipeline is
4 o_cursor refcur.
5 rec rsn % ROWTYPE;
6 start
7. open o_cursor for
8. Select
rsn_cd 9,.
10 rsn_desc
11 of rsn;
12 loop
13 extract o_cursor in rec;
When exit 14 (o_cursor % notfound);
line 15 pipe (rsn_rec (rec.rsn_cd, rec.rsn_desc)
16 );
17 end of loop;
18 return;
end 19;
20 end pkg_rept_test;
21.
Package body created.
SQL > select * from table (pkg_rept_test.get_rsn);
RSN_CD RSN_DESC
---------- ------------------------------
tests of cd test description
Tags: Database
Similar Questions
-
Hello expert;
I have a function that returns a ref cursor, but the function may not return anything. I would like to know what is the best way to manage the error message
ORA-06503: PL/SQL: function returned no value - slider Ref
.. Please see below.
function f_de return latest_cur is my_l_cur l_cur; begin open my_l_cur for select max(dateadded) as dateadded from tbl_test; end;
I was wondering what is the best way to manage. I know I could use a count, and if the number is greater than 0, manipulate, but I was looking for the best way to manage it.
user13328581 wrote:
Hello expert;
I have a function that returns a ref cursor, but the function may not return anything. I would like to know what is the best way to manage the error message
ORA-06503: PL/SQL: function returned no value - slider Ref
.. Please see below.
- latest_cur the f_de function return is
- my_l_cur l_cur;
- Start
- Open the my_l_cur for
- Select max (dateadded) as dateadded
- of tbl_test;
- end;
I was wondering what is the best way to manage. I know I could use a count, and if the number is greater than 0, manipulate, but I was looking for the best way to manage it.
by definition a FUNCTION returns a value, but your code isn't working; Therefore, the error is thrown.
RETURN MY_L_CUR;
the top line should take place before the END; statement.
-
How to clear the Ref Cursor runtime error
Hello everyone,
the code as follows
When I run this code im gettingcreate or replace procedure Country_sel(key in varchar2) as cc Res_RelcountryLan.countrycode%type; len Res_Language.langname_en%type; lid Res_Language.langid%type; ab Res_Language.Abrivation%type; type refcursorr is ref cursor; cur refcursorr; d_stmt varchar2(100); begin d_stmt := 'select RCL.countrycode,RL.langid,RL.langname_'||key||', RL.Abrivation from Res_RelCountryLan RCL inner join Res_Language RL ON RCL.LangId = RL.LangId'; open cur for d_stmt; loop fetch cur into cc,lid,len,ab; if cur%found then dbms_output.put_line(cc||lid||len||ab); else exit; end if; end loop; close cur; commit; end Country_sel;
can you please help me get rid of this problem.ORA-06502: PL/SQL: numeric or value error: character string buffer too small ORA-06512: at "RASOOL.COUNTRY_SEL", line 11 ORA-06512: at line 6
thanking you,
Prakashd_stmt varchar2(100);
Increase the size of d_stmt. Your an a larger string assignment
d_stmt := 'select RCL.countrycode,RL.langid,RL.langname_'||key||',RL.Abrivation from Res_RelCountryLan RCL inner join Res_Language RL ON RCL.LangId = RL.LangId';
The size of the string above is more than 100 characters.
-
Error when you work with Ref Cursor
Hi, I tried the following, but the err
Error isDECLARE TYPE ref_nm IS REF CURSOR; vref REF_NM; vemp emp%rowtype; BEGIN OPEN vref FOR SELECT ename ,sal FROM EMP; LOOP FETCH vref INTO vemp; EXIT WHEN vref%NOTFOUND; DBMS_OUTPUT.PUT_LINE ( vemp.ename ||','||vemp.sal ); END LOOP; CLOSE vref; END;
ORA-06504: PL/SQL: Return types of Result Set variables or query do not match
Use you this structure as a buffer of extraction:
PEMV emp % rowtype;This structure contains the whole line of EMP - all columns.
That's what you're looking for cursor - 2 columns (not the whole line):
Vref OPEN for SELECT ename, sal of EMP;You can not expect from PL/SQL to find out how to move the 2 column values in a structure that has more than just 2 columns. The error message is quite clear about this - read and think what is transport of the error.
-
REF cursor kicking package compilation error
I have a package with the following procedure:
It keeps giving me the error "encountered the symbol"REF"during awaits one of the following values:" any idea of another way to do this dynamic SQL cursor, or is there something I'm not here?PROCEDURE INTERPRET_DATAVRSN ( p_table IN VARCHAR2) AS cursor Generic_Tab IS REF CURSOR; c_sub Generic_Tab; v_SQL VARCHAR2(2000); v_SQLUpdate VARCHAR2(2000); v_RawDataVrsn VARCHAR2(200); BEGIN -- Start by selecting all of the unique values in the table. v_SQL := 'select distinct DataVrsn_in from '||p_table||' '; OPEN c_sub for v_SQL; -- Then process each unique value. Loop FETCH c_sub into v_RawDataVrsn; exit when c_sub %notfound; v_SQL := 'update '||p_table||' set DataVrsn='''; if (Instr(Upper(trim(v_RawDataVrsn)), 'V') > 0) then begin v_SQL := v_SQL||Replace(v_RawDataVrsn, 'V', '')||''' '; end else begin v_SQL := v_SQL||v_RawDataVrsn||''' '; end end if; v_SQL := v_SQL||''' where DataVrsn_in='''||v_RawDataVrsn||''' '; EXECUTE IMMEDIATE v_SQL; end loop; close c_sub; commit work; EXCEPTION WHEN OTHERS THEN /*DBMS_OUTPUT.PUT_LINE(' Received CODE=' || SQLCODE || ' MESSAGE=' || SQLERRM);*/ RAISE; END INTERPRET_DATAVRSN;
Thank you!Hello
It should be
type Generic_Tab IS REF CURSOR;
and is not
cursor Generic_Tab IS REF CURSOR;
In addition, your if condition does not have a begin and end, you can change it to
if (Instr(Upper(trim(v_RawDataVrsn)), 'V') > 0) then v_SQL := v_SQL||Replace(v_RawDataVrsn, 'V', '')||''' '; else v_SQL := v_SQL||v_RawDataVrsn||''' '; end if;
Arun-
-
REP-0737: must be a function of return type 'ref cursor.
Hi all
I have create a ref cursor query in reports 10 g. But it is giving error REP-0737: must be a function of return type 'ref cursor.
Here is my code
function QR_1RefCurDS return sys_refcursor is My_Cur Sys_Refcursor; begin Open My_Cur for select * from scott.emp order by deptno; return My_Cur end;
fate of the screen.
Oracle Forms/Reports has a complete PL/SQL engine and (only) the SQL parser.
However, the engine of forms/States PL / SQL and SQL Analyzer are at a level that was in the Oracle 8.0 database.
So, in the forms/States functions/procedures and forms/States triggers, you can not use SQL commands that did not exist in the 8.0 database.
The predefined SYS_REFCURSOR type is introduced in Oracle 9i.
Use this:
PACKAGE test_rc IS
TYPE of rc_type IS REF CURSOR RETURN emp % ROWTYPE;
END;
FUNCTION RETURN QR_1RefCurDS Test_rc.rc_type IS
test_rc.rc_type RC;
BEGIN
OPEN the RC to SELECT * FROM emp;
RETURN rc;
END;
Kind regards
Zlatko
-
Ref Cursor remote procedure fails
Remote database server Oracle 9iR2 1
Local database server Oracle 10 g 2 2
Remote procedure:
CREATE OR REPLACE PROCEDURE p_get_results ( i_query IN VARCHAR2 , o_refc OUT sys_refcursor ) AS BEGIN IF ( i_query IS NULL ) THEN RAISE_APPLICATION_ERROR(-20001,'The paramter i_query cannot be null') ; END IF ; OPEN o_refc FOR i_query ; EXCEPTION WHEN others THEN RAISE ; END p_get_results ; /
Local PL/SQL block
SQL> var i_query varchar2(100) SQL> var o_refc refcursor SQL> exec :i_query := 'select count(*) from oo_attrs' SQL> exec p_get_results@demo_oo2 (:i_query,:o_refc) ERROR at line 1: ORA-00604: error occurred at recursive SQL level 1 ORA-01001: invalid cursor
Check the link works and request db:
SQL> select count(*) from oo_attrs@demo_oo2; COUNT(*) ---------- 225
Am I missing something here?
Am I missing something here?
Yes - you cannot use REF CURSOR over links to db.
-
REF CURSOR as a return of a function in SQL developer
Hi team,
I have a function which returns a Ref from a function slider while getting an entry number. But once I have create an implementation of single test on it with a valid entry that he throws error like below and have failed. My SQL developer version is 4.0.2.15.21 and it turns on a Linux OS (GNU/Linux 3.10.0 - 123.6.3.el7.x86_64). Here is the error I get.
Cannot be converted to NUMBER <oracle.jdbc.driver.OracleResultSetImpl@5925237>.
oracle.dbtools.raptor.datatypes.oracle.sql.NUMBER.customUnscaledInternalValue(NUMBER.java:93)
oracle.dbtools.raptor.datatypes.oracle.sql.NumericDatum.customInternalValue(NumericDatum.java:37)
oracle.dbtools.raptor.datatypes.impl.DataTypeImpl.customInternalValueFilter(DataTypeImpl.java:411)
oracle.dbtools.raptor.datatypes.impl.DataTypeImpl.getInternalValue(DataTypeImpl.java:399)
oracle.dbtools.raptor.datatypes.impl.DataValueImpl. < init > (DataValueImpl.java:55)
oracle.dbtools.raptor.datatypes.impl.DataTypeImpl.customDataValue(DataTypeImpl.java:196)
oracle.dbtools.raptor.datatypes.impl.DataTypeImpl.getDataValue(DataTypeImpl.java:178)
Oracle.DBTools.unit_test. Runner.UtRunnerImplIterator$ UtRunnerImplObject.getDynamicValueByName (UtRunnerImplIterator.Java:324)
Oracle.DBTools.unit_test. Runner.UtRunnerImplIterator$ UtRunnerImplObject.mapDynamicValueByName (UtRunnerImplIterator.Java:301)
Oracle.DBTools.unit_test. Runner.UtRunnerImplIterator$ UT...
Please help me out here.
Please do not post double fillet.
Mark this thread ANSWER and continue to use your other thread.
-
Fetch the Ref Cursor several times
create or replace PROCEDURE refcursor1 AS TYPE r_cursor IS REF CURSOR; rcv_emp r_cursor; TYPE rec_emp IS record ( empno NUMBER, ename VARCHAR2(20 CHAR), deptno number ); recv_emp rec_emp; recv_emp2 rec_emp; ------------------------------------------------------- PROCEDURE printemployeedetails AS BEGIN loop fetch rcv_emp INTO recv_emp; exit WHEN rcv_emp%notfound; dbms_output.put_line(recv_emp.empno||'-'||recv_emp.ename||'-'||recv_emp.deptno); END loop; END; ------------------------------------------------------- PROCEDURE printemployeedetails2(p_emp r_cursor) IS BEGIN loop fetch p_emp INTO recv_emp2; exit WHEN p_emp%notfound; dbms_output.put_line(recv_emp2.empno||'-'||recv_emp2.ename||'-'||recv_emp2.deptno); end loop; END; ------------------------------------------------------- BEGIN FOR i IN (SELECT deptno FROM dept order by deptno) loop OPEN rcv_emp FOR SELECT empno,ename,deptno FROM emp WHERE deptno=i.deptno; dbms_output.put_line(i.deptno); dbms_output.put_line('--------------------'); dbms_output.put_line('calling printemployeedetails'); printemployeedetails; dbms_output.put_line(' '); dbms_output.put_line('calling printemployeedetails2'); dbms_output.put_line(' '); printemployeedetails2(rcv_emp); CLOSE rcv_emp; END loop; end;
Output:
10 -------------------- calling printemployeedetails 7839-KING-10 7782-CLARK-10 7934-MILLER-10 calling printemployeedetails2 20 -------------------- calling printemployeedetails 7566-JONES-20 7788-SCOTT-20 7902-FORD-20 7369-SMITH-20 7876-ADAMS-20 calling printemployeedetails2 30 -------------------- calling printemployeedetails 7698-BLAKE-30 7499-ALLEN-30 7521-WARD-30 7654-MARTIN-30 7844-TURNER-30 7900-JAMES-30 calling printemployeedetails2 40 -------------------- calling printemployeedetails calling printemployeedetails2
Hi all
If I open a cursor once can I collect the elements of a cursor n times as above? I see one of these procedures to print the details, but not both.
Wonder why that I'm passing same ref cursor to a second procedure.
It doesn't throw me an error indicating that the elements of the ref cursor is already read.
Thank you.
Your condition is not clear. Cursor is a pointer. He points to the result set of your query. At the time wherever you collect once, it advances the pointer to the next line and so on. I wonder if the pointer can return to the previous line once you recovered.
-
Irregular data loss - function from PL/SQL returning data using Ref Cursor
Database Version: 10.2.0.4.0 (node 2 CARS)
The high-level process flow is as below:
(1) insert records in a few tables & commit the same
(2) call the pl/sql function to extract files (on certain conditions with joins with other tables) of the tables which are filled in step 1.
-> It uses the ORDER BY clause to queries inline & line number 5000 records return for each call.
Sense - if inline query is supposed to return 1,00,000 records then 20 calls to the same function. This, because the application cannot contain records beyond number.
(3) the data returned by the ref cursor is then processed by application (Tibco BW) to generate the flat file.
We are facing the problem of data loss in the file and there is no fixed model. It happens once between 200-300 calls process.
Resolution: When the problem occurs, triggering the process and in almost every time re-outbreak of the process provides required data.
Guidance on what could be the reason?
* Examples of Code for the function:
CREATE OR REPLACE FUNCTION FUNC_GET_HRCH_TOTAL_DATA)
outinstrid in NUMBERS
outinstrkey in NUMBERS
rownumberstart in NUMBERS
rownumbereend in NUMBERS
err_code OUT VARCHAR2,
err_msg OUT VARCHAR2)
RETURN PACK_TYPES. HRCH_TOTAL_CURSOR
IS
REF_HRCH_TOTAL_CURSOR PACK_TYPES. HRCH_TOTAL_CURSOR;
BEGIN
OPEN FOR REF_HRCH_TOTAL_CURSOR
SELECT *.
FROM (SELECT A.HIERARCHY_KEY, B.KEY, B.VAL_KEY, A.KEY_NEW, C.ITEMID, B.VAL_TAG, B.sort_order, ROWNUM ROWNUMBER
OF AOD_HRCH_ITEM A, AOD_HRCH_ATTR B, AOD_HRCH_ITEMS C
WHERE A.outputid = B.outputid
AND A.outputid = C.outputid AND A.outputkey = B.outputkey
AND A.outputkey = C.outputkey AND A.outputid = outinstrid
AND A.outputkey = outinstrkey AND A.ITEM_SEQ = B.ITEM_SEQ
AND A.ITEM_SEQ = C.ITEM_SEQ AND A.HIERARCHY_LEVEL_ORDER = B.SORT_ORDER
ORDER BY A.HIERARCHY_LEVEL_ORDER DESC)
WHERE ROWNUMBER < rownumbereend
AND ROWNUMBER > = rownumberstart;
RETURN REF_HRCH_TOTAL_CURSOR;
EXCEPTION
WHILE OTHERS
THEN
err_code: = x_progress | ' - ' || SQLCODE;
err_msg: = SUBSTR (SQLERRM, 1, 500);
END FUNC_GET_HRCH_TOTAL_DATA;
/
Published by: meet_sanc on February 16, 2013 10:42Your SELECT statement is almost certainly incorrect
SELECT * FROM ( SELECT A.HIERARCHY_KEY, B.KEY, B.VAL_KEY, A.KEY_NEW, C.ITEMID, B.VAL_TAG, B.sort_order,ROWNUM ROWNUMBER FROM AOD_HRCH_ITEM A, AOD_HRCH_ATTR B, AOD_HRCH_ITEMS C WHERE A.outputid = B.outputid AND A.outputid = C.outputid AND A.outputkey = B.outputkey AND A.outputkey = C.outputkey AND A.outputid = outinstrid AND A.outputkey = outinstrkey AND A.ITEM_SEQ = B.ITEM_SEQ AND A.ITEM_SEQ = C.ITEM_SEQ AND A.HIERARCHY_LEVEL_ORDER = B.SORT_ORDER ORDER BY A.HIERARCHY_LEVEL_ORDER DESC) WHERE ROWNUMBER < rownumbereend AND ROWNUMBER >= rownumberstart;
Since the ORDER BY is applied after the ROWNUM is assigned in this case, your query is requested for a period of 5000 lines any arbitrariness. It would be perfectly valid for a single line to return in each of your 200 different calls or for a line to return in any of them.
You definitely want to do something in the sense of the canonical askTom wire
select * from ( select a.*, rownum rnum from ( YOUR_QUERY_GOES_HERE -- including the order by ) a where rownum <= MAX_ROWS ) where rnum >= MIN_ROWS
That said, it seems inconceivable that Tibco is unable to manage a cursor that returns more than a certain number of lines. You do a ton of work to return the data pages that are certainly not necessary. Unless you're saying that you somehow paralyzed your installation of Tibco giving him a ridiculously small amount of memory to process, something doesn't look good. A slider is just a pointer - it holds that no data - so the number of lines that you can extract a slider should have no impact on the amount of memory on the client application needs.
As others have already pointed out, your exception handler is almost certainly do more harm than good. Return the error codes and error messages as from the OUT parameters, instead of simply allowing the exception to propagate deletes a ton of useful information (such as the mistake of the stack) and makes your process much less robust.
Justin
-
Initialize the Ref Cursor to avoid ORA-01001: Invalid cursor
Hello
I write a stored procedure that returns a REF CURSOR. However, there are times when the cursor is not open if certain conditions are not met, so I wonder if there is a way to initialize the REF CURSOR so that the appellant does not receive the "ORA-01001: Invalid cursor" error when you try to work with the cursor, if it has not been opened.
Any help is greatly appreciated...
Thank you
Christinecad0227 wrote:
HelloI write a stored procedure that returns a REF CURSOR. However, there are times when the cursor is not open if certain conditions are not met, so I wonder if there is a way to initialize the REF CURSOR so that the appellant does not receive the "ORA-01001: Invalid cursor" error when you try to work with the cursor, if it has not been opened.
Any help is greatly appreciated...
Thank you
ChristineThe most appropriate way would be the caller to handle the situation. The caller must capture the exception of INVALID_CURSOR and do what is necessary.
Other suggestions like having a separate Pavilion or a model select all will lead the appellant to act to the particular situation, that slider is not being opened. What is the case with the exception of INVALID_CURSOR raised by oracle.
All the need for the appellant to do is manage the exception of INVALID_CURSOR and you should be good. And also INVALID_CURSOR is not a mistake, it's an exception that has a special meaning for her. In the case you sense it takes the condition when not together to return a cursor.
-
Ref Cursor as an out parameter.
Hi all
Please help me with this.
It is a small procedure where the ref cursor is used as output parameter.
There is another procedure that calls the procedure above. But during the call, it is throwing an exception that ORA-01722. What's not here? Help, please.create or replace PROCEDURE P_REFCURSOR_OUT (P_DEPTNO IN EMP.DEPTNO%TYPE, P_RECORDSET OUT SYS_REFCURSOR) AS BEGIN OPEN P_RECORDSET FOR SELECT EMPNO, EMPNM, DEPTNO FROM EMP WHERE DEPTNO = P_DEPTNO ORDER BY EMPNM; END P_REFCURSOR_OUT;
Kind regardsCREATE OR REPLACE PROCEDURE P_CALL_REFCURSOR_OUT AS L_CURSOR SYS_REFCURSOR; L_EMPNM EMP.EMPNM%TYPE; L_EMPNO EMP.EMPNO%TYPE; L_DEPTNO EMP.DEPTNO%TYPE; BEGIN P_REFCURSOR_OUT (P_DEPTNO => 1000, P_RECORDSET => L_CURSOR); LOOP FETCH L_CURSOR INTO L_EMPNM, L_EMPNO, L_DEPTNO; EXIT WHEN L_CURSOR%NOTFOUND; DBMS_OUTPUT.PUT_LINE(L_EMPNM || ' | ' || L_EMPNO || ' | ' || L_DEPTNO); END LOOP; CLOSE L_CURSOR; END P_CALL_REFCURSOR_OUT;
BS2012The cursor that you open selects the EMPNO and DEPTNO EMPNM in that order.
When you retrieve the cursor, you get in L_EMPNM, L_EMPNO, L_DEPTNO.It would seem that the first two columns have been inverted in your FETCH statement. Assuming that EMPNO is a NUMBER EMPNM is a VARCHAR2, this means Oracle trying implicitly converted to the EMPNM in a NUMBER that is causing the error.
If you change the order of the variables in your FETCH statement, the error should disappear
FETCH L_CURSOR INTO L_EMPNO, L_EMPNM, L_DEPTNO;
Justin
-
The stored procedure PL/SQL - t - it accept the custom Ref Cursor type?
I am not able to compile the following procedure in the HR schema comes with default oracle... I use Oracle 11g Release 11.2.0.2.0 Express edition. It gives me an error (given after the code block):
Block of code:
CREATE OR REPLACE PROCEDURE TEST_REF IS
DECLARE
TYPE REF_EMP IS REF CURSOR RETURN % ROWTYPE EMPLOYEES;
RF_EMP REF_EMP;
V_EMP EMPLOYEES % ROWTYPE;
BEGIN
DBMS_OUTPUT. ENABLE (1000000);
OPEN FOR RF_EMP
SELECT * FROM EMPLOYEES WHERE EMPLOYEE_ID > 100;
EXTRACT THE RF_EMP IN V_EMP;
DBMS_OUTPUT. PUT_LINE (V_EMP. FIRST_NAME. ' ' || V_EMP. LAST_NAME);
CLOSE RF_EMP;
EXCEPTION
WHILE OTHERS
THEN DBMS_OUTPUT. PUT_LINE (SQLERRM);
END TEST_REF;
/
Error:
Errors in PROCEDURE TEST_REF:
LINE/COL ERROR
-------- -----------------------------------------------------------------
2/1 PLS-00103: encountered the symbol "DECLARE" when waiting for an a
What follows:
Start function < an ID > pragma procedure subtype type
< between double quote delimited identifiers > delete the current cursor
There are the external language prior
The symbol 'start' is substituted for 'DECLARE' continue.
16/13 PLS-00103: encountered the symbol "end-of-file" when waiting for him
one of the following values:
(begin case declare exit end exception for goto if loop mod)
pragma raise return null select update while withGet rid of the DECLARED:
SQL> CREATE OR REPLACE PROCEDURE TEST_REF IS 2 TYPE REF_EMP IS REF CURSOR RETURN HR.EMPLOYEES%ROWTYPE; 3 RF_EMP REF_EMP; 4 V_EMP EMPLOYEES%ROWTYPE; 5 BEGIN 6 DBMS_OUTPUT.ENABLE(1000000); 7 OPEN RF_EMP FOR 8 SELECT * FROM EMPLOYEES WHERE EMPLOYEE_ID > 100; 9 FETCH RF_EMP INTO V_EMP; 10 DBMS_OUTPUT.PUT_LINE(V_EMP.FIRST_NAME || ' ' || V_EMP.LAST_NAME); 11 CLOSE RF_EMP; 12 EXCEPTION 13 WHEN OTHERS 14 THEN DBMS_OUTPUT.PUT_LINE(SQLERRM); 15 END TEST_REF; 16 / Procedure created. SQL> set serveroutput on SQL> exec TEST_REF; Donald OConnell PL/SQL procedure successfully completed. SQL>
SY.
-
Hello
FOR REC V_LIST LOOPING
INSERT INTO G_ID_TEMP_COMMON (TC_TYPE, TC_NUMBER_1_COL) VALUES ('T_ID_REPORT_PARM_VALUES', REC KEY);
END LOOP;
The above statement a part of the package.
V_LIST is ref cursor,
It returns a list of values,
If place the statement above in the package, it shows error when compiling the package.
Error:
Error (17887,2): PL/SQL: statement ignored
Error (17887,13): PLS-00221: 'V_LIST' is not a procedure or is not defined
Kind regards
FameTry this:
DECLARE l_key NUMBER; BEGIN ... LOOP FETCH v_list INTO l_key; -- INSERT INTO G_ID_TEMP_COMMON(TC_TYPE,TC_NUMBER_1_COL) VALUES('T_ID_REPORT_PARM_VALUES', l_key); -- EXIT WHEN v_list%NOTFOUND; END LOOP; ...
-
I want to return ref cursor based on explicit cursors
create or replace procedure get_extract (in_val in varchar2, return_cursor to sys_refcursor)
is
cursor c1 is select * from jumbo.
cursor c2 is select * from mumbo.
rec_j jumbo % rowtype;
rec_m mumbo % rowtype;
Start
If in_val = am' then
Open c1;
loop
Fetch c1 in rec_m;
When exit c1% notfound;
end loop;
Open return_cursor SELECT * from rec_m;
Close c1;
elsif in_val = 'J' then
Open c2;
loop
extract the c2 in rec_j;
When the exit c2% notfound;
end loop;
Open return_cursor SELECT * from rec_j;
Close c2;
on the other
Open return_cursor select double null.
end if;
end;
/
When I compile the procedure above, I get the error
LINE/COL ERROR
-------- ---------------------------------------------------
20/24 PL/SQL: statement ignored
20/38 PL/SQL: ORA-00942: table or view does not exist
32/24 PL/SQL: statement ignored
32/38 PL/SQL: ORA-00942: table or view does not exist
so its occurring in the open return_cursor for... statement, what is the problem with above?user650888 wrote:
I wrote the above and it worked but instead of having a select into the body of the procedure, I love it in an explicit cursorYou can't do that. The sliders don't work that way. On the closest you could get would be something like:
SQL> select * from t; ID DESCR ---------- ---------- 1 T One 2 T Two SQL> select * from t1; ID DESCR ---------- ---------- 1 T1 One 2 T1 Two SQL> create or replace procedure get_extract(in_val in varchar2, 2 return_cursor out sys_refcursor) is 3 l_cur_m varchar2(100) := 'select * from t'; 4 l_cur_j varchar2(100) := 'select * from t1'; 5 begin 6 if in_val = 'M' then 7 open return_cursor for l_cur_m; 8 elsif in_val = 'J' then 9 open return_cursor for l_cur_j; 10 else 11 open return_cursor for select null from dual; 12 end if; 13 end; 14 / Procedure created. SQL> var cur refcursor; SQL> exec get_extract('M', :cur); PL/SQL procedure successfully completed. SQL> print cur ID DESCR ---------- ---------- 1 T One 2 T Two SQL> exec get_extract('J', :cur); PL/SQL procedure successfully completed. SQL> print cur ID DESCR ---------- ---------- 1 T1 One 2 T1 Two
John
Maybe you are looking for
-
I can't see the list of my Add-ons (extensions). It shows me a blank page.
After that I updated firefox 42.0, I can't see the list of my Add-ons (extensions). I see a blank page instead. Modules work, but I can't manage/uninstall any of them.
-
Satellite A100-797: Vista Device Manager show different CPU speeds
Hi all I had an an A100-797 with Vista Home Premium 32 Bit and I was cruising along the system properties. Via 'Control panel system->' I saw the spec CPU as Processor: Intel (r) Core (TM) 2 CPU T7200 @ 2.00 Ghz, 2.00 Ghz Then I checked the CPU the D
-
The Vista is better than Windows XP Home edition?
Hello I installed vista, but is not supported & is unlikely to be the main programs I want to use with it! Is it because Vista is new, or Windows XP Home edition (which he runs under) is a better OS. I read on the forum that WXP can be used in anothe
-
Received my HP Envy 14 t 2000 a few days ago... Sound worked as a laptop by itself... Just loaded the drivers for monitor 25 inches HP and after that no sound at all. I checked the posts and see HER has become a major issue through a number of models
-
I tried to solve installation SP3.0 in sharing environment point 2007 windows 2003 32-bit, but not able to succeed. I get the following errors, please make a ticket for this problem. Product: Microsoft Windows SharePoint Services 3.0 - error 1401.Set