Dbadapter returning sqltype REFCURSOR
hi!
im trying to do the next.
from my bpel i use the dbadapter to call the next procedure in the oracle database
procedure getDepartmentEmployees(p_department_id in varchar2, p_dept_emps out ref_cursor)
is
begin
dbms_output.put_line('debug begin getDepartmentEmployees for '||p_department_id);
open p_dept_emps for
select department_id,
department_name,
cursor(select employee_id, last_name, department_id
from employees e
where e.department_id = d.department_id) employees
from departments d
where department_id=60
dbms_output.put_line('debug end getDepartmentEmployees for '||p_department_id);
end getDepartmentEmployees;this returns all the departments and within the departmentrow all the employees for this department.
when i do a jdbc call it will return a resultset in a resultset for me.
so i can easily loop over both resultsets.
when i call this procedure from by bpel by use of the dbadapter i get the next output in the audit trail :
<P_DEPT_EMPS>
- <Row>
<Column name="DEPARTMENT_ID" sqltype="NUMBER">60</Column>
<Column name="DEPARTMENT_NAME" sqltype="VARCHAR2">IT</Column>
<Column name="EMPLOYEES" sqltype="REFCURSOR"/>
</Row>
</P_DEPT_EMPS>Now im wondering....how can get data out of the EMPLOYEES-part of the response.
I cant find any example of how to loop over the refcursor sqltype from within my bpel.
i checked the examples like : Oracle_Home\bpel\samples\tutorials\122.DBAdapter\ResultSetConverter but this isn't what i want..don't want to create extra objecttypes on the database.
i can call a 1level refcusor..this just returns good data in my bpel...but for this 'master/details'-refcursor i need a solution.
Any ideas ?
Hi
Even i am having such an issue. In my case i was thinking of modifying my query is such a way that it returns 2 ref cursors. One of employees. But if your quesion is specific to finding how to extract it out from the object that is got in bpel i am not sure. Please do post the solution if you get it.
Thanks
-Pradip
Similar Messages
-
Issue with IN parameter of Oracle Procedure returning two RefCursors...
Hi all,
I'm having a nightmare with an Oracle procedure that takes one input parameter and returns two RefCursors as outputs. I recently got help in this forum getting a procedure to work that took no inputs but returned two refcursors and that's still working fine. So, for my current issue I have a procedure defined as follows:
PROCEDURE getQueueInfo(domainKey char, importQueues OUT ODPNet.refcur, exportQueues OUT ODPNet.refcur) IS
BEGIN
OPEN importQueues FOR SELECT
source_key, source_applid,
import_status(source_key) as status,
time_added, time_processed
FROM wm_import_source_header
WHERE source_id = domainKey
ORDER BY source_key DESC;
OPEN exportQueues FOR SELECT
h.source_key, d.source_applid,
export_status(h.source_key) as status,
d.source_wire_code, d.destination_wire_code, h.time_added,
h.time_transmitted
FROM wm_export_source_header h, wm_export_source_data d
WHERE h.source_key = d.source_key
and d.source_id = domainKey
ORDER BY h.source_key DESC;
END getQueueInfo;This is defined within a package called ODPNet as with my previous procedure and all works fine (I can execute within Oracle SQL Developer and it returns the expected results). Within my .NET application my code is as follows:
try
using (OracleConnection conn = new OracleConnection(connString))
using (OracleCommand comm = new OracleCommand())
comm.CommandText = "ODPNet.getQueueInfo";
comm.CommandType = CommandType.StoredProcedure;
comm.Connection = conn;
OracleParameter domainKey = new OracleParameter();
OracleParameter importQueues = new OracleParameter();
OracleParameter exportQueues = new OracleParameter();
domainKey.OracleDbType = OracleDbType.Char;
importQueues.OracleDbType = OracleDbType.RefCursor;
exportQueues.OracleDbType = OracleDbType.RefCursor;
domainKey.Value = "UKBD72";
domainKey.Direction = ParameterDirection.Input;
importQueues.Direction = ParameterDirection.Output;
exportQueues.Direction = ParameterDirection.Output;
comm.Parameters.Add(domainKey);
comm.Parameters.Add(importQueues);
comm.Parameters.Add(exportQueues);
conn.Open();
comm.ExecuteNonQuery();
OracleDataReader dr1 = ((OracleRefCursor)importQueues.Value).GetDataReader();
OracleDataReader dr2 = ((OracleRefCursor)exportQueues.Value).GetDataReader();
if (dr1.HasRows)
while (dr1.Read())
result6 += dr1["source_applid"].ToString() + "<br>";
else
result6 += "No Rows";
if (dr2.HasRows)
while (dr2.Read())
result7 += dr2["source_applid"].ToString() + "<br>";
else
result7 += "No Rows";
catch (Exception ex)
result6 = ex.ToString();
}The value I want to submit as the IN parameter of the procedure is "UKBD72". but I'm really not sure how to apply this and then return my two refcursors into separate datareaders (except for the input parameter stuff the code above is exactly what I did with the other procedure that returned two ref cursors and still works fine). When I run this code I get no errors, I just get told that each DataReader has no rows returned, which shouldn't be right.
Any help with this would be hugely appreciated.
Cheers,
SebSorry folks, after staring at this over and over, eventually going to sleep and coming back to it with some fresh eyes I realised I was just being a complete idiot - I was feeding the procedure different data in the .NET app than I was when testing in Oracle SQL Developer. Low and behold once I gave it the right data it worked!
Silly me... -
Call a procedure that returns a refcursor, use it in another proc's sql?
I have a procedure that returns a refcursor; how can I include that refcursor in a sql statement that's in another procedure, or view etc?
This is the kind of foolery I've tried so far (myproc1 returns a ref cursor):
create or replace procedure myproc2
rc ref cursor
AS
rc1 ref cursor;
begin
EXECUTE myproc1(rc1);
open rc for
select rc1.* from rc1;
end myproc2;lecaro wrote:
To reiterate, I was interested in consuming the refcursor output of one proc in another proc. I wanted to take what I regarded as the records returned by the first sproc and manipulate them using SQL in the second sproc.
Since I can't use that approach, what are some hopefully fairly straightforward solutions that might work?Something like:
create or replace
procedure p1(
p_stmt varchar2,
p_refcursor OUT sys_refcursor
is
begin
open p_refcursor for p_stmt;
end;
create or replace
procedure p2(
p_stmt varchar2
is
v_refcursor sys_refcursor;
v_var varchar2(30);
begin
p1(p_stmt,v_refcursor);
loop
fetch v_refcursor into v_var;
exit when v_refcursor%notfound;
dbms_output.put_line(v_var);
end loop;
end;
set serveroutput on
exec p2('select ename from emp where deptno = 20');
SQL> set serveroutput on
SQL> exec p2('select ename from emp where deptno = 20');
SMITH
JONES
SCOTT
ADAMS
FORD
PL/SQL procedure successfully completed.
SQL> SY. -
Call a Stored Procedure that returns a REFCURSOR using ODI Procedure
Hi,
I have a scenario wherein the stored procedure (TEST_PROC1) that returns a REFCURSOR. The second procedure(TEST_PROC2) will use the REFCURSOR as inpuut and insert it to a table.
Now, I need to execute the test procedures (TEST_PROC1 and TEST_PROC2) using the ODI Procedure but I always get error. However, I was able to execute the test procedures using sqlplus. Here is the command I used for sqlplus:
var rc refcursor
exec TEST_PROC1(:rc);
exec TEST_PROC2(:rc);
PL/SQL Stored Procedure:
-- TEST_PROC1 --
create or replace
PROCEDURE TEST_PROC1 (p_cursor IN OUT SYS_REFCURSOR)
AS
BEGIN
OPEN p_cursor FOR
SELECT *
FROM test_table1;
END;
-- TEST_PROC2 --
create or replace
procedure TEST_PROC2( rc in out sys_refcursor ) is
FETCH_LIMIT constant integer := 100;
type TFetchBuffer is table of test_table2%RowType;
buffer TFetchBuffer;
begin
loop
fetch rc bulk collect into buffer limit FETCH_LIMIT;
forall i in 1..buffer.Count
insert into test_table2(
c1, c2
) values(
buffer(i).c1, buffer(i).c2
exit when rc%NotFound;
end loop;
end;
Is there a way to call a PL/SQL Stored Procedure that returns a REFCURSOR using ODI Procedure?
Thanks,
CathyThanks for the reply actdi.
The procedure TEST_PROC1 is just a sample procedure. The requirement is that I need to call a stored procedure that returns a cursor using ODI and fetch the data and insert into a table, which in this case is test_table2.
I was able to execute a simple SQL procedure (without cursor) using ODI procedure. But when i try to execute the SQL procedure with cursor in ODI, I encountered error.
Do you have any idea how to do this? -
Hi ,
I need to write a procedure which return a multiple rows . This proc will be called by a java application . so my proc is like this
create procedure trial(req_cursor out sys_refcursor) as
emp_rec emp%rowtype
begin
open req_cursor for
select * from emp where emp_id = xxx for update;
loop
fetch req_cursor into emp_rec ;
exit when req_cursor%notfound;
update emp_name = YY where emp_i d = emp_rec .emp_id;
end loop;
end;
But from java when
CallableStatement cst = dbConnection.prepareCall("{call trial(?)}");
cst.registerOutParameter(1, OracleTypes.CURSOR);
cst.execute();
while(rst.next()){
System.out.println(rst.getString("emp_name"));
this ccode is throwing ORA-01002: fetch out of sequence
I doubt in the procedure trial , am opening a refursor and loop it to do a update stmt . so the cursor is coming to an end and when i try to loop though cursor in java code it must be throwing . This is my assumptipn . But the code in my applicaion is exactly similar to what i have written above. And my requirement is after creating a refcursor i have to loop through it to change the status of a column . SO how can i get the rows ? Please suggest me a solution .
If i dont loop in procedure then it is returning multiple rows which i can read in java app.
Thanks in advance.user8690565 wrote:
I am looping because before i pass the multiple rows back i want to change the status of a certain column so the same row is not read by any other thread.
With out the above requirement it is staright forward that i can simple return the refcursor but i should update the rows selected and then return , thats the reason i posted this question in this forumYou definitely need to read the link I provided above. Your understanding of ref cursors (and cursors in general) is wrong. -
No values returned by refcursor ....
Hi
1) I have created one procedure which returns refcursor
2) at sql prompt i have created variable of type refcursor
3) then I execute procedure by passing this variable
4) then i tried printing
i.e
SQL> print :jc11
ERROR:
ORA-24338: statement handle not executed
SP2-0625: Error printing variable "jc11"
my query is:-
Is the above error becoz of no records returned by cursor ????
( I have checked the select statement which is used in procedure which is not returning any records.)
Thanks and Regards
JCexample:
SQL> ed
Wrote file afiedt.buf
1 create or replace function myrefc return sys_refcursor is
2 v_rc sys_refcursor;
3 begin
4 OPEN v_rc FOR 'SELECT 1 as tom, 2 as fred from dual';
5 RETURN v_rc;
6* end;
SQL> /
Function created.
SQL> var x refcursor;
SQL> exec :x := myrefc;
PL/SQL procedure successfully completed.
SQL> print x
TOM FRED
1 2
SQL> -
Show refcursor returned by a PL/SQL function ?
Is it possible to show the results returned by a
PL/SQL function that returns a refcursor ?
In sqlplus it goes like this:
SQL> variable a refcursor;
SQL> execute :a := p_front.get_invoice_list;
PL/SQL procedure successfully completed.
SQL> print a;
INVOICE_ID CLIENT_ID INVOICE_D
101 100 01-APR-06
100 100 06-APR-06
If not, this would be on the top of my wishlist...
By the way: you did a good job on this tool!
Regards,
WillemIs it possible to show the results returned by a
PL/SQL function that returns a refcursor ?
In sqlplus it goes like this:
SQL> variable a refcursor;
SQL> execute :a := p_front.get_invoice_list;
PL/SQL procedure successfully completed.
SQL> print a;
INVOICE_ID CLIENT_ID INVOICE_D
101 100 01-APR-06
100 100 06-APR-06
If not, this would be on the top of my wishlist...
By the way: you did a good job on this tool!
Regards,
Willem -
Refcursor not returning rows when called from non SQL*Plus IDE or other
Hi all,
I have a very weird problem.
We have recently performed a minor upgrade to our oracle database and are now using:
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
PL/SQL Release 10.2.0.5.0 - Production
CORE 10.2.0.5.0 Production
TNS for Linux: Version 10.2.0.5.0 - Production
NLSRTL Version 10.2.0.5.0 - Production
5 rows selected.We have a crystal report selecting data from a refcursor returned by a stored procedure.
The stored procedure updates data when called as well as returning the refcursor in question.
Observe the following test scenario executed in SQL*Plus:
SQL> create table testtab (teststr varchar2(100));
Table created.
Elapsed: 00:00:00.00
SQL> insert into testtab values ('X');
1 row created.
Elapsed: 00:00:00.00
SQL> create or replace procedure testtabproc (p_listcur in out sys_refcursor)
2 as
3 begin
4
5 open p_listcur for
6 select *
7 from testtab
8 where teststr = 'X';
9
10
11 update testtab
12 set teststr = 'Y';
13
14 commit;
15
16 end;
17 /
Procedure created.
Elapsed: 00:00:00.00
SQL> declare
2
3 v_list_cur sys_refcursor;
4
5 type t_out_rec is record (teststr varchar2(100) );
6
7
8
9 v_out_rec t_out_rec;
10
11 v_rec_count number := 0;
12 v_count_limit number := 10000;
13
14 begin
15
16 dbms_output.put_line('about to call proc');
17
18 testtabproc(v_list_cur);
19
20 dbms_output.put_line('about to fetch records');
21
22 fetch v_list_cur into v_out_rec;
23 while v_list_cur%found loop
24 v_rec_count := v_rec_count + 1;
25 if v_rec_count <= v_count_limit then
26 dbms_output.put_line(v_out_rec.teststr);
27 end if;
28 fetch v_list_cur into v_out_rec;
29 end loop;
30 dbms_output.put_line('complete. selected '||v_rec_count||' records.');
31
32
33 end;
34 /
about to call proc
about to fetch records
X
complete. selected 1 records.
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.00
SQL> select * from testtab;
TESTSTR
Y
1 row selected.
Elapsed: 00:00:00.00
SQL> as you can see, the cursor returns data and the table is updated.
now, our problem is with crystal and also when I use the same test case via another IDE like TOAD.
No data is returned from the list but the table is still updated.
We suspect that something is happening that is causing the table to be updated before the refcursor is opened, or at least before the predicates are applied.
has anyone else encountered this problem before?Tubby wrote:
WhiteHat wrote:
nope - it works from sqlplus itermitantly (i.e. we always get the debug output but the cursor only sometimes fetches the rows).
it is almost as if the commit is being executed before the cursor is opened.
I still havn't been able to reproduce it except with the actual scenario that I am working with...Is the code you are dealing with exactly the same as the skeleton you've posted in your original post? Do you perhaps have a generic exception catcher in there somewhere (perhaps catching and hiding an ORA-01555) when the cursor is being fetched?
Not that i expect it to make any difference, but i'm curious as to why you've declared your cursor as IN / OUT ?
p_listcur in out sys_refcursor
the code structure in the real example is almost identical to that test case I produced - the exception handler is only catering for no_data_found, all other errors should be raised as normal.
edit: sorry I forgot to add - it's in/out because apparently that's what crystal reports needs in order to use the refcursor..... I'm not a crystal guy so I can't be any more specific than that sorry......
Edited by: WhiteHat on Oct 11, 2010 9:34 AM -
Calling a storedprocedure returning refcursor of xmltype
Hi,
I'm having issues with stored procedure, returning a refcursor of xmltypes. Most of the examples in the docs(http://docs.oracle.com/html/E10927_01/featXML.htm#i1012109) are always a direct query and I have yet to see one using a stored procedure.
Here's a repro script:
Register an xsd:
BEGIN
dbms_xmlschema.registerschema('http://www.testing.com/person.xsd',
'<?xml version = "1.0" encoding = "utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="first_name" type="xs:string"/>
<xs:element name="last_name" type="xs:string"/>
<xs:element name="gender">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="male"/>
<xs:enumeration value="female"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>',
LOCAL => FALSE, -- local
GENTYPES => FALSE, -- generate object types
GENBEAN => FALSE, -- no java beans
GENTABLES => TRUE, -- generate object tables
FORCE => FALSE,
options => dbms_xmlschema.register_binaryxml,
OWNER => USER );
END;
--create a array of int type
CREATE OR REPLACE
type int_array_type as table of number;
-- Create the table
CREATE TABLE person
ID NUMBER,
xml_document XMLTYPE
xmltype column xml_document STORE AS BINARY XML XMLSCHEMA "http://www.testing.com/person.xsd" element "person";
-- insert some data
INSERT INTO person (ID, xml_document)
VALUES (1, XMLTYPE ('<?xml version="1.0" encoding="utf-8"?>
<person xsi:noNamespaceSchemaLocation="http://www.testing.com/person.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<first_name>John</first_name>
<last_name>Doe</last_name>
<gender>male</gender>
</person>'));
INSERT INTO person (ID, xml_document)
VALUES (2, XMLTYPE ('<?xml version="1.0" encoding="utf-8"?>
<person xsi:noNamespaceSchemaLocation="http://www.testing.com/person.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<first_name>Jane</first_name>
<last_name>Doe</last_name>
<gender>female</gender>
</person>'));
Create the Package
create or replace
package test_pkg as
TYPE refcursor IS REF CURSOR;
type t_id_array is table of number index by binary_integer;
-- user procs
procedure udp_get_personlist (
p_ids IN t_id_array,
p_resultset out refcursor );
end test_pkg;
create or replace
package body test_pkg as
procedure udp_get_personlist (
p_ids IN t_id_array,
p_resultset out refcursor ) IS
v_int_array_type int_array_type := int_array_type();
begin
FOR i IN 1..p_ids.COUNT LOOP
v_int_array_type.extend(1);
v_int_array_type(i) := p_ids(i);
END LOOP;
OPEN p_resultset FOR
SELECT E.XML_DOCUMENT AS "person" FROM person E
WHERE e.ID IN ( SELECT t.COLUMN_VALUE FROM TABLE ( v_int_array_type ) t );
end udp_get_personlist;
end test_pkg;And here is my ODP.NET code
using (var con = new OracleConnection("<your oracle connection>"))
using (var cmd = con.CreateCommand())
cmd.CommandText = "test_pkg.udp_get_personlist";
cmd.CommandType = CommandType.StoredProcedure;
int[] ids = new int[] { 1, 2 };
OracleParameter param1 = cmd.Parameters.Add("p_ids", OracleDbType.Int32);
OracleParameter param2 = cmd.Parameters.Add("p_resultset", OracleDbType.RefCursor, ParameterDirection.Output);
param1.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
param1.Value = ids;
param1.Size = ids.Length;
param1.ArrayBindSize = new int[] { 4, 4 };
// Setup the ArrayBind Status for param2
param1.ArrayBindStatus = new OracleParameterStatus[1] { OracleParameterStatus.Success }; //, OracleParameterStatus.Success };
try
cmd.XmlQueryProperties.MaxRows = 1;
con.Open();
XmlReader r = cmd.ExecuteXmlReader(); // this always generates invalidoperationexception
// do something with the result
catch (Exception)
throw;
// Close and Dispose OracleConnection object
con.Close();
con.Dispose();
} Server/Tools information:
Oracle is Standard - Oracle Database 11g Release 11.2.0.1.0 running on Windows Server 2003 Std
ODP.NET (ie Oracle.DataAccess.DLL is 4.112.3.0);
Visual Studio 2010 Ultimate SP1
Any pointers in what I'm (obviously doing wrong) is greatly appreciated...
thanks
Edited by: 947266 on Sep 10, 2012 9:46 AMWas able to make it work
using (var con = new OracleConnection("<your oracle connection>"))
using (var cmd = con.CreateCommand())
cmd.CommandText = "test_pkg.udp_get_personlist";
cmd.CommandType = CommandType.StoredProcedure;
int[] ids = new int[] { 1, 2 };
OracleParameter param1 = cmd.Parameters.Add("p_ids", OracleDbType.Int32);
OracleParameter param2 = cmd.Parameters.Add("p_resultset", OracleDbType.RefCursor, ParameterDirection.Output);
param1.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
param1.Value = ids;
param1.Size = ids.Length;
param1.ArrayBindSize = new int[] { 4, 4 };
// Setup the ArrayBind Status for param2
param1.ArrayBindStatus = new OracleParameterStatus[1] { OracleParameterStatus.Success }; //, OracleParameterStatus.Success };
try
cmd.XmlQueryProperties.MaxRows = 1;
con.Open();
int i = cmd.ExecuteNonQuery();
OracleRefCursor curs = (OracleRefCursor)cmd.Parameters["p_resultset"].Value;
OracleDataReader dr = curs.GetDataReader();
while (dr.Read())
Console.WriteLine(dr[0].ToString());
catch (Exception)
throw;
// Close and Dispose OracleConnection object
con.Close();
con.Dispose();
} -
How to use RefCursor to return millions of records
I have a stored Procedure which returns a RefCursor. Following is the query which is used to open the RefCursor. this query gets executed in 7 seconds and it returns 13,00,000 records. It takes hours to show them in the dotnet application.
SELECT
CO.COMPANY_ID AS COMPANY_ID,
PCH.HOLDING_ID AS HOLDING_ID,
CO.NAME AS FIRM_NAME,
PCC.NAME AS "Sub-Account Name",
PCC.PORTFOLIO_CLASS_NAME AS "Sub-Account Type",
H.COUPON_RATE AS COUPON_RATE,
NVL(TO_CHAR(H.COUPON_RATE),F_GETCODE(H.COUPON_STRUCTURE_ID,'CPN')) AS COUPON_FIELD,
TO_CHAR(H.MATURITY_DATE,'DD-MON-YYYY') AS MATURITY_DATE,
CO.ALPHA_NAME AS ALPHA_NAME,
H.ISSUER_NAME AS ISSUER_NAME,
H.ISSUER_ALPHA_NAME AS ISSUER_ALPHA_NAME,
PCH.FI_PAR_AMOUNT AS "Currency Par (000s)",
PCH.FI_NET_CHANGE AS "Net Change (000s)",
PCH.FI_BONDS_HELD AS "# of Bonds Held",
TO_CHAR(CO.REPORT_DATE,'DD-MON-YYYY') AS REPORT_DATE,
H.NAME AS ISSUEDESC,
H.ISSUER_COUNTRY_NAME AS ISSUER_COUNTRY_NAME,
F_GETCODE(H.ISSUER_STATE_ID,'S') AS ISSUER_STATE_NAME,
TO_CHAR(H.ISSUE_DATE,'DD-MON-YYYY') AS ISSUE_DATE,
H.LEAD_MANAGER AS LEAD_MANAGER,
H.CURRENCY_CODE AS CURRENCY_CODE,
PCH.MARKET_SECTOR_CODE AS MARKET_SECTOR_CODE,
H.CUSIP AS CUSIP,
H.ISIN AS ISIN,
H.ISSUER_TICKER_SYMBOL_TEXT AS "Primary Exchange Equity Ticker",
H.PLEDGE_NAME AS "Instrument/Pledge",
H.COLLATERAL_NAME AS "Collateral/Purpose",
H.ISSUER_CREDIT_SECTOR_NAME AS "Issuer Credit Sector",
H.COUPON_STRUCTURE_NAME AS "Coupon Structure",
H.SP_RATING_NAME AS "SP Rating",
H.MOODYS_RATING_NAME AS "Moodys Rating",
H.FITCH_RATING_NAME AS "Fitch Rating" ,
P.HONORIFIC_PREFIX_CODE AS HONORIFIC,
P.FIRST_NAME AS FIRST_NAME,
P.MIDDLE_INITIAL AS MIDDLE_INITIAL,
P.LAST_NAME AS LAST_NAME,
P.DISPLAY_FUNCTION_NAME AS Title,
P.DIRECT_DIAL_PHONE AS "DIRECT DIAL PHONE",
D.PHONE_CODE AS "Country Phone Code",
P.EMAIL_ID AS "Email Address",
CO.MAIL_ADDRESS_LINE1 AS MAIL_ADDRESS_LINE1,
CO.MAIL_ADDRESS_LINE2 AS MAIL_ADDRESS_LINE2,
CO.MAIL_CITY_NAME AS MAIL_CITY_NAME,
CO.MAIL_STATE_CODE AS MAIL_STATE_NAME,
CO.MAIL_ZIP_CODE as "Firm Postal Code",
CO.LOC_ADDRESS_LINE1 AS LOC_ADDRESS_LINE1,
CO.LOC_ADDRESS_LINE2 AS LOC_ADDRESS_LINE2,
CO.LOC_CITY_NAME AS LOC_CITY_NAME,
CO.LOC_STATE_CODE AS LOC_STATE_NAME,
CO.LOC_ZIP_CODE,
CO.LOC_COUNTRY_NAME AS LOC_COUNTRY_NAME,
C.PHONE_CODE AS "Firm Country Phone Code",
CO.PHONE_NUMBER AS PHONE,
CO.FAX_NUMBER AS FAXNO,
/* COUNT(PCH.COMPANY_ID) OVER (PARTITION BY PCH.COMPANY_ID ORDER BY PCH.COMPANY_ID) AS ROW_CNT,
COUNT(DISTINCT CO.COMPANY_ID) OVER() AS FIRMCOUNT,
COUNT(DISTINCT CO.COMPANY_ID) OVER() AS TOTAL_RECORDS,
COUNT(DISTINCT PCC.PORTFOLIO_COMPANY_CUSTOMER_ID) OVER(PARTITION BY CO.COMPANY_ID) AS FUNDCOUNT,
COUNT(DISTINCT PCC.PORTFOLIO_COMPANY_CUSTOMER_ID) OVER() AS FUNDPORTFOLIOCOUNT,
COUNT(DISTINCT H.HOLDING_ID) OVER(PARTITION BY CO.COMPANY_ID,PCC.PORTFOLIO_COMPANY_CUSTOMER_ID) AS ISSUECOUNT,
PCC.PRIVATE_PORTFOLIO_FLAG,
PCC.TOP_TEN_HOLDINGS_FLAG ,
TO_CHAR(SYSDATE,'DD/MM/YYYY HH:MM:SS') TI
FROM
PORTFOLIO_COMPANY_HOLDING PCH,
HOLDING H,
COMPANY CO,
PORTFOLIO_COMPANY_CUSTOMER PCC,
PERSON P ,
PERSON_PORTFOLIO PP,
COUNTRY C,
COUNTRY D
WHERE
PCH.HOLDING_ID=H.HOLDING_ID
AND PCH.COMPANY_ID=CO.COMPANY_ID
AND PCH.PORTFOLIO_COMPANY_CUSTOMER_ID=PCC.PORTFOLIO_COMPANY_CUSTOMER_ID
AND P.EMPLOYEE_ID = PP.EMPLOYEE_ID
AND CO.COMPANY_ID=PP.COMPANY_ID
AND CO.COMPANY_ID=PCC.COMPANY_ID
AND PCC.PORTFOLIO_COMPANY_CUSTOMER_ID = PP.PORTFOLIO_COMPANY_CUSTOMER_ID
AND C.COUNTRY_ID = CO.LOC_COUNTRY_ID
AND D.COUNTRY_ID= P.COMPANY_LOC_COUNTRY_ID
AND P.DISPLAY_COMPANY_CONTACT_FLAG = 'Y'
AND PCH.HOLDING_ID IN ( SELECT HOLDING.HOLDING_ID FROM MV_BOND HOLDING WHERE HOLDING.LANGUAGE_ID=2 AND INSTR(PATTNO_STRING,',96,')>0
-- AND (((HOLDING.MARKET_SECTOR_ID) IN (8209) )
AND (((HOLDING.CURRENCY_ID) IN (10000003) )
)i ran the query in TOAD it got executed in 7 seconds. but when i used the same query in stored procedure it was taking lot of time to complete pushing the data to the application. Need your help to tune the query.
-
How to call a procedure with refcursor from another plsql unit
example I created a pkg with the a procedure that returns a REFCURSOR.
Now I need to call this procedure from another pkg and use the refcursor values in other pkg.
Help please.......
PROCEDURE CustomerSite_Get (p_Registry IN VARCHAR2,
p_CustomerNumber IN VARCHAR2, p_Cursor IN OUT t_cursor);
PROCEDURE CustomerSite_Get (p_Registry IN VARCHAR2,
p_CustomerNumber IN VARCHAR2, p_Cursor IN OUT t_cursor)
IS
-- 0903: Include BillToName
BEGIN
OPEN p_Cursor FOR
SELECT S.LOCATION CustomerSite, S.SITE_USE_ID CustomerSiteID, C.CUSTOMER_NAME BillToName
FROM RA_CUSTOMERS C,
RA_ADDRESSES A,
RA_SITE_USES S,
UWA_REGISTRY R,
UWA_REGISTRY_BILL_TO B
WHERE C.CUSTOMER_ID = A.CUSTOMER_ID
AND A.ADDRESS_ID = S.ADDRESS_ID
AND S.SITE_USE_ID = B.SITE_USE_ID
AND R.REGISTRY_ID = B.REGISTRY_ID
AND B.TRIP_BILLING != 'N'
AND R.DELETE_FLAG != 'Y'
AND R.Registry = p_Registry
AND R.CUSTOMER_NUM = p_CustomerNumber
ORDER BY S.LOCATION;
END CustomerSite_Get;
thanks,
Anitha.
Edited by: user521218 on May 6, 2009 1:24 PMHi Anitha,
try this,
-- PKG_A
Procedure CustomerSite_Get( p_Registry IN Varchar2
, p_CustomerNumber IN Varchar2
, p_Cursor IN OUT t_cursor) Is
Begin
PKG_B.CustomerSite_Get( p_Registry
, p_CustomerNumber
, p_Cursor );
End;
-- PKG_B
Procedure CustomerSite_Get(p_Registry IN Varchar2
,p_CustomerNumber IN Varchar2
,p_Cursor IN OUT t_cursor) Is
Begin
Open p_Cursor For
SELECT S.LOCATION CustomerSite
,S.SITE_USE_ID CustomerSiteID
,C.CUSTOMER_NAME BillToName
FROM RA_CUSTOMERS C
,RA_ADDRESSES A
,RA_SITE_USES S
,UWA_REGISTRY R
,UWA_REGISTRY_BILL_TO B
WHERE C.CUSTOMER_ID = A.CUSTOMER_ID
AND A.ADDRESS_ID = S.ADDRESS_ID
AND S.SITE_USE_ID = B.SITE_USE_ID
AND R.REGISTRY_ID = B.REGISTRY_ID
AND B.TRIP_BILLING != 'N'
AND R.DELETE_FLAG != 'Y'
AND R.Registry = p_Registry
AND R.CUSTOMER_NUM = p_CustomerNumber
Order BY S.LOCATION;
End CustomerSite_Get;regards,
Christian Balz -
Using Refcursor in Callable Statement without using the Oracle Drivers
Hello all,
Is there anyway to have a stored procedure (Oracle 8i) return a refcursor to my CallableStatement without using the Oracle Thin drivers (i'm now using jdbcodbc). I've tried registering my out parameter with every possible type i can think of...REF, JAVA_OBJECT, OTHER, etc. but with no luck.
Help!!!!Certainly...I connect to the database using the
jdbcodbc driver and when i execute any of the code, i
get the following error:
java.sql.SQLException: [Oracle][ODBC][Ora]ORA-06550:
line 1, column 7:
PLS-00306: wrong number or types of arguments in call
to 'PVISUAL_GET'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
It's bombing on the line that i attempt to register
OracleTypes.CURSOR. It works fine when i use the
oracle thin drivers, but i want to get this puppy
working with the JdbcOdbcDriver. Here's the code:
CallableStatement dbCall =
nt dbCall =
(CallableStatement)connection.prepareCall("{ call
PAK_VISUAL_GET.pvisual_get(?, ?, ?, ?, ?, ?) }");
dbCall.setString(1, sessionKey);
dbCall.setInt(2,
l.setInt(2, Integer.parseInt(storedVizID));
dbCall.registerOutParameter(3,
arameter(3, OracleTypes.CURSOR);
dbCall.registerOutParameter(4,
arameter(4, OracleTypes.NUMBER);
dbCall.registerOutParameter(5,
arameter(5, OracleTypes.VARCHAR);
dbCall.registerOutParameter(6,
arameter(6, OracleTypes.NUMBER);
dbCall.execute();when you don't use oracle thin driver, you cannot use the OracleTypes. but, instead use the java.sql.Types values.Replace dbCall.registerOutParameter(3, OracleTypes.CURSOR); with
dbCall.registerOutParameter(3,java.sql.Types.OTHER). things should be fine.
Ganesh -
Dynamic Column Names using Refcursors
Hi,
I have a stored procedure which returns a refcursor. The refcursor contains a SQL query in which the column names and number of columns vary dynamically based on the date parameters passed.
"My objective is to return certain XYZ details of employees for a certain month range."
For ex: For the month of Aug-2011, the column names would be '1-AUG-11' to '31-AUG-11 and for Feb-2011 '1-FEB-11' to '28-FEB-11'
My issue is, when I execute the refcursor query using "EXEC", my column names/headings are preserved.
FIELD NAMES: EMPLOYEE_CODE XYZ_TYPE *1-AUG-11* *2-AUG-11* ... *31-AUG-11*
DATA: EMPCODE_Z TYPE1 VALUE_1 VALUE_1 ... VALUE_31
Whereas when I fetch the refcursor into a collection of nested table and display, my column names are lost.
DATA: EMPCODE_Z TYPE1 VALUE_1 VALUE_1 ... VALUE_31
Is there a way where I can preserve the column names from the refcursor after fetching into pl/sql collections?
Any help would be highly appreciated.
Thank you.
Edited by: 867622 on Nov 11, 2011 4:38 PM867622 wrote:
If not dynamic SQL, how can the number of columns be altered based on the input parameters?Cannot. A dynamic SQL projection means dynamic SQL (there's an exception to this, and despite interesting is not relevant to 99.99% of problems dealing with dynamic SQL projections).
You can however still use a dynamic projection and wrap that into a user defined type interface.
Here's the basic approach:
// create a user define type that will provide the wrapper for the SQL projection
create or replace type TString as table of varchar2(4000);
// build dynamic SQL projections via this type, e.g.
select
TStrings( object_id, object_name, created )
from user_objects
select
TStrings( emp_id, dept_id, salary, commission )
from employeesDespite the SQL cursors being different and the columns and number of columns being selected different, the SQL projection of both are the same. The Count method tells you the number of columns in the projection. Referencing an applicable column is simply done by using the column's sequential number in the projection.
You also do not have to use a collection or varchar2 as the wrapper type - you can create complex user objects and use the collection type for that, as the SQL projection.
Another alternative is converting the ref cursor into a DBMS_SQL cursor and using the latter's describe interface to dynamically determine the structure of the SQL projection and fetching the column values from it. But 11gr1 or later is needed for doing this. -
Test a procedure which returns a sys_refcursor
Hi all,
Oracle 9i
Got a simple stand alone procedure which has an input param and an output param, the second of which
is a ref cursor.
Can anyone tell me how I can go about testing this from within Pl/SQL (Command line)?
CREATE OR REPLACE PROCEDURE "LOGMNR"."LM"
(p_filename in varchar2, p_recordset OUT SYS_REFCURSOR)
as
begin
begin
dbms_output.put_line('Hello World');
OPEN p_recordset FOR
SELECT *
FROM test_table;
end;
end LM;
Also, and I know this is a huge long-shot. I'm going to be calling this procedure from VB6 (yes I know!), via ADODB, but I'm not
sure what type to add for the second parameter. Anyone called an Oracle procedure with ADODB which returns a refcursor/result set?
cmd.Parameters.Append cmd.CreateParameter("p_filename", adVarChar, adParamInput, 255, "c:\test.dat")
cmd.Parameters.Append cmd.CreateParameter("p_recordset", *???*, adParamOutput, 6000, "")
Regards
DaveWhy don't you just use sqlplus as already suggested
Re: Test a procedure which returns a sys_refcursor
SQL> var c refcursor
SQL> begin
2 open :c for
3 select * from
4 (
5 select * from all_tab_comments
6 where owner = 'SYS'
7 order by (length(comments)) desc nulls last
8 )
9 where rownum <= 3;
10 end;
11 /
PL/SQL procedure successfully completed.
SQL> print c
OWNER TABLE_NAME TABLE_TYPE COMMENTS
SYS USER_AUDIT_OBJECT VIEW Audit trail records for statements concerning objects, specificall
y: table, cluster, view, index, sequence, [public] database link, [public] synonym, procedure, trigger, rollback segment, tablespace, role,
user
SYS ALL_JAVA_DERIVATIONS VIEW this view maps java source objects and their derived java class ob
jects and java resource objects for the java class accessible to user
SYS USER_JAVA_DERIVATIONS VIEW this view maps java source objects and their derived java class ob
jects and java resource objects for the java class owned by user
SQL>* Interesting how two out of three of the wordiest comments relate to java. -
Redirect the refcursor output of an SP to a table ?
hi.
i have an SP which returns a refcursor. now what i need is to get this output to a table so that i can manupulate the data.
this is how i executed the table
var a refcursor
exec packagename.spname(:a,'inputchar');
print :a;
please help.
i tried create table temp as select * from :a
and
create table temp as select * from table (cast a as a)
but both didnt work..
what am i missing here ????novicedba wrote:
the SP is not mine. so i cannot alter it.So? That does not make something less wrong.
suppose the refursor returns itemcode, purchase_time, price. and details of 100+ items are returning in thi refcursor. what i need is first to get the results. and then filter it only to view detaild of one item. Why? That cursor does work (in the SQL engine) to find the relevant rows (using indexes and/or tables reading data blocks). It does +"x"+ amount of work to output the results for that SQL select statement.
Now you want to filter, in PL/SQL or another client language, the output of that cursor. That filtering should be done by the SQL engine - as it is best suited for doing that work. And the workload of +"x"+ that was needed, can now be +"x/2"+ as a result - as the filtering and elimination of columns not needed from the SQL projection can significantly decrease the workload and increase performance.
So what benefits are there to filter the output of a cursor? NONE! There are no benefits. Not a single one.
this is why i need to get the Output into a table.The cursor returns data from the SQL engine. This data needs to be pushed from the SGA db buffer cache all the way to the client language. In the case of PL/SQL, into the private heap space of the process (called the PGA).
Then you take that very same data, create an insert SQL cursor, and send that data back to the SQL engine to be inserted.
So what benefits are there pushing and pulling SQL data like this across memory and process and even platform boundaries, when the both the read data and write data processes could have been done as a SQL "+insert .. select+" cursor? NONE! There are no benefits. Not a single one.
(no wonder this sounds like TSQL coz i am more familiar to TSQL than PL ;) (irrelevant stuff) )Treating PL/SQL like TSQL 'cause your are "familiar" with TSQL is, bluntly put, idiotic. PL/SQL is not TSQL. Oracle is not MS-SQL Server.
if i am going for a cast.. what should i do ?I would go instead for the manuals.. and educate myself on the concepts and fundamentals of the product and languages I'm using. And design and write robust and performant and flexible and scalable code.
Maybe you are looking for
-
All the sudden my iPod shuffle no longer shows up in my devices on my computer nor does iTunes show it? Why would this happen? How can i fix this? Anyone know?
-
How to retrieve the Conversation ID in ABAP
Does anyone know how to retrieve a conversation ID in ABAP? You can retrieve the reference ID from SXMSPMAST but how do you retrieve the conversation ID? Table names? FM? ABAP not Java or UDF All suggestions welcome. Regards, Nay
-
Problem in displaying portal login page
Hi I made 3 diffirent installation and I still have the same problem : 1. AS 10g R2 on windows 2003 SP1 2. AS 10g R2 on Windows XP SP2 3. AS 10g (9.0.4) on Windows XP SP2 All of the services of infrastructure and Middle tier are working properly , no
-
Basic interview questions in abap ddic
can any one pls give me the link for basic ddic interview questions
-
Web Dynpro Model Generation for Application Services
Hi Experts, I'm currently experimenting with the new functionality provided by CE, but there is one thing that I can't seem to figure out. How does the new Web Dynpro model generation work with regards to CAF Application Services? I'm trying to call