Fetch Ref Cursor Multiple 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
Hello All,
If i open a cursor once can i fetch the elements of a cursor n times like above? i see only either one of those procedures are printing the details but not both.
Wonder why as i am passing the same ref cursor to a second procedure.
It's neither throwing me an error saying the elements of ref cursor are already fetched.
Thank you.
>
If i open a cursor once can i fetch the elements of a cursor n times like above? i see only either one of those procedures are printing the details but not both.
Wonder why as i am passing the same ref cursor to a second procedure.
It's neither throwing me an error saying the elements of ref cursor are already fetched.
>
You can't see any such thing. That code above won't even compile let alone run.
The 'ref cursor' you are talking about is defined in a standalone procedure 'refcursor1' which does NOTHING but declare some variables that are then NEVER USED.
The other procedures try to use variables that DO NOT EXIST since they are not declared in the procedure that is trying to use them. So those procedures won't compile and even if they did compile and run each execution only does ONE fetch so the anonymous block can't possibly produce multiple rows of output.
I don't know what you claim to be seeing but it certainly isn't anything produced by the code you posted.
Similar Messages
-
Different error messages from different env while fetching ref cursor
Hi<br>
I have a package where i need to call one of the procedure.I this <br>
procedure i am returning a refcursor as out parameter.Before returning refcursor i <br>
am doing i am checking a condition if it is satisfied then I am saying return or else<br>
it will proceed and refcursor is assigned for out parameter.So i am speakig about <br>
the condition where i am exiting from procedure before refcursor parameter is <br>
assigned .And later i am tring to fetch from that cursor .So i am getting different <br>
kinds of errors which i described as follows <br>
<br>
<br>
So If execute that procedure from sqlplus uing <br>
<br>
<br>
var m ref cursor<br>
DECLARE<br>
Y NUMBER;<br>
Z NUMBER;<br>
A NUMBER;<br>
BEGIN<br>
A:=campa.dtl_inq(2,100070875,'R',Y,Z,:M);<br>
END;<br>
<br>
Then if say<br>
Print m<br>
It gives <br>
<br>
ORA-24338: statement handle not executed<br>
<br>
And if i execute this using vb application <br>
<br>
I am getting following error <br>
<br>
ORA-01023: Cursor context not found (Invalid cursor number)<br>
<br>
So i am serching the reason for different errors<br>
<br>
Regards<br>
vamsi krishna<br>The error depends on exactly what OCI calls the client software makes in accessing this invalid (null) ref cursor variable.
It would seem that SQL*Plus makes different calls than what your code and Visual Basic does - thus the different error messages returned by the two applications. -
Select Query Fetching same records multiple time
Hi ABAPers,
I have an issue where the select query is fetching the same records more than one time for particular sale order.
Kindly help to solve the issue.
Thanks in advance..
Here is the Select Query:-
SELECT VBAK~VKORG VBAK~VTWEG VBAK~VBELN VBAK~KUNNR
VBAK~ERDAT VBAK~LIFSK VBKD~INCO1 VBKD~INCO2
VBAP~MATNR VBAP~ARKTX VBAP~MATKL VBAK~BSTNK
VBAK~BSTDK VBAK~KNUMV VBAP~UEPOS VBAP~POSNR
VBAP~KWMENG VBAK~VDATU VBAP~VRKME VBAK~ERNAM VBAK~WAERK
INTO CORRESPONDING FIELDS OF TABLE IT_PENDING FROM VBAK
INNER JOIN VBAP ON VBAK~VBELN = VBAP~VBELN
INNER JOIN VBKD ON VBAK~VBELN = VBKD~VBELN
WHERE
VBAK~VBELN IN SO_VBELN AND
VBAK~ERDAT IN SO_ERDAT AND
( AUART EQ 'OR' OR AUART EQ 'ZEO' OR AUART EQ 'TA' OR AUART EQ 'LP' OR AUART EQ 'ZFOC' ) AND
VKORG IN SO_VKORG AND
VTWEG IN SO_VTWEG AND
SPART IN SO_SPART AND
KUNNR IN SO_KUNNR AND
MATNR IN SO_MATNR AND
MATKL IN SO_MATKL AND
ABGRU EQ '' AND LIFSK <> '35'.
Edited by: Suhas Saha on Jan 14, 2012 3:42 PMHello Suhale,
On retrospection, I found the query in my above response STILL HAS ONE ISSUE. When we are making a left outer join on vbkdposnr = vbapposnr we are only fetching vbkdinco1 and vbkdinco2 values where item level entries exist in VBKD which match with vbkdposnr = vbapposnr.
Actually we should bring inco1 and inco2 from vbkd when a matching entry exists in vbkd where vbkdposnr = vbapposnr and if there is no entry matching vbkdposnr = vbapposnr, then we should fetch inc01 and inco2 from VBKD where posnr = '000000' (i.e., from header).
This is how SAP behaves when you open an item in VA03 and look at inco1 and inco2. They come from the item if an entry corresponding to that item exists in VBKD otherwise they come from VBKD header record (where vbkd~posnr = '000000')
We can't use VBKD in the joins and still be able to do the above. So we need to fetch inco1, inco2 from VBKD separately like below.
FIELD-SYMBOLS: <fs_pending> LIKE LINE OF it_pending.
SELECT vbak~vkorg vbak~vtweg vbak~vbeln vbak~kunnr
vbak~erdat vbak~lifsk "vbkd~inco1 vbkd~inco2
vbap~matnr vbap~arktx vbap~matkl vbak~bstnk
vbak~bstdk vbak~knumv vbap~uepos vbap~posnr
vbap~kwmeng vbak~vdatu vbap~vrkme vbak~ernam vbak~waerk
INTO CORRESPONDING FIELDS OF TABLE it_pending
FROM vbak INNER JOIN vbap
ON vbak~vbeln = vbap~vbeln
WHERE vbak~vbeln IN so_vbeln AND
vbak~erdat IN so_erdat AND
( vbak~auart EQ 'OR' OR vbak~auart EQ 'ZEO' OR
vbak~auart EQ 'TA' OR vbak~auart EQ 'LP' OR
vbak~auart EQ 'ZFOC' ) AND
vbak~vkorg IN so_vkorg AND
vbak~vtweg IN so_vtweg AND
vbak~spart IN so_spart AND
vbak~kunnr IN so_kunnr AND
vbap~matnr IN so_matnr AND
vbap~matkl IN so_matkl AND
vbap~abgru EQ '' AND
vbak~lifsk NE '35'.
LOOP AT it_pending ASSIGNING <fs_pending>.
SELECT SINGLE inco1 inco2
FROM vbkd
INTO (<fs_pending>-inco1,<fs_pending>-inco2)
WHERE vbkd~vbeln = <fs_pending>-vbeln AND
vbkd~posnr = <fs_pending>-posnr.
IF sy-subrc NE 0.
SELECT SINGLE inco1 inco2
FROM vbkd
INTO (<fs_pending>-inco1, <fs_pending>-inco2)
WHERE vbkd~vbeln = <fs_pending>-vbeln AND
vbkd~posnr = '000000'.
ENDIF.
ENDLOOP.
Best regards,
Vishnu Tallapragada. -
Using Ref cursor in Procedure.
Hi All,
Can i use a single ref cursor multple times within the life cycle of a procedure.
Thanks,
DillipYes.
See the example here. A cursor expression is selected - repeatedly, within a loop - into emp_cur (which is of type REF CURSOR) - and emp_cur is then used to process it in a nested loop.
(By the way - this question would be better asked in the PL/SQL).
Regards Nigel -
Number of total rows returned by a ref cursor without using FETCH
Hi. How can we get the total number of rows returned by a ref cursor without doing the FETCH? I mean, if you use %ROWCOUNT, it only returns the current row number being returned in every fetch. This is not what I want. My purpose is to determine if my query using ref cursor returns greater than zero total rows without using fetch. Thanks.
As John pointed out in the thread you linked to, the only way to know how many rows a query will return is to actually fetch all the rows. Oracle doesn't know how many rows a query is going to return until it actually fetches the last row.
Plus, assuming the default transaction isolation level, if you run the same query multiple times in succession, there is no guarantee that the results will be the same.
If you just want to know whether a query will return a nonzero number of rows, why not just write the code to assume that it returns at least 1 row and handle the zero row result as an exception.
Justin -
Dynamic REF Cursor with Dynamic Fetch - Urgent
i have a pl/sql package with generates dynamic SQL statments. my problem is i want to open this SQL statment dynamically and fetch data in dynamic variable.
declare
type type_temp is REF CURSOR;
cur_temp type_temp;
mv_sql varchar2(4000);
begin
-- this will be dunamically generated and
-- hence could have any no. of columns.
mv_sql := select f1, f2, f3, f4 from table_temp;
open cur_temp for mv_sql;
fetch cur_temp into c1, c2, c3, c4;
close cur_temp;
end;
problem is my sql statment will have N no. of columns how can i fetch this N no. of columns.Very hard problem, because ref cursors do not (directly) support description!
Se mine (non-ideal) solution (it may be doable, but it isn't very practical
or easily maintainable):
1. "Generic" package
CREATE OR REPLACE PACKAGE dyn_fetch IS
TYPE ref_cur_t IS REF CURSOR;
g_query VARCHAR2 (32000);
g_count NUMBER;
g_desc_tab DBMS_SQL.DESC_TAB;
varchar2_type CONSTANT PLS_INTEGER := 1;
number_type CONSTANT PLS_INTEGER := 2;
date_type CONSTANT PLS_INTEGER := 12;
rowid_type CONSTANT PLS_INTEGER := 11;
char_type CONSTANT PLS_INTEGER := 96;
long_type CONSTANT PLS_INTEGER := 8;
raw_type CONSTANT PLS_INTEGER := 23;
mlslabel_type CONSTANT PLS_INTEGER := 106;
clob_type CONSTANT PLS_INTEGER := 112;
blob_type CONSTANT PLS_INTEGER := 113;
bfile_type CONSTANT PLS_INTEGER := 114;
PROCEDURE describe_columns;
FUNCTION record_def RETURN VARCHAR2;
END;
CREATE OR REPLACE PACKAGE BODY dyn_fetch IS
PROCEDURE describe_columns IS
l_cur INTEGER;
BEGIN
l_cur := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE (l_cur, g_query, DBMS_SQL.NATIVE);
DBMS_SQL.DESCRIBE_COLUMNS (l_cur, g_count, g_desc_tab);
DBMS_SQL.CLOSE_CURSOR (l_cur);
EXCEPTION
WHEN OTHERS THEN
IF DBMS_SQL.IS_OPEN (l_cur) THEN
DBMS_SQL.CLOSE_CURSOR (l_cur);
END IF;
RAISE;
END;
FUNCTION record_def RETURN VARCHAR2 IS
l_record_def VARCHAR2 (32000);
l_type VARCHAR2 (100);
l_col_type PLS_INTEGER;
l_col_max_len PLS_INTEGER;
l_col_precision PLS_INTEGER;
l_col_scale PLS_INTEGER;
BEGIN
FOR i IN 1..g_count LOOP
l_col_type := g_desc_tab(i).col_type;
l_col_max_len := g_desc_tab(i).col_max_len;
l_col_precision := g_desc_tab(i).col_precision;
l_col_scale := g_desc_tab(i).col_scale;
IF l_col_type = varchar2_type THEN
l_type := 'VARCHAR2(' || l_col_max_len || ')';
ELSIF l_col_type = number_type THEN
l_type := 'NUMBER(' || l_col_precision || ',' || l_col_scale || ')';
ELSIF l_col_type = date_type THEN
l_type := 'DATE';
ELSIF l_col_type = rowid_type THEN
l_type := 'ROWID';
ELSIF l_col_type = char_type THEN
l_type := 'CHAR(' || l_col_max_len || ')';
-- ELSIF l_col_type = ...
-- long_type, raw_type ...
END IF;
l_record_def := l_record_def || ' col_' || i || ' ' || l_type || ',';
END LOOP;
l_record_def := RTRIM (l_record_def, ',');
RETURN l_record_def;
END;
END;
Note that procedure "record_def" creates columns names as col_1 (col_2 ...)
because SELECT clause in your query can be without aliases, for example
"SELECT deptno || dname FROM dept".
2. Your package which returns query nad ref cursor
CREATE OR REPLACE PACKAGE test IS
PROCEDURE set_query (p_query VARCHAR2 := NULL);
FUNCTION ref_cur RETURN dyn_fetch.ref_cur_t;
END;
CREATE OR REPLACE PACKAGE BODY test IS
PROCEDURE set_query (p_query VARCHAR2 := NULL) IS
l_query VARCHAR2 (32000) :=
' SELECT e.empno, e.ename,' ||
' e.deptno, d.dname' ||
' FROM emp e,' ||
' dept d' ||
' WHERE e.deptno = d.deptno';
BEGIN
IF p_query IS NULL THEN
dyn_fetch.g_query := l_query;
ELSE
dyn_fetch.g_query := p_query;
END IF;
END;
FUNCTION ref_cur RETURN dyn_fetch.ref_cur_t IS
l_ref_cur dyn_fetch.ref_cur_t;
BEGIN
OPEN l_ref_cur FOR dyn_fetch.g_query;
RETURN l_ref_cur;
END;
END;
Why we need two separate procedures (functions) in your package ?
a) Receiving program must use dynamic SQL, but in dynamic block we can access
only PL/SQL code elements that have global scope (standalone functions and procedures,
and elements defined in the specification of a package).
Unfortunately, cursor variables cannot be defined in the specification of a package
(cannot be global variables).
b) Receiving program must get the column list before ref cursor.
So, we have two options: call (in receiving program) the same function two times
(once to get the column list and once to return a ref cursor)
or use one procedure (or function) for returning query (to get the column list)
and second function for returning a ref cursor.
3. Your receiving program
CREATE OR REPLACE PROCEDURE test_fetch_ref_cur (p_query VARCHAR2 := NULL) IS
l_statement VARCHAR2 (32000);
FUNCTION process_def RETURN VARCHAR2 IS
l_process_def VARCHAR2 (32000);
BEGIN
l_process_def := 'DBMS_OUTPUT.PUT_LINE (';
FOR i IN 1 .. dyn_fetch.g_count LOOP
l_process_def := l_process_def || ' l_record.col_' || i || ' || ''>>'' || ';
END LOOP;
l_process_def := RTRIM (l_process_def, ' || ''>>'' || ') || ');';
RETURN l_process_def;
END;
BEGIN
test.set_query (p_query);
dyn_fetch.describe_columns;
l_statement :=
' DECLARE' ||
' TYPE record_t IS RECORD (' ||
dyn_fetch.record_def || ');' ||
' l_record record_t;' ||
' l_ref_cur dyn_fetch.ref_cur_t;' ||
' BEGIN' ||
' l_ref_cur := test.ref_cur;' ||
' LOOP' ||
' FETCH l_ref_cur INTO l_record;' ||
' EXIT WHEN l_ref_cur%NOTFOUND;' ||
process_def ||
' END LOOP;' ||
' CLOSE l_ref_cur;' ||
' END;';
EXECUTE IMMEDIATE l_statement;
END;
You can test this with:
SET SERVEROUTPUT ON;
EXECUTE test_fetch_ref_cur;
Note that we can try to use more generic solution:
CREATE OR REPLACE PACKAGE dyn_fetch IS
-- SAME AS BEFORE, PLUS:
PROCEDURE fetch_ref_cur (
p_function_ref_cur VARCHAR2,
p_process_def VARCHAR2);
END;
CREATE OR REPLACE PACKAGE BODY dyn_fetch IS
-- SAME AS BEFORE, PLUS:
PROCEDURE fetch_ref_cur (
p_function_ref_cur VARCHAR2,
p_process_def VARCHAR2)
IS
l_statement VARCHAR2 (32000);
BEGIN
l_statement :=
' DECLARE' ||
' TYPE record_t IS RECORD (' ||
record_def || ');' ||
' l_record record_t;' ||
' l_ref_cur dyn_fetch.ref_cur_t;' ||
' BEGIN' ||
' l_ref_cur := ' ||
p_function_ref_cur || ';' ||
' LOOP' ||
' FETCH l_ref_cur INTO l_record;' ||
' EXIT WHEN l_ref_cur%NOTFOUND;' ||
p_process_def ||
' END LOOP;' ||
' CLOSE l_ref_cur;' ||
' END;';
EXECUTE IMMEDIATE l_statement;
END;
END;
CREATE OR REPLACE PROCEDURE test_fetch_ref_cur (p_query VARCHAR2 := NULL) IS
FUNCTION process_def RETURN VARCHAR2 IS
-- SAME AS BEFORE
END;
BEGIN
test.set_query (p_query);
dyn_fetch.describe_columns;
dyn_fetch.fetch_ref_cur (
p_function_ref_cur => 'test.ref_cur',
p_process_def => process_def);
END;
Regards,
Zlatko Sirotic -
How to fetch NO DATA FOUND exception in Ref Cursor.
In my procedure ref cursor is out parameter with returns dataset. in my proceudre
its like...
OPEN pPymtCur FOR
select.....
when I call this procedure from report to get dataset it causes NO DATA FOUND exception.
How to fetch this exception in my oracle procedure so I can get some other data.
Any Idea to do this?
Edited by: Meghna on 17-Jun-2009 22:28Mass25 wrote:
Correct me if I am wrong.
So if I do something as follows in my stored proc, I do not have to check for NO_DATA_FOUND?
OPEN my_CuRSR FOR
SELECT DISTINCT blah blah blahmy_cursr is what I am returning as OUT param in my SP.Correct. At the point you open the cursor, oracle has not attempted any 'fetch' against the data so it won't know if there is any data or no data. that only occurs when a fetch is attempted.
Take a read of this:
[PL/SQL 101 : Understanding Ref Cursors|http://forums.oracle.com/forums/thread.jspa?threadID=886365&tstart=0] -
Ref Cursors / throwing data into a Ref Cursor as data is fetched
I was wondering if anyone has executed an SQL statement and as each row is being fetched back from an SQL, doing some data checks and processing to see if the row is valid to return or not, based on the values being fetched in an SQL.
For example, I'm taking an SQL statement and trying to do some tuning. I have an Exists clause in the Where statement that has a nested sub-query with some parameters passed in. I am attempting to move that statement to a function call in a package (which is called in the SELECT statement). As I fetch each row back, I want to check some values that are Selected and if the values are met, then, I want to execute the function to see if the data exists. If it does exist, then, I want the fetched row returned in the Ref Cursor. If the criteria is met and the row doesn't exist in the function call, then, I don't want the fetched row to return.
Right now, the data has to be thrown to REF Cursor because it's being outputted to the Java application as a Result Set.
I've found many statements where you can take a SELECT statement and throw the Results in the Ref Cursor. But, I want to go a step further and before I throw each row in the Ref Cursor, I want to some processing to see if I put the Fetched Row in the Ref Cursor.
If someone has a better idea to accomplish this, I'm all ears. Like I say, I'm doing this method only for the sake of doing some database tuning and I think this will speed things up. Having the EXISTS clause works and it runs fast from an End-user standpoint but, when it processes on the database with the nested subquery, it is slow.
Here's an example of something that might be a problem (Notice the nested subquery). I moved the nested subquery to a function call written on the database package and make the call to the procedure/package in the SELECT statement. As I process each row, I want to check some values prior having the function call execute. If it meet some criteria, then the record is Ok to fetch and display in the Ref Cursor. If it does not meet the criteria and goes through the function and doesn't return data, then, I don't want the Fetched row from the main query to return the data.:
SELECT EMPNO,
FIRST_NAME,
LAST_NAME
FROM EMP E,
DEPT D
WHERE E.DEPTNO = D.DEPTNO
AND EXISTS (SELECT 'X'
FROM MANAGER M
WHERE M.MANAGER_ID = E.MANAGER_ID
AND MANAGER_TYPE IN (SELECT MANAGER_TYPE
FROM MANAGER_LOOKUP ML WHERE ML.MANAGER_TYPE = M.MANAGER_TYPE))
Any help or ideas of other things to try is appreciated. Keep in mind that I am returning this data to the Java application so, throwing the data to a Ref Cursor in the PL/SQL is the ideal method.
ChrisRef cursors are not required nor desirable when writing java database application. Cursors are mentioned only once in the JDBC documentation reference guide, in the section "Memory Leaks and Running Out of Cursors".
In a word cursors are just plain ridiculous, and in fact I never used them in my 15+ years of application development practice:
http://vadimtropashko.wordpress.com/cursors/ -
Is it possible to identify records in ref cursor without actually fetching
CREATE OR REPLACE PROCEDURE test_miles (p_ref_cursor OUT SYS_REFCURSOR)
IS
BEGIN
OPEN p_ref_cursor FOR
select 5168 mem_uid, 16353 bac_uid, '2013-JAN-19' dte,3 no_of_pax,'AnoopM' username,NULL reward_id from dual
union select 4702 mem_uid , 16344 bac_uid, '2013-JAN-29' dte, 2 no_of_pax,'RAZO' username, NULL reward_id from dual;
END;
Hi all,
I have having a Procedure with out parameter as a REF CURSOR.
This ref cursor will be returned to the calling service.
Is there a way in oracle by which we can identify whether the Ref cursor holds data without actually fetching it.
Since if i choose to fetch the data, i will lose one row when i return the ref cursor back to the calling service. Or else is there way i can retrieve the row i lose during fetch.
Other alternative what have been suggested is create and object type ,fetch the ref cursor values in object type. Then i can use the ref cursor to return the data by table casting.
one more solution is
OPEN
FETCH
CLOSE
OPEN (AGAIN)
In reality the select statement will have is huge lines of code therefore want a suggestion whether there is an alternative to the above solution
Please suggest.CREATE OR REPLACE PROCEDURE test_miles (p_ref_cursor OUT SYS_REFCURSOR)
IS
BEGIN
OPEN p_ref_cursor for SELECT * from DUAL;
OPEN p_ref_cursor FOR
select 5168 mem_uid, 16353 bac_uid, '2013-JAN-19' dte,3 no_of_pax,'AnoopM' username,NULL reward_id from dual
union select 4702 mem_uid , 16344 bac_uid, '2013-JAN-29' dte, 2 no_of_pax,'RAZO' username, NULL reward_id from dual;
END;
If the second cursor doesnt fetch any data then an empty dataset will be stored -
I am trying to make a ssis package that get the data calling the store proc with two param one is ID and other is Sys_refcursor. Say Store Proc as ListName(Id int, myCur sys_refcursor), which gets the datas with the conditions inside it.
REATE OR REPLACE PROCEDURE schemaName.LISTNAME (P_ID IN INT, LST_NAME_REFCUR IN OUT SYS_REFCURSOR)
IS
P_NAMESOURCE_ID INT;
BEGIN
SELECT SOURCE_ID INTO P_NAMESOURCE_ID FROM SEARCHING_TABLE ST WHERE ST.ID = P_ID;
IF (P_NAMESOURCE_ID=1)
THEN
OPEN LST_SOURCE_REFCUR FOR
SELECT ST.ID,
ST.TRANSACTION_DATE AS TRAN_DATE,
IF (P_NAMESOURCE_ID=1)
THEN
OPEN LST_SOURCE_REFCUR FOR ....
then i need to get the data from that refcursor and fetch those data to excel sheet to a virtual directory.
Any help would be appreciated. I am new to SSIS. and i need to do this assignment this friday.Hi 11srk,
To fetch data from Oracle store procedure, you can use a Script Component as source to call the Oracle stored procedure by using System.Data.OracleClient OracleDataReader, and get the rows and add them to the pipeline buffer. For more information, please
see:
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/1d0b3a1b-8792-469c-b0d1-f2fbb9e9ff20/dump-oracle-ref-cursor-into-ms-sql-staging-table-using-ssis
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/fcdaa97e-8415-4c3e-8ffd-1ad45b590d57/executing-an-oracle-stored-procedure-from-ssis?forum=sqlintegrationservices
http://msdn.microsoft.com/en-us/library/system.data.oracleclient.oracledatareader(VS.90).aspx
Regards,
Mike Yin
TechNet Community Support -
How to clear the run time error in ref cursor
good morning every one,
the code as follows
create 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;when i am running this code im getting
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 6can you please help me in getting rid of this problem.
thanking you,
prakashd_stmt varchar2(100); Increase the size of d_stmt. Your a assigning a larger string
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 above string is more than 100 characters. -
Data Set with multiple ref cursors
Hi ,
I need to design an integrated report , i created my data set with a oracle procedure which returns "multiple ref cursors" . In this case birt is displaying all output columns together and it is difficult to identify which column belongs to which ref cursor and if there are any columns with same name in both output cursors , it displays only one. Is there any way to handle this ? or how we handle a data set which contains multiple ref cursors in output ??Having to ref cursors return mutiple recordsets in an Oracle package is like haveng two resultsets return from a MS SQL Server sparc.
The link may point you in the right direction.
http://www.codeproject.com/Articles/675933/Returning-Multiple-Result-Sets-from-an-Entity-Fram -
Wanted to fetch data from ref cursor to nested pl/sql table getting an erro
create or replace type "DEPT12" as object(dno number(2),dname varchar2(30),loc varchar2(50));
create or replace type dept_tab as table of "DEPT12"
create or replace type "LOC12" as object(locno number,loc_name varchar2(100))
create or replace type loc_tab as table of "LOC12"
create or replace type dept_loc_rec1 as object (dept_dt dept_tab,eno number,loc_dt loc_tab);
create type dept_loc_tb as table of dept_loc_rec1
create table dept_loc_tb_bk1(dept_dt dept_tab,eno number,loc_dt loc_tab)
NESTED TABLE dept_dt
STORE AS dept_tab12,
NESTED TABLE loc_dt
STORE AS loc_tab12
insert into dept_loc_tb_bk1 values(dept_tab(dept12(3,'ABD','LOC')
,dept12(4,'ABD','LOC')
,dept12(5,'ABD','LOC')),3,loc_tab(loc12(21,'AAB'),
loc12(22,'AAB'),
loc12(23,'AAB')));
when I am trying to fetch data from ref cursor to pl/sql table which i am getting an error ora-06504: pl/sql : Return types of result set variables or query do not match.
I have created a nested table of same as the nested pl/sql object table dept_loc_tb and i have declared the lv_dept_loc_tb of same dept_loc_tb but getting an above error when trying to fetch into that variable.
Please any one who can solve my problem.
declare
type cr is ref cursor;
cr_obj cr;
lv_dept_loc_tb dept_loc_tb;
begin
open cr_obj for select dept_dt,eno,loc_dt from dept_loc_tb_bk1;
fetch cr_obj bulk collect into lv_dept_loc_tb;
close cr_obj;
end;Your query selects 3 separate columns therefore requires 3 collections of corresponding types. You want to treat those 3 columns as an object of DEPT_LOC_REC1 type:
SQL> declare
2 type cr is ref cursor;
3 cr_obj cr;
4
5 lv_dept_loc_tb dept_loc_tb;
6
7 begin
8 open cr_obj for select dept_dt,eno,loc_dt from dept_loc_tb_bk1;
9 fetch cr_obj bulk collect into lv_dept_loc_tb;
10 close cr_obj;
11 end;
12 /
declare
ERROR at line 1:
ORA-06504: PL/SQL: Return types of Result Set variables or query do not match
ORA-06512: at line 9
SQL> declare
2 type cr is ref cursor;
3 cr_obj cr;
4
5 lv_dept_loc_tb dept_loc_tb;
6
7 begin
8 open cr_obj for select DEPT_LOC_REC1(dept_dt,eno,loc_dt) from dept_loc_tb_bk1;
9 fetch cr_obj bulk collect into lv_dept_loc_tb;
10 close cr_obj;
11 end;
12 /
PL/SQL procedure successfully completed.
SQL> SY.
P.S. Discover sys_refcursor. -
Importing function with multiple ref cursors in Stored Procedure of Oracle 12c database Using EF6
Hi Good day!
I can able to import function for stored procedure of oracle db and able to add the complex type and get the output but i tried to import the procedure which having two ref cursors and unable to retrieve the column information. Only able to retrieve the
columns of first ref cursor. Please help me to get the result of two ref cursors which acting as out parameters.Having to ref cursors return mutiple recordsets in an Oracle package is like haveng two resultsets return from a MS SQL Server sparc.
The link may point you in the right direction.
http://www.codeproject.com/Articles/675933/Returning-Multiple-Result-Sets-from-an-Entity-Fram -
Procedure to fetch table records using ref cursor
Hi
i need to fetch all the records in the table using ref cursor.we need to pass table
name and the out paramater should be ref cursor.
CREATE OR REPLACE PROCEDURE gettable(p_table_name IN VARCHAR2,
p_ref_cursor OUT dept_pack.ref_cursor1)
IS
BEGIN
OPEN p_ref_cursor FOR SELECT * FROM p_table_name;
END gettable;
is that a start ? then after this i have to execute this procedure to fetch the data from table. i am getting error that table doesnot exist but my idea was to pass p_table_name as IN parameter.
Thnks in Advancehere is the example
SQL> CREATE OR REPLACE PROCEDURE TEST( t_name IN VARCHAR2
2 , p_cursor OUT SYS_REFCURSOR)
3 IS
4 BEGIN
5 OPEN p_cursor FOR
6 'SELECT * FROM '|| t_name ;
7 END TEST;
8 /
Procedure created.
Elapsed: 00:00:00.02
SQL> var o refcursor;
SQL> var tname varchar2(10);
SQL> execute test('EMP',:o);
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.00
SQL> print :o;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DNO
7369 SMITH CLERK 7902 17-DEC-80 800.2 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10
14 rows selected.
Elapsed: 00:00:00.01
SQL> execute test('DEPT',:o);
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.02
SQL> print :o;
DEPTNO DNAME LOC
90 LOGISTIC
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
Elapsed: 00:00:00.01
Maybe you are looking for
-
Hello, I have a Windows 7 Pc where Lightroom 5 is on installed. When I open a photo using " verkenner" I see a good coloured photo. When I open a photo via Lightroom 5, the photo will be too dark. This gives difficulties during shaping the photograph
-
Hidden file on desktop from QT?
I found a file on my desktop using Grand Perspective. It is 622Mb and has the following path/name: Desktop/.QT-0142-bf812bbb-bffff3a4-00 From what little unix I know, this looks like a hidden file. I cannot actually see it on the desktop. Can I just
-
How to Copy Specific Changes between branches in jdev 10g??
Hi! I'm using jdev 10g with svn, I've already create a branch of a project (we're going to use it in production), but I cant find an option to merge the content of trunk with my branch. (would like to use jdev instead of command line) I found the opt
-
Problems with attached documents in Mail and Docs To Go
Hello everybody. I've found a problem with attached documents in Mail. In fact, if I click on attached documents with .doc (microsoft office word 97-2004) and files in .docx Office Open .xml, the iPad doesn't open them, also if I click in "Open with
-
Image Sort order changes when doing an editing in PS or Portraiture.
LR 5.7 OSX 10.9. Sometimes when doing an edit in PS and/or Portraiture the tiff and the raw file move to the end of the Loupe view. The first 15 images I worked on today stayed in the order they were shot, by file name,with the tiff and raw file nex