sys_refcursor
create or replace procedure p1 (one in sys_refcursor)
is
b emp.ename%type;
Start
loop
look for one in b;
exit when a % notfound;
dbms_output.put_line (b);
end loop;
end;
/
procedure is created but the execution:
Start
P1('SCOTT');
end;
/
ERROR on line 2:
ORA-06550: line 2, column 1:
PLS-00306: wrong number or types of arguments in the call to 'P1 '.
ORA-06550: line 2, column 1:
PL/SQL: Statement ignored
Note: Please help me how to run?
SQL> declare 2 rc sys_refcursor; 3 begin 4 open rc for select a from foo; 5 p1(rc); 6 end; 7 /
Tags: Database
Similar Questions
-
Hey Geeks,
I am trying to execute the procedure from the SQL Developer, but these errors are coming. What can I do wrong here...
Procedure works fine when I run the compilation and debugging mode. But I need to put later in the c# code.
SET serveroutput on;
DECLARE
OutParam1 to SYS_REFCURSOR;
OutParam2 ON Varchar;
BEGIN
/ * Call procedure package * /.
SPAT_QUERY. SP_VALIDATERULES (9, 'BIS2015001', OutParam1, OutParam2);
/ * Display parameters * /.
dbms_output.put_line ('OutParam1: ' |) OutParam2);
END;
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Error report-
ORA-06550: line 3, column 20:
PLS-00103: encountered the symbol "SYS_REFCURSOR" during the expected in the following way:
:= . (@ %; not null default range character)
06550 00000 - "line %s, column % s:\n%s".
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-Procedure below:
create or replace PACKAGE SPAT_QUERY of BODY
AS
/ * Declare a global variable to hold the result of the Validation. */
valResult varchar (10);
PROCEDURE SP_VALIDATERULES)
IN_RQST_NUM NUMBER,
IN_CASEID IN VARCHAR,
OUT_REFCURSOR ON SYS_REFCURSOR,
OUT_VAL_RSLT ON VARCHAR
)
AS
p_rc sys_refcursor;
I have NUMBER: = 0;
/ * Logical query - a loop in the Table of RULES based on request NUM * /.
BEGIN
FOR rec IN (SELECT * FROM T_RULES where RQST_NUM = IN_RQST_NUM)
LOOP
i: = i + 1;
SP_GETSECTS (IN_CASEID, rec. LYR_TX, rec. TRGT_TX, rec. EXCPTD_RSLT_CD, p_rc);
OUT_VAL_RSLT: = valResult;
END LOOP;
END SP_VALIDATERULES;
Thank you
Ken
in anonymous block, variables cannot be defined in the form. IN and OUR are not variable parameters type
Change your code to
DECLARE
OutParam1 SYS_REFCURSOR;
OutParam2 Varchar;
-
NOCOPY Hint in a SYS_REFCURSOR.
I hava a procedure with a parameter of output SYS_REFCURSOR and there is a warning that I can take advantage of a NOCOPY HINT.
Isn't the REF CURSOR already a reference? What would be the real advantage in terms of performance by adopting such a suggestion?
Thanks in advance.
It's the PLW-07203 warning that apears after a compilation in a session with:
ALTER SESSION SET PLSQL_WARNINGS = ' ENABLE: ALL ';
'Parameter 'chain' likely to benefit from the use of the NOCOPY compiler flag.
http://docs.Oracle.com/CD/B28359_01/server.111/b28278/plwus.htm#PLW-07203
Don't know, but it's probably just a warning of 'catch-all '.
REF CURSOR is pointers, so no matter how it happened, you can still have multiple pointers to the same location and risk having the problem of "aliasing" described in the doc:
http://docs.Oracle.com/CD/E11882_01/AppDev.112/e25519/subprograms.htm#CHDEBECB
Subprogramme parameter Aliasing with variable cursor parameters
Cursor variables are pointers. Therefore, if a subroutine assigns a parameter variable cursor to another, they refer to the same memory location. This folding can have unexpected results.
In the example 8-19, the procedure has two variable slider settings,
emp_cv1
andemp_cv2
. The procedure opensemp_cv1
and sets its value (which is a pointer) toemp_cv2
. Nowemp_cv1
andemp_cv2
refer to the same memory location. When the procedure endsemp_cv1
, it also closesemp_cv2
. Therefore, when the procedure is trying to get toemp_cv2
, PL/SQL raises an exception.Example 8-19 parameters sub-program Variable Cursor alias
A cursor is NOT given, so copying is not accomplish the type of separation that makes copy of data.
If you copy data, then you have TWO copies of the data. A change to each copy will NOT change the other copy.
As shown in example 8-19 in this doc copy that a cursor does not copy any data - it provides just TWO paths to it.
-
sys_refcursor function call
function execute_lov (in_lov_id NUMBER, in_opc_id, P_REF_CUR to SYS_REFCURSOR)
end;
How to call iam funtion todo as this error of setting train can u help me for this
Declare
v_rc sys_refcursor;
mycv1 sys_refcursor;
BEGIN
SELECT DTC_LC_WEB_PKG. EXECUTE_LOV (75,2345,v_rc) in the double mycv1;
dbms_output.put_line (' lines: ' | mycv1);
END;
Thank you
Olivier
is not necessary, I got solution
DECLARE
sys_refcursor v1;
VARCHAR2 (200) v2;
BEGIN
/ * Get ref cursor... * /.
V2: = DTC_LC_WEB_PKG. EXECUTE_LOV (75,5144,v1);
dbms_output.put_line ('refcursor' | v2);
END;
-
Hello
I have 3 tables with the following structure.
create table a_os_lang_stls
(ID NUMBER )
SWB_NUMBER VARCHAR2 (30),
Pc_NUMBER VARCHAR2 (30),
PC_FLAG TANK (1),
INSTALLATION_ord NUMBER ,
SP_OR_LATER_VSN TANK (1),
Platform VARCHAR2 (4000),
OS VARCHAR2 (4000),
LANG VARCHAR2 (4000),
LOSS_OF_FUNC_REASON_TXT VARCHAR2 (4000),
CREATION_DATE DATE ,
MODIFIED_DATE DATE ,
CREATED_BY VARCHAR2 (100 BYTE),
MODIFIED_BY VARCHAR2 (100 BYTE)
);
Insert in a_os_lang_stls
values (1 'SWB1' 'SWB0','P',1 of ','11118,14,16,234,124' '12,26,17,24,35''34,28,45,67,123,95',USER, NULL, NULL, NULL, SYSDATE);
Insert in a_os_lang_stls
values (2,'SWB1' 'SWB2','P',2 of ','111,20,14,16,124''11,26,18,24,35''35,27,42,67,123,95', SYSDATE, NULL, NULL, NULL, USER);
insert into a_os_lang_stls
values (3,'SWB1','SWB3','C', 1,'','11118,14,16,234,124','12,26,17,24,35',' 35,27,42,67,123,95', SYSDATE, NULL, NULL, NULL, USER);
insert into a_os_lang_stls
values (4,'SWB1','SWB4','C', 2,'','111,20,14,16,124','11,26,18,24,35'' 34,28,45,67,123,95, SYSDATE, NULL, NULL, NULL, USER)
CREATE TABLE os_dtls
(
OSCODE VARCHAR2 (10 BYTE),
ID NUMBER DEFAULT NULL,
AG_OSCODE VARCHAR2 (250 BYTE),
);
insert into os_dtls
values ('HUX', 12, 'HP UNIX');
insert into os_dtls
values('SUX',26,'SOLARIS');
insert into os_dtls
values ('LUX', 17, 'LINUX');
CREATE TABLE lang_dtls
(
LANGCD TANK (2 BYTE),
LANGNAME VARCHAR2 (255 BYTE),
ID NUMBER DEFAULT 1 NOT NULL
);
insert into lang_dtls
values ('ENG', 'ENGLISH UK', 35);
insert into lang_dtls
values ('UEG', 'USA ENGLISH', 27);
insert into lang_dtls
values('FR','FRENCH',45);
Information on the database:
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production
PL/SQL version 11.1.0.7.0 - Production
Production base 11.1.0.7.0
AMT for Linux: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - Production
I have to write a procedure like this
procedure os_lang_info (P_SB_NO IN varchar2, p_pcur sys_refcursor, p_ccur, sys_refcursor );
The requirement is to get the details for a given swb_no where pc_flag is P or C pass like 2 different sys_refcursor. But the value of column of bones and lang I need to map to the os_dtls and lang_dtls tables to get the ag_oscode and langname respectively for the corresponding id then through sys_refcursor.
So sys_refcursor structure will be
Open the p_pcur for
Select * from a_os_lang_stls
where swb_number = p_sb_no
and PC_FLAG = 'P' ;
so the output will resemble the following
1 , « SWB1 » , « SWB0 » , 'P' , 1 , 'S' , '11118,14,16,234,124' , «HP UNIX,SOLARIS,LINUX,... « , "UK ENGLISH,US ENGLISH,FRENCH,...» ', NULL, NULL, NULL, USER, SYSDATE
I must get the id separated by commas of column bone and lang and map to the corresponding table to get the names separated by commas of the bones and langs and pass it as a component of sys_refcursor.
Open the p_ccur for
Select * from a_os_lang_stls
where swb_number = p_sb_no
and PC_FLAG = 'C';
Could someone please help me how to convert the value separated by commas in a comma separated value new map to another table and pass it as part of the sys_refcursor.
Thanks in advance.
Kind regards
SB2011
Hello. Here are the queries for the two sys_refcursors.
(1) FOR THE FLAG = 'P '.
SELECT T1.ID,
T1. SWB_NUMBER,
T1. PC_NUMBER,
T1. PC_FLAG,
T1. INSTALLATION_ORD,
T1. SP_OR_LATER_VSN,
T1. PLATFORM,
T1. OS_CODE,
T2. LANG_CODE
DE)
SELECT T1.ID,
SWB_NUMBER,
PC_NUMBER,
PC_FLAG,
INSTALLATION_ORD,
SP_OR_LATER_VSN,
PLATFORM,
RTRIM (XMLAGG (XMLELEMENT(A,AG_OSCODE,',')). Extract ('//Text ()'), ',') OS_CODE
FROM (SELECT ID,
SWB_NUMBER,
PC_NUMBER,
PC_FLAG,
INSTALLATION_ORD,
SP_OR_LATER_VSN,
PLATFORM,
(COLUMN_VALUE). GETNUMBERVAL() os_id
Of a_os_lang_stls t, xmltable (os) t1) T1.
OS_dtls T2
WHERE T2.ID = T1. OS_ID
GROUP OF T1.ID,
SWB_NUMBER,
PC_NUMBER,
PC_FLAG,
INSTALLATION_ORD,
SP_OR_LATER_VSN,
T1 PLATFORM),
(SELECT T1.ID,
SWB_NUMBER,
PC_NUMBER,
PC_FLAG,
INSTALLATION_ORD,
SP_OR_LATER_VSN,
PLATFORM,
RTRIM (XMLAGG (XMLELEMENT(A,LANGNAME,',')). Extract ('//Text ()'), ',') LANG_CODE
FROM (SELECT ID,
SWB_NUMBER,
PC_NUMBER,
PC_FLAG,
INSTALLATION_ORD,
SP_OR_LATER_VSN,
PLATFORM,
(COLUMN_VALUE). GETNUMBERVAL() lang_id
Of a_os_lang_stls t, xmltable (lang) t1) T1.
lang_dtls T2
WHERE T2.ID = T1.lang_id
GROUP OF T1.ID,
SWB_NUMBER,
PC_NUMBER,
PC_FLAG,
INSTALLATION_ORD,
SP_OR_LATER_VSN,
T2 PLATFORM)
WHERE T1.ID = T2.ID
AND T1. SWB_NUMBER = T2. SWB_NUMBER
AND T1. PC_NUMBER = T2. PC_NUMBER
AND T1. INSTALLATION_ORD = T2. INSTALLATION_ORD
AND T1. PLATFORM = T2. PLATFORM
AND T1. PC_FLAG = "P";
(2) PC_FLAG FOR = 'C '.
SELECT T1.ID,
T1. SWB_NUMBER,
T1. PC_NUMBER,
T1. PC_FLAG,
T1. INSTALLATION_ORD,
T1. SP_OR_LATER_VSN,
T1. PLATFORM,
T1. OS_CODE,
T2. LANG_CODE
DE)
SELECT T1.ID,
SWB_NUMBER,
PC_NUMBER,
PC_FLAG,
INSTALLATION_ORD,
SP_OR_LATER_VSN,
PLATFORM,
RTRIM (XMLAGG (XMLELEMENT(A,AG_OSCODE,',')). Extract ('//Text ()'), ',') OS_CODE
FROM (SELECT ID,
SWB_NUMBER,
PC_NUMBER,
PC_FLAG,
INSTALLATION_ORD,
SP_OR_LATER_VSN,
PLATFORM,
(COLUMN_VALUE). GETNUMBERVAL() os_id
Of a_os_lang_stls t, xmltable (os) t1) T1.
OS_dtls T2
WHERE T2.ID = T1. OS_ID
GROUP OF T1.ID,
SWB_NUMBER,
PC_NUMBER,
PC_FLAG,
INSTALLATION_ORD,
SP_OR_LATER_VSN,
T1 PLATFORM),
(SELECT T1.ID,
SWB_NUMBER,
PC_NUMBER,
PC_FLAG,
INSTALLATION_ORD,
SP_OR_LATER_VSN,
PLATFORM,
RTRIM (XMLAGG (XMLELEMENT(A,LANGNAME,',')). Extract ('//Text ()'), ',') LANG_CODE
FROM (SELECT ID,
SWB_NUMBER,
PC_NUMBER,
PC_FLAG,
INSTALLATION_ORD,
SP_OR_LATER_VSN,
PLATFORM,
(COLUMN_VALUE). GETNUMBERVAL() lang_id
Of a_os_lang_stls t, xmltable (lang) t1) T1.
lang_dtls T2
WHERE T2.ID = T1.lang_id
GROUP OF T1.ID,
SWB_NUMBER,
PC_NUMBER,
PC_FLAG,
INSTALLATION_ORD,
SP_OR_LATER_VSN,
T2 PLATFORM)
WHERE T1.ID = T2.ID
AND T1. SWB_NUMBER = T2. SWB_NUMBER
AND T1. PC_NUMBER = T2. PC_NUMBER
AND T1. INSTALLATION_ORD = T2. INSTALLATION_ORD
AND T1. PLATFORM = T2. PLATFORM
AND T1. PC_FLAG = 'C ';
-
Procedure with input output and num_array sys_refcursor
Hello
I have to write a procedure with input of type of parameter num_array which will forward a list of IDs to the procedure and the output is sys_refcursor that will pass the id with the other columns in the table to the list of identifiers.
operating system is the table with the id, os_name column with more than a few columns.
create table os
(identification number,
OS_name varchar2 (30),
.. .few more columns);
I spend the os_name with id through the sys_refcursor.
So I created the following procedure.
num_array is a type of data defined by the user that is created as follows:
create or replace type num_array in the table to the number;
/
create or replace procedure get_os_lang_dtls (num_array, id_os sys_refcursor id_num)
is
Start
/ * oses is the main table with id, os_name with other columns
/ * oses_gtt is the temporary table with id number data type varchar2 os_name * /.
for indx in 1.id_num.count
loop
insert into os_gtt
SELECT id, os_name
of the operating system
where id = id_num (indx);
end loop;
commit;
Open the id_os for
Select * from os_gtt;
end;
/
I created a global temporary table with the column id and os_name.
Insert in this table by using the id of i / p and setting os_name recovery operating system for this id in the loop.
Then I open the exit sys_refcursor.
Could someone please suggest me a better way to write the same logic?
Thanks in advance
No need of the TWG or anything too flashy here.
Since you have a SQL type, you should be able to get away with...
open out_ref_cursor for select
from os, table(cast(id_num as num_array)) nu where os.id = nu.column_value; A couple of notes apart from that. ID is not a great name for a column, why not OS_ID to be online with your OS_NAME? Second, always try to avoid use of the TWG, they are handy once in awhile, but not required nearly as often as find you them.
A "rebate" in the casting of tables like that and their use in SQL is the cost based optimizer usually (depending on version) has no idea of how to do to optimize the query (it has no statistics on the table as it does on a table). In General, if you know that you have X items in this table, it is better to say Oracle. You can use the CARDINALITY indicator to tell Oracle about the number of lines, you expect your table to have on average. The default proposal is going to be your block size, so assuming that 8 k (standard) the estimate is going to be like 8000 items... probably not close to reality.
See you soon,.
-
ResultSet sys_refcursor
Hi Master,
I created a function that will return the result set of the emp table. I must use this result set in another procedure/function. Is this possible?
I have writtne a feature like this...
create or replace function test (v_sal in number) return is sys_refcursor
v_cur sys_refcursor;
Start
Open v_cur SELECT * from emp where sal > = v_sal;
Return v_cur;
end;
SQL > select test (2000) twice;
6 rows displayed.
I need to use this record to filter another subprogramme? is this possible? Please advise... !!!
Concerning
AP
-
How to call a procedure with parameter SYS_REFCURSOR OUT
Hello
With the help of Oracle 11 g R2.
I would like to know if it is possible to display the results of a SYS_REFCURSOR in a query. For example, if I had the following stored procedure
create or replace procedure testprocedure (result OUT sys_refcursor) as begin open result for select 1 from dual union all select 2 from dual; end;
I want to call this procedure similar to how a query is called and executed. Like this
Select * from testprocedure
I have seen lots of examples on the web that show how it is possible to loop through the results of a sys_refcursor inside an anonymous block and display the results using dbms_output.putline, but this isn't the method I'm looking for.
Read this: PL/SQL 101: understanding Ref Cursor
You're wrong if you think a ref cursor is a result set of data that you can query from.
-
greater than 32 KB in sys_refcursor SQL
Hello
We have to write the function/procedure to form reports in java, there we just bind the recordsets in a grid. We should return the record set as SYS_REFCURSOR.
Most of the sqls participate in rotation and length of the query is so beat 32 k.
Is it possible to move the large sql Ref Cursor?
VersionCREATE OR REPLACE FUNCTION TESTFUN (pREFCUR OUT SYS_REFCURSOR) RETURN NUMBER IS vSQLSTR VARCHAR2(32000); nRETURN NUMBER; BEGIN vSQLSTR := ' SQL > 32K '; OPEN pREFCUR FOR vSQLSTR; RETURN 1; EXCEPTION WHEN OTHERS THEN COMMONEXCEPTIONHANDLER(SQLCODE, SQLERRM); -- log errors which is having RAISE_APPLICATION_ERROR RETURN -1; END;
Added Version detailsSQL> select * from v$version; BANNER ---------------------------------------------------------------- Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod PL/SQL Release 10.2.0.1.0 - Production CORE 10.2.0.1.0 Production TNS for 32-bit Windows: Version 10.2.0.1.0 - Production NLSRTL Version 10.2.0.1.0 - Production
Published by: knksoft on June 7, 2013 06:44>
using DBMS_SQL I can analyze and execute sqls. But I have to return my output by refcursor. If this is limit PLSql, does perform a work around available?
>
The only option I can think of your Oracle version is:1. create a function pipeline using DBMS_SQL to create lines for the result set. Here is an example of PIPELINED function; your gathered lines using DBMS_SQL.
CREATE OR REPLACE function get_emp_data return emp_table_type PIPELINED as TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE; emp_cv EmpCurTyp; l_rec emp%rowtype; begin open emp_cv for select * from emp; loop fetch emp_cv into l_rec; exit when (emp_cv%notfound); pipe row( emp_scalar_type( l_rec.empno, LOWER(l_rec.ename), l_rec.job, l_rec.mgr, l_rec.hiredate, l_rec.sal, l_rec.comm, l_rec.deptno ) ); end loop; return; end; /
2. create a simple procedure that opens and returns a REF CURSOR on a call to this procedure in pipeline
OPEN myCursor FOR SELECT * FROM TABLE(get_emp_data);
This "myCursor" would be the REF CURSOR which are returned to the client.
-
SYS_REFCURSOR cannot be open / close?
SYS_REFCURSOR cannot be open / close? I spent a sys_refcursor in proceedings, want to loop data, how to do?
Thank you.
declare refCursorValue SYS_REFCURSOR; ------------ procedure -------------------- procedure displayEmpolyeeCursor(v_cur_employee SYS_REFCURSOR) is begin dbms_output.put_line('---------- cursor is calling ----'); open v_cur_employee; loop dbms_output.put_line('test'); end loop; close v_cur_employee; end displayEmpolyeeCursor; begin OPEN refCursorValue FOR SELECT * from employees; displayEmpolyeeCursor(refCursorValue); end; /
SYS_REFCURSOR cannot be open / close? I spent a sys_refcursor in proceedings, want to loop data, how to do?
A REF cursor is open when it is built.
The procedure does not try to open it again, but it is up to the consumer to close after the treatment.SQL> set serveroutput on SQL> SQL> DECLARE 2 3 rc sys_refcursor; 4 5 procedure print (p_rc in sys_refcursor) is 6 v_name scott.emp.ename%type; 7 begin 8 loop 9 fetch p_rc into v_name; 10 exit when p_rc%notfound; 11 dbms_output.put_line(v_name); 12 end loop; 13 close p_rc; 14 end; 15 16 BEGIN 17 18 open rc for select ename from scott.emp; 19 print(rc); 20 21 END; 22 / SMITH ALLEN WARD JONES MARTIN BLAKE CLARK KING TURNER JAMES FORD MILLER PL/SQL procedure successfully completed
-
normalcursor vs sys_refcursor
Hello
In the code below I opens the cursor twice. Here, I get the cursor is already open
exception
I use sys_refcursor to open the dynamic cursor. in this case, I opened the cursor twice.DECLARE CURSOR cur_emp IS SELECT * FROM emp; BEGIN OPEN cur_emp; OPEN cur_emp; END;
In the normal cursor, I get the exception. In the sys_refcursor that I don't have the cursor is already openDECLARE l_curemp sys_refcursor; BEGIN OPEN l_curemp FOR SELECT * FROM emp; OPEN l_curemp FOR SELECT * FROM emp; END;
exception. Why?
can someone explain me detailed?Hello
in the second example, you do not use a cursor - it's a cursor variable.
Oracle documentation > other OPEN-FOR statements can open the same variable cursor for different queries. You must not close a cursor variable before reopening. When you reopen a cursor to a different query variable, the previous query is lost.http://docs.Oracle.com/CD/B19306_01/AppDev.102/b14261/cursor_variables.htm
-
sys_refcursor and Ref Cursor
Hello
I found this diffrence between ref and sys_refcursor slider.
If you specify return_type, then the variables of type and slider REF CURSOR of this type are strong; If not,
they are weak.
The variables SYS_REFCURSOR and slider of this type are weak.
my situation is that I must write a procedure stored so many reports entery pages. little enter pages use typed data groups and can't.
so please tel me what is the best in terms of performance and maintainability above three conditions?
Yours sincerely944768 wrote:
my situation is that I must write a procedure stored so many reports entery pages. little enter pages use typed data groups and can't.
Called stored procedures what and where?
If, with a layer of app such as Java or .net, then they do not distinguish between weak and strong ref Cursor - because it is a concept of PL/SQL.
And by using a ref cursor type in PL/SQL is intended to provide a mechanism to pass the handle of real cursor SQL cursor created in this session, the client (for example Java or .net). Nothing more. So, why even care that PL/SQL? a weak or strong Ref to the application layer slider
so please tel me what is the best in terms of performance and maintainability above three conditions?
I find always frustrating that there is this concept that some methods to create cursors, results in faster and better than other methods, the sliders. It is a concept of bs. All SQLs are analyzed as a SQL cursors. Each. Unique. One. By the SAME CBO.
If the client code (Java, PL/SQL or other) you write for this SQL cursor DOES NOT change the source SQL.
This therefore does not cause the CBO now compile a different SQL execution plan for her. The CBO does not care if your code uses a strong Ref Cursor or a weak Ref Cursor, or a slider DBMS_SQL, an explicit cursor, or whatever. Those are concepts of customer. And do not change the execution plan of cursor SQL on the server. Or its planned performance/cost.
Yes, your client code (Java, PL/SQL, etc.) can use the SQL cursor on the server-side evil - and this can affect performance.
But waiting for a weak Ref cursor will somehow cause a faster cursor or slower for the same SQL statement, that a strong Ref cursor is not understanding what SQL cursor is, and how the customer interacts with its data types, the classes of customers and its customer interfaces with this SQL cursor.
-
collection vs sys_refcursor parameter
When it provides a set of results in a function parameter, are there advantages/disadvantages to using a sys_refcursor vs collection type a user defined?>
I proposed an iteration through the game of results that foo() returns and then return pipelined (sorry, should have made clear that) the lines of a collection, which is a function of adapter that would take the ref cursor and return a "table" can be reached. So instead of taking a p_deptno, as in your example, the adapter function would take the ref cursor returned by foo() as a parameter and then loop through it every record out of pipes. Is this the best approach?
>
This is the ONLY approach that you will be able to use.BluShadow wrote a final piece that covers ALL of the options. Towards the end of the second page is an example in pipeline similar to what you ask in the topic.
PL/SQL 101: Understand the Ref Cursor -
sys_refcursor do not fetch any data, even if the query returns the value
I use sys_refcursor to return the columns and aid below the procedure to do. Although the data are there in table_1 and table_2.
PROCEDURE test_pro (abc_date N, DATE,
cur_get_data ON sys_refcursor
)
OPEN cur_get_data
for
Select A.col1, B.col2
from table_1 A
where A.dis_date = abc_date
left outer join
table_2 B
on
A.dis_date = B.dis_date;
IF cur_get_data % rowcount = 0
then
raise e_error;
END if;
EXCEPTION
When e_error
then
-no_data_found;
while others
then
-(giving an error with the SQL error code);
END test_pro;
When running under sql in the sql pl/sql developer window pick
data
Select A.col1, B.col2
from table_1 A
where A.dis_date = abc_date
left outer join
table_2 B
on
A.dis_date = B.dis_date;
But while testing the test_pro in the test of the pl/sql Developer window, it is
do not fetch all data and raise e_error every time
is there a problem arising from the use IF cur_get_data % rowcount = 0 whenever that happens in the exception block.
so can someone please put a few ideas what cud be the reason for this?PROCEDURE test_pro(abc_date IN DATE, cur_get_data OUT sys_refcursor ) is BEGIN OPEN cur_get_data for select A.col1,B.col2 from table_1 A where A.dis_date = abc_date left outer join table_2 B on A.dis_date = B.dis_date; /* while testing let exceptions just pop out EXCEPTION when no_data_found then ------no_data_found; when others then --------(giving SQL error with error code); */ END test_pro;
then you test as something like
declare my_date date := to_date('20120621','yyyymmdd'); my_cursor sys_refcursor; col1 ... ; col2 ... ; begin test_pro(my_date,my_cursor); loop fetch my_cursor into col1,col2; exit when my_cursor%notfound; dbms_output.put_line(col1 || ' ~ ' || col2); end loop; end;
Concerning
Etbin
-
procedure call with sys_refcursor as a parameter in the procedure
Hello
I tried the following procedure after sys_refcursor as parameter of a procedure,
And confused about the procedure call
How can I call the above procedure to get the dataCREATE OR REPLACE PROCEDURE test_ref (emp_cur IN sys_refcursor) IS emp_rec Z_emp%ROWTYPE; BEGIN LOOP FETCH emp_cur INTO emp_rec; EXIT WHEN emp_cur%NOTFOUND; dbms_output.put_line(emp_rec.ename ||' is a ' || emp_rec.job); END LOOP; END;
Thank youYou must declare a variable sys_refcursor and open it with the necessary query and then pass that variable as a parameter to your procedure.
Something like that.
set serveroutput on declare my_cursor sys_refcursor; begin open my_cursor for select * from employee; test_ref (my_cursor); end; /
Maybe you are looking for
-
Two Apple ID and...
I have two Apple ID, even if I only want to use a. I get repeated requests to connect to my account (main/desirable), but the password (that I've reset) is not accepted. I am trying to connect it to iTunes and get this message: there is a problem of
-
Lock on an i7 2670QM Intel Turbo Boost?
Hello My HP Envy 15 - 3040nr has an Intel i7-2670QM processor, which works very well with Turbo Boost technology. My laptop goes to a maximum of 3.0 GHz under full load (I give heavy gameplay videos) and is Underclocks do very well when it is in powe
-
3 failed attempts to download El Capitan
11 Mac OS 10.9 inches air I was part of the beta version of El Capitan and my machine seems to be running slow. After reading the reviews of the Forum, I started again to Maverick. Now that Apple seems to have worked on many bugs on El Capitan, I wo
-
Hall 20: Error code 0q 0000185
There is a 0q 0000185 error please help, I couldn't start my computer anyway please help me.
-
How can I choose to download all my music library on my windows pc 10 icloud iTunes seems to he scratched my machine! ?? Thank you