Oracle Function returns a Ref Cursor to a ResultSet object - Performance
My program calls an Oracle PL/SQL function which returns a ref cursor to a ResultSet object. I know that the function runs to completion relatively quickly when i run it in an anonymous block but when the call is made through my Java application the resultset takes about 30 mins to return. Below is a snippet of my code:
currentConnection = ConnectionManager.getInstance().getConnection();
reportStmt = currentConnection.prepareCall("BEGIN ? := ENVISION.PKG_WMS_TO_AP.F_REPORT_CI_SC_HOLDING(?,?); END;"); reportStmt.registerOutParameter(1, OracleTypes.CURSOR);
reportStmt.setString(2, invoice.getCrewHQ());
reportStmt.setDate(3, invoice.getWrCompletionDate());
reportStmt.execute();
reportRS = ((OracleCallableStatement) reportStmt).getCursor(1);
Through a debugger I see that the second last statement (reportStmt.execute()) runs quickly. It is only when I step into the last statement that the debugger takes up to 30 minutes.
Any thoughts?
Flynn,
The Internet is a dynamic place. After nearly two and a half years, there is a chance that a link will change. This is the new URL for the relevant Web page:
http://asktom.oracle.com/~tkyte/ResultSets/
Good Luck,
Avi.
Similar Messages
-
Function call returned in ref cursor
We have a ref cursor that calls a function in a package. When ODP.NET reads the cursor, it can't see what the function is returning. OO4O works fine, and if I take the sql that populates the ref cursor and put it into a temporary table, then select from that temporary table to return the ref cursor to ODP, it works fine. Anyone else seen this issue? Any help would be appreciated. Thanks.
Eric Schrauth
[email protected]Did you set the parameter direction to be ParameterDirection.Input when you created the parameter? Post your code.
-
Creating a function having a ref cursor returned
I get an error message for the following code below. I am trying to create a function that allows the users to pass in a certain parameter which is used to invoke a specific query for the paramented passed in. Once the query is invoked, it should return a ref cursor. Please help. I am still using pl/Sql developer.
create or replace package TEST2 is
type rec_DropDownList_Item is RECORD(
TEXT_TYPE VARCHAR2(200),
xsVALUE VARCHAR2(200));
TYPE cur_DropDownList IS REF CURSOR RETURN rec_DropDownList_Item;
FUNCTION Getprocedure_yearreportdisplay (need_type in VARCHAR2) RETURN cur_DropDownList;
end TEST2;
create or replace package body TEST2 is
FUNCTION Getprocedure_yearreportdisplay (need_type in VARCHAR2)
RETURN cur_DropDownList IS
my_ref_cursor cur_DropDownList;
BEGIN
OPEN my_ref_cursor FOR
SELECT vehicletype, vehicledescription
FROM cars where vehicletype = need_type;
return my_ref_cursor;
END Getprocedure_yearreportdisplay;
end TEST2;user13046875 wrote:
a simple example might help because I am having a difficult understanding the reply. Thank you.
create or replace package TEST2 is
type rec_DropDownList_Item is RECORD(
TEXT_TYPE VARCHAR2(200),
xsVALUE VARCHAR2(200));
TYPE cur_DropDownList IS REF CURSOR RETURN rec_DropDownList_Item;
FUNCTION Getprocedure_yearreportdisplay (need_type in VARCHAR2) RETURN cur_DropDownList;
end TEST2;
create or replace package body TEST2 is
FUNCTION Getprocedure_yearreportdisplay (need_type in VARCHAR2)
RETURN cur_DropDownList IS
my_ref_cursor cur_DropDownList;
BEGIN
OPEN my_ref_cursor FOR
SELECT 'column1', 'column2'
FROM dual;
return my_ref_cursor;
END Getprocedure_yearreportdisplay;
end TEST2;
TUBBY_TUBBZ?variable x refcursor;
TUBBY_TUBBZ?
TUBBY_TUBBZ?exec :x := TEST2.Getprocedure_yearreportdisplay('dummy');
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.01
TUBBY_TUBBZ?print :x
'COLUMN 'COLUMN
column1 column2
1 row selected.
Elapsed: 00:00:00.03
TUBBY_TUBBZ?Is an example of running in SQLPLUS (you may want to get your own copy, it's free and available on OTN). -
Plsql use a function which returns a ref cursor
Hi
I've been using an function which returns a ref cursor. I've been returning this into a java resultset. Fine!
Now i'm in plsql and want to use the same function. I'm not sure how to get this resultset in plsql.It's not very practical to use a refcursor like you want to, but here you go
create or replace function test_ref
return sys_refcursor
is
v_rc sys_refcursor;
begin
open v_rc for select emp_name from emp ;
return v_rc;
end;
declare
v_rc sys_refcursor;
v_emp_name emp.emp_name%type;
begin
v_rc := test_ref ;
loop
fetch v_rc into v_emp_name ;
exit when v_rc%notfound ;
dbms_output.put_line('Employee Name: '||v_emp_name );
end loop;
end; -
Toplink JPA Calling Oracle Function Return sys_refcursor
I have a function which return sys_refcursor and I am trying to call this using JPA(1.0)
@NamedNativeQuery( name = "getEmpsByDeptId"
, query = "{ ? = call my_pck.getEmployees(:longName)}"
, resultClass = Employee.class
, hints = { @QueryHint(name = "org.hibernate.callable", value = "true")
, @QueryHint(name = "org.hibernate.readOnly", value = "true")
DAOImpl
query = getEntityManager().createNamedQuery("getEmpsByDeptId");
query.setParameter("longName", "SCOTT");
list = (List<Employee>)query.getResultList();
However when I execute, I am getting the following exception
Exception [TOPLINK-6132] (Oracle TopLink Essentials - 2.1 (Build b52-fcs (09/24/2008))):
oracle.toplink.essentials.exceptions.QueryException Exception Description:
Query argument 2 not found in list of parameters provided during query execution.
Query: ReadAllQuery(test.entity.Employee) at oracle.toplink.essentials.exceptions.QueryException.namedArgumentNotFoundInQueryParameters
I have tried using
call my_pck.getEmployees(?)}"
and
query.setParameter(1, "SCOTT");
However error remains the same and how can I resolve this issue?
I have used the same function with Hibernate using JPA2.0 and it has worked.
Thanklecaro wrote:
OK. But obviously there is some oracle object that one can call via an Access pass-through query which returns rows?Just to clarify. You could fetch data in Access from an Oracle function that returns a ref cursor using VBA editor. To use a pass-through query Oracle function should be a table function or pipelined table function:
CREATE OR REPLACE
TYPE testvalues_obj_type
AS OBJECT(
val varchar2(10),
isnum number
CREATE OR REPLACE
TYPE testvalues_tbl_type
AS TABLE OF testvalues_obj_type
CREATE OR REPLACE
FUNCTION fn_testvalues
RETURN testvalues_tbl_type
PIPELINED
IS
CURSOR testvalues_cur
IS
SELECT testvalues_obj_type(MyValue,fn_isnum(MyValue)) testvalues_obj
FROM t_values;
BEGIN
FOR v_rec IN testvalues_cur LOOP
PIPE ROW(v_rec.testvalues_obj);
END LOOP;
RETURN;
END;
/To test it in Oracle:
SELECT *
FROM TABLE(fn_testvalues)
VAL ISNUM
Merced 0
Pixie 0
452 1
SQL> Now in Access pass-trough query window enter:
SELECT *
FROM TABLE(fn_testvalues);SY. -
How to return a ref cursor from this dbms_sql?
Hi,
Can anyone show me how to return a ref cursor from this dbms_sql based procedure? I see 11g has a dbms_sql.to_refcursor(cursor_handle). How can this be done is 10g?
Thx.
CREATE OR REPLACE PROCEDURE Sample_Get_t
p_sample_id sample.sample_id%TYPE,
p_contract_id sample.contr_id%TYPE
IS
cursor_handle INT;
sql_stmnt varchar2(500);
rows_processed NUMBER;
BEGIN
sql_stmnt :=
'SELECT
sample_id,
contr_id,
rcpt_id
FROM
sample s
WHERE
s.contr_id = :1
and s.sample_id = :2
ORDER BY
sample_id';
cursor_handle := dbms_sql.open_cursor;
dbms_sql.parse(cursor_handle, sql_stmnt, dbms_sql.native);
dbms_sql.bind_variable(cursor_handle, ':1', p_contract_id);
dbms_sql.bind_variable(cursor_handle, ':2', p_sample_id);
rows_processed := dbms_sql.execute(cursor_handle);
dbms_sql.close_cursor(cursor_handle);
END Sample_Get_t;In 10 this cannot be done with dbms_sql (to my knowledge). There are a couple of other options.
1) open the ref cursor for the dynamic statement using bind variables (or SYS_CONTEXT variables, which i prefer since they are much easier to deal with when you are dynamically adding predicates).
declare
wRefCursor SYS_REFCURSOR;
begin
open wRefCursor for 'select * from all_objects where owner = :Logged_in_user' using user;
end;
/or using the context (the context will bind for you)
declare
wRefCursor SYS_REFCURSOR;
begin
open wRefCursor for 'select * from all_objects where owner = SYS_CONTEXT(''CONTEXT_NAME'', ''VARIABLE_NAME'') ';
end;
/Be aware that contexts ALWAYS return varchar values, so if you are comparing to a number you should wrap it in TO_NUMBER, a date, TO_DATE and so on....
2) change the DBMS_SQL to do an insert into a global temporary table and return the ref cursor which select's * from GTT;
3) upgrade to Oracle 11 :) -
Procedure to RETURN a REF CURSOR
Environment:
OWB10g Client on Windows XP Professional
Repository - 9.2.0.4 on UNIX (AIX 5.2)
Target - 9.2.0.4 on UNIX (AIX 5.2)
Is it possible to create a PROCEDURE in OWB that returns a REF CURSOR?
It was not one of the TYPEs available when specifying the procedure parameters.
Is this an enhancement that's coming if it's not possible today?
Many thanks for all feedback. This is a great interactive discussion forum.
GaryGood afternoon Gary,
Have you checked whether it's possible to use the table-function?
Don't know you specific requirements, but according to the explanation ("Table functions extend PL/SQL and are a new option in Oracle9i. This option allows a function to accept, process and return multiple rows.") it at least is capable of returning rowtypes.
Cheers, Patrick -
Can oracle function return more than one value
Hi All
please answer can oracle function return more than one value
need one schenario
regardsCan any function, irrespective of the language, return multiple values?
OF COURSE NOT!!
So why do you think Oracle will now suddenly do it differently than all other languages? Never mind that it is impossible for a function (a unit/module of code) returning a memory address, to return multiple memory addresses. The machine code that does that, has not been yet been designed/implemented.
I am continually amazed that this question is asked. It is about something so fundamental in almost every single 3rd and 4th generation language... something that is taught right at the start... the definition of what a procedure and what a function is.
Sorry, but I simply cannot pull punches on this subject and smooth it over. There is something fundamentally wrong with your training as a programmer if you have to ask such a question about a function.
And whatever programming skills you build on such a foundation, will be seriously lacking.
I kindly suggest that you get back to the very basics of programming - and review and revisit until you fully understand it. There are no shortcuts in becomming a good programmer.
Message was edited by:
Billy Verreynne -
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 -
Using an Oracle procedure that returns three ref cursors
Is it possible to use an Oracle stored proc that outputs 3 reference cursors to create a BO report? I can get it to work for one ref cursor only.
Well, If no one can answer my first question, how about a new one. Can you join 2 data cubes on a key in a BO report (using 2 Oracle stored procedures)? For example, I have one cube that has employee beneficiary information and a second cube with what employee coverages the person has. I need to have a report that displays an employee, thier coverages and then a section that show the employee benefits. I need a report for each employee (therefore 100 employees= 100 reports) and I can't join the data cubes. Any help would be appreciated.
-
How to update data returned using REF CURSOR
Hi all,
I am trying to update updated data in a gridview but the update button seem to do nothing as i retrieve data using REF CURSOR.
Let me describe the architecture of my application first. I'm trying to implement best practice whenever possible. I am following the data access tutorial published in www.asp.net , the only difference is that i have an Oracle (10g) database. So I split my application into three layers, data access, business logic, and presentation layer. I'm also writing all queries in an Oracle package.
So I have my Oracle packages that perform CRUD operations. Then I have an xsd file that define dataTable based on the package procedure. My business logic layer then calls functions defined in the xsd file. And finally a detailsView control that uses an ObjectDataSource to call business logic functions.
In a nutshell, I am just trying to update records retrieved using REF CURSOR. Your help is very much appreciated. Please let me know if further details are required. Cheers,In the DataSet (xsd) where your DataTable is defined, you just need to add additional methods to the TableAdapter to handle insert, update and delete, either with SQL or by mapping to stored procedures.
Alternatively in code, create an OracleDataAdapter and supply its InsertCommand, UpdateCommand and DeleteCommand.
David -
How return parameter ref Cursor from procedure using dynamic SQL?
I sorry, but i very need help.
I using Oracle 8.0.6
I need to return parameter of type ref Cursor from procedure.
create or replace package PlanExp is
type cursortype is ref cursor;
procedure ShowPlan (cursorparam out
cursortype.............);
end PlanExp;
create or replace package body PlanExp is
procedure ShowPlan (cursorparam out cursortype,
.............) Is
sql_str varchar2(1000);
sql_str_select varchar2(100);
sql_str_from varchar2(100);
sql_str_where varchar2(500);
Return_Code integer;
Num_Rows integer;
cur_id_sel integer;
tSum_Plan DBMS_SQL.NUMBER_TABLE;
tSum_Plan_Ch DBMS_SQL.NUMBER_TABLE;
tSum_Plan_Day DBMS_SQL.NUMBER_TABLE;
begin
/* calculating string variables ........... /*
sql_str := 'select ' || sql_str_select ||
'from ' || sql_str_from ||
'where ' || sql_str_where ||
'group by ' || sql_str_select;
cur_id_sel := dbms_sql.open_cursor;
dbms_sql.parse(cur_id_sel, sql_str, dbms_sql.native);
dbms_sql.define_array(cur_id_sel, 1, tSum_Plan, 20, 1);
dbms_sql.define_array(cur_id_sel, 2, tSum_Plan_Ch, 20, 1);
dbms_sql.define_array(cur_id_sel, 3, tSum_Plan_Day, 20, 1);
Return_Code := dbms_sql.execute(cur_id_sel);
delete from TEMP_SHOWPLAN;
Loop
Num_Rows := dbms_sql.Fetch_Rows(cur_id_sel);
dbms_sql.column_value(cur_id_sel, 1, tSum_Plan);
dbms_sql.column_value(cur_id_sel, 2, tSum_Plan_Ch);
dbms_sql.column_value(cur_id_sel, 3, tSum_Plan_Day);
if Num_Rows = 0 then
exit;
end if;
Exit When Num_Rows < 20;
End Loop;
dbms_sql.close_cursor(cur_id_sel);
end;
end PlanExp;
How return cursor (cursorparam) from 3 dbms_sql.column_value-s ?I am using Oracle 8.1.7, so I don't know if this will work in
8.0.6 or not:
SQL> CREATE TABLE test
2 (col1 NUMBER,
3 col2 NUMBER,
4 col3 NUMBER)
5 /
Table created.
SQL> INSERT INTO test
2 VALUES (1,1,1)
3 /
1 row created.
SQL> INSERT INTO test
2 VALUES (2,2,2)
3 /
1 row created.
SQL> INSERT INTO test
2 VALUES (3,3,3)
3 /
1 row created.
SQL> CREATE TABLE temp_showplan
2 (tSum_Plan NUMBER,
3 tSum_Plan_Ch NUMBER,
4 tSum_Plan_Day NUMBER)
5 /
Table created.
SQL> EDIT planexp
CREATE OR REPLACE PACKAGE PlanExp
IS
TYPE CursorType IS REF CURSOR;
PROCEDURE ShowPlan
(cursorparam IN OUT CursorType,
sql_str_select IN VARCHAR2,
sql_str_from IN VARCHAR2,
sql_str_where IN VARCHAR2);
END PlanExp;
CREATE OR REPLACE PACKAGE BODY PlanExp
IS
PROCEDURE ShowPlan
(cursorparam IN OUT CursorType,
sql_str_select IN VARCHAR2,
sql_str_from IN VARCHAR2,
sql_str_where IN VARCHAR2)
IS
sql_str VARCHAR2 (1000);
cur_id_sel INTEGER;
return_code INTEGER;
BEGIN
DELETE FROM temp_showplan;
sql_str := 'INSERT INTO temp_showplan '
|| ' SELECT ' || sql_str_select
|| ' FROM ' || sql_str_from
|| ' WHERE ' || sql_str_where;
cur_id_sel := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE (cur_id_sel, sql_str, DBMS_SQL.NATIVE);
return_code := DBMS_SQL.EXECUTE (cur_id_sel);
DBMS_SQL.CLOSE_CURSOR (cur_id_sel);
OPEN cursorparam FOR SELECT * FROM temp_showplan;
END ShowPlan;
END PlanExp;
SQL> START planexp
Package created.
Package body created.
SQL> VARIABLE g_ref REFCURSOR
SQL> EXEC PlanExp.ShowPlan (:g_ref, 'col1, col2,
col3', 'test', ' 1 = 1 ')
PL/SQL procedure successfully completed.
SQL> PRINT g_ref
TSUM_PLAN TSUM_PLAN_CH TSUM_PLAN_DAY
1 1 1
2 2 2
3 3 3 -
Returning a ref cursor on a Global Temporary table
I realize this is probably not feasible but I am manipulating data and storing it in a GTT and I wish to return that transformed data out as a ref cursor is this possible to do? I also dont want a static table because this is a heavily hit procedure and I do not want to have to keep track of which session is which data not to mention contention between them.
I am using Oracle 10g on Windows server 2008You will be able to see the records in the refcursor in the same session
Example
SQL> create global temporary table X_GTT as select * from emp where 1=2;
Table created.
SQL> insert into x_GTT select * from emp ;
14 rows created.
SQL> var rf refcursor ;
SQL> begin
2 open :rf for select * from X_GTT ;
3 end ;
PL/SQL procedure successfully completed.
SQL> print rf
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800 99
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.SS -
Ref cursor to object and return to ref cursor
how i will call object type from refcursor and return value to ref cursor .
I need a help. please help me.
takes oracle object types as input/output.
PROCEDURE createserviceorder(
P_serviceorder IN serviceorder,
P_serviceid in out p_sm_type.serviceid,
P_serviceorderid out p_sm_type.serviceorderid,
Returnstatus out callstatus);
The serviceorder, callstatus are oracle object types.
The wrapper procedure for this API would be something like the example with pseudo code below
PROCEDURE createserviceorderwrapper(
P_serviceorder IN REFCURSOR,
P_serviceid in out p_sm_type.serviceid,
P_serviceorderid out p_sm_type.serviceorderid,
Returnstatus out REFCURSOR)
Map from ref cursor P_serviceorder to oracle object for serviceorder;
Map from other data types to local variables;
Call createserviceorder (pass the parameters here and get output .);
Map output callstatus to its equivalent REF CURSOR variable;
Return callstatus (and other out parameters if any )as REF CURSORS;
} -
Returning a Ref cursor as an OUT Parameter
Hi Guys
I have defined 2 Types and 2 Ref cursors as shown below.I have written a procedure having 2 IN and 2 OUT parameters which are of type Ref cursors and return records to the calling client. My question is how can i test for the output of the two cursors here in pl/sql?.. also i should not close the sursors.. right?..its the job of the calling client as per my knowledge....Please suggest
TYPE type_dept_Rec IS RECORD(deptNo varchar2);
TYPE type_prod_Rec IS RECORD(prodType varchar2);
TYPE deptCursor IS REF CURSOR RETURN type_dept_Rec;
TYPE prodCursor IS REF CURSOR RETURN type_prod_Rec;
PROCEDURE TEST (pinCode IN varchar2, prodType IN number, deptCursor OUT deptType, productCursor OUT deptType) IS
BEGIN
OPEN deptCursor FOR SELECT
deptNo
from
DEPT
where
pinCode = pinCode;
OPEN productCursor FOR SELECT
prodCode
from
PROD
where
prodType = prodType;
end;A Correction to the above code snippet
Hi Guys
I have defined 2 Types and 2 Ref cursors as shown below.I have written a procedure having 2 IN and 2 OUT parameters which are of type Ref cursors and return records to the calling client. My question is how can i test for the output of the two cursors here in pl/sql?.. also i should not close the sursors.. right?..its the job of the calling client as per my knowledge....Please suggest
TYPE type_dept_Rec IS RECORD(deptNo varchar2);
TYPE type_prod_Rec IS RECORD(prodType varchar2);
TYPE deptCursor IS REF CURSOR RETURN type_dept_Rec;
TYPE prodCursor IS REF CURSOR RETURN type_prod_Rec;
PROCEDURE TEST (pinCode IN varchar2, prodType IN number, deptCursor OUT deptCursor, productCursor OUT prodCursor) IS
BEGIN
OPEN deptCursor FOR SELECT
deptNo
from
DEPT
where
pinCode = pinCode;
OPEN productCursor FOR SELECT
prodCode
from
PROD
where
prodType = prodType;
end
Maybe you are looking for
-
Faulty Devices - Blackberry Z10
Our company recently renewed the corporate mobile phone contract with Maxis and we received Blackberry Z10 Smart Phones as free device for the plan that we signed up. We received 58 units of Blackberry Z10 in June 2014, out of which to-date, several
-
Adobe Reader 9 & Adobe Distiller 6.0
I have a user who has Distiller 6.0 & Reader 9.0 on his laptop. On a specific web site he is trying to download a pdf document, the computer defaults to distiller 6.0 and the web site refuses to open the document, stating that Reader 8.0 or 9.0 canno
-
Lightning to SD adapter supportet RAW formats?
Hi there! The Lightning to SD adapter product page states that "The Lightning to SD Card Camera Reader supports standard photo formats, including JPEG and RAW". However, I'm concerned that the RAW formats I shoot in might not be a "standard photo for
-
Großhandel mit mehreren Standorten
Hallo zusammen, wie geht man am idealerweise vor, um Standorte innerhalb eines Mandanten auseinander zu halten bzw. getrennt auswertbar zu halten? - auuschließlich über unterschiedliche Belegserien? Wie geht man vor, wenn man interne Bestellungen/ L
-
Hi All, I am new to ODI 11g, Can somebody help me with the following.. In 10g operator you can see details of the session by clicking on the session like execution time...user... see below image ... http://img27.imageshack.us/img27/3844/odii.jpg when