Using Ref cursor in Procedure.
Hi All,
Can i use a single ref cursor multple times within the life cycle of a procedure.
Thanks,
Dillip
Yes.
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
Similar Messages
-
Using Ref cursor from Procedure output in BPEL
Hi
Can any body help me ..
The output variable of db adapter is refcursor from stored procedure. in ref cursor i will get xml from a clob variable. how to use it in bpel...can an body help me how to do it....APEX is based on Oracle Database. Whatever you can do with PL/SQL, the same can be done with APEX also. APEX stores the application definition in the form of metadata.
So if you put all your logic and code in packages, procedures or functions then it will be really good compact and modular approach.
Bottom line is that you can do all of those.
Check the documentation at
http://www.oracle.com/technetwork/developer-tools/apex/documentation/index.html
Thanks,
Mehabub -
Using Ref Cursor in procedure in place of normal cursor
Hi,
I have a procedure where i have the follwoing cursors declared,
CURSOR c_wip IS
SELECT tdvalue
FROM tabledetails
WHERE tdidcode = 'PEL_DASHBOARD'
AND tdkey LIKE 'WIP_QUEUES%';
CURSOR c_pending IS
SELECT tdvalue
FROM tabledetails
WHERE tdidcode = 'PEL_DASHBOARD'
AND tdkey LIKE 'PENDING_QUEUES%';
CURSOR c_out IS
SELECT tdvalue
FROM tabledetails
WHERE tdidcode = 'PEL_DASHBOARD'
AND tdkey LIKE 'OUT_QUEUES%';
CURSOR c_out_status IS
SELECT tdvalue
FROM tabledetails
WHERE tdidcode = 'PEL_DASHBOARD'
AND tdkey LIKE 'OUT_STATUS%';
Will the usage of 1 ref cursor instead of the 4 cursors increase the performance.
Thanks.Cursor is a structure which points to a memory locations.
While a Ref-cursor is a datastructure which point to a object which inturn points to Memory locations.
The advantage of having Ref-cursor is that we can pass dynamically the Ref-cursor as a parameter to a procedures.
So it does improve the performance to a small extent. -
I have a procedure which is using one ref cursor as OUT paramater. Now when I call this procedure, it gives me the following error:
ORA-00932: inconsistent datatypes: expected CURSER got NUMBER
ORA-06512: at "APPS.ORDER_RETURN1", line 8
ORA-06512: at "APPS.ORDER_RETURN2", line 4
ORA-06512: at line 1
Below is my code
PROCEDURE ORDER_RETURN1(p_order OUT sys_refcursor) IS
TYPE OE_ORDER_rcur IS REF CURSOR;
rcur OE_ORDER_rcur;
BEGIN
OPEN rcur FOR
SELECT ORDER_NUMBER FROM OE_ORDER_HEADERS_ALL WHERE ROWNUM < 4;
FETCH rcur INTO p_order;
CLOSE rcur;
END ORDER_RETURN1;
PROCEDURE ORDER_RETURN2 IS
OE_ORDER_rcur11 sys_refcursor;
BEGIN
ORDER_RETURN1(OE_ORDER_rcur11);
end;
I tried to call proc ORDER_RETURN1 with the help of proc ORDER_RETURN2, but no change, it gives me same error if i call the first proc ORDER_RETURN1 or i call ORDER_RETURN2.
I am stuck with this problem, I had used ref cursor in procedure but not able to call the procedure which uses ref cursor as OUT parameter.
Please help me to resolve this.
Thanks
Nidhi..Check out this
SQL>VARIABLE X REFCURSOR
SQL>CREATE OR REPLACE PROCEDURE ORDER_RETURN1(p_order OUT sys_refcursor) IS
2 BEGIN
3 OPEN p_order FOR
4 SELECT OBJECT_ID FROM ALL_OBJECTS WHERE ROWNUM < 4;
5 END ORDER_RETURN1;
6 /
Procedure created.
SQL>EXEC ORDER_RETURN1(:X)
PL/SQL procedure successfully completed.
SQL>PRINT X
OBJECT_ID
4
39
30
SQL>Regards
Arun -
Call procedure that uses REF CURSOR?
Can someone tell me how to call a procedure that uses a REF CURSOR?
Procedure is something like this:
PROCEDURE my_proc
P_PROG_ID IN VARCHAR2,
P_CRITERIA IN VARCHAR2,
P_TASKCURSOR OUT MYREFCUR
IS
blah, blah blah
I tried this to call the procedure:
exec my_proc(variable1,variable2,variable3)
but I don't know how to define variable3.
Can someone help me out?Based on the parameters for the procedure, it looks like you have a cursor (myrefcursor) defined in a package somewhere. So, in sqlplus, you would need to do it in an anonymous block, something like:
DECLARE
l_cur package_name,myrefcur;
variables to hold cursor fields
BEGIN
my_proc('ID', 'Criteria', l_cur);
LOOP
FETCH l_cur INTO variables to hold cursor fields
EXIT WHEN l_cur%NOTFOUND;
Do something with variables
END LOOP;
CLOSE l_cur;
END;If you are on Oracle 9 or higher, assuming that myrefcursor is weakly typed,
you could change the definition of the procedure to:
PROCEDURE my_proc (p_prog_id IN VARCHAR2,
p_criteria IN VARCHAR2,
P_TASKCURSOR OUT SYS_REFCURSOR)then you could call it in sql plus like:
-- Define the variables
var var1 VARCHAR2(100);
var var2 VARCHAR2(100);
var cur SYS_REFCURSOR;
-- Assign Vlaues to the IN parameters
EXEC :var1 := 'ID'; :var2 := 'Criteria';
EXEC my_proc(:var1, :var2, :cur);
-- See the contents of the cursor
print curHTH
John -
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 -
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 -
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 -
Using Ref Cursors as region source
Is it possible to use a function that returns a ref cursor as a region's source? I asked this question at the end of another thread and got no response so I made this new thread.
I created an application called 'ref cursor' on apex.oracle.com at
http://apex.oracle.com/pls/otn/f?p=4550
Workspace : wc_jason
username: dev
password: password
There is a table named TBL and a function returning a ref cursor name FNC. On the home page there are three regions, one using a sql statement, one using a pl/sql function returning a sql statement, and one that attempts to use a ref cursor. The ref cursor region's condition is set to NEVER because I couldn't get it to work and I wanted to show the page with the two working regions.
Can I even use a ref cursor in this manor?
Thanks for the help.Heres a quick example I did for you:
create or replace package pkg_refcursordemo
as
type rc_generic is ref cursor;
rec_emp emp%rowtype;
type tab_emp is table of emp%rowtype;
procedure proc_get_emp (
pi_ename in emp.ename%type
,pio_emp_rc in out rc_generic
function func_get_emp (
pi_ename in emp.ename%type
return tab_emp pipelined;
end pkg_refcursordemo;
create or replace package body pkg_refcursordemo
as
-- Procedure with in out ref cursor parameter
procedure proc_get_emp (
pi_ename in emp.ename%type
,pio_emp_rc in out rc_generic
is
begin
open pio_emp_rc for
select empno
, ename
, job
, mgr
, hiredate
, sal
, comm
, deptno
from emp
where ename like pi_ename||'%';
end proc_get_emp;
-- Wrapper pipelined function
function func_get_emp (
pi_ename in emp.ename%type
return tab_emp pipelined
is
l_rc_generic rc_generic;
l_rec_emp emp%rowtype;
begin
proc_get_emp (
pi_ename => pi_ename
,pio_emp_rc => l_rc_generic
loop
fetch l_rc_generic into l_rec_emp;
exit when l_rc_generic%notfound;
pipe row ( l_rec_emp );
end loop;
close l_rc_generic;
return;
end func_get_emp;
end pkg_refcursordemo;
create or replace view vw_emp
as
select empno
, ename
, job
, mgr
, hiredate
, sal
, comm
, deptno
from table ( pkg_refcursordemo.func_get_emp( null ) )
SQL> select * from vw_emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800 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
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
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.
SQL>
Whats cool is you can declare the view with an APEX variable in it e.g.
create or replace view vw_emp
as
select empno
, ename
, job
, mgr
, hiredate
, sal
, comm
, deptno
from table ( pkg_refcursordemo.func_get_emp( v('P1_ENAME_PARAM' ) )
/ -
How to out Dynamic ref cursor from Procedure to Forms
Hi
I am trying to out Dynamic ref cursor from Procedure to Forms, But I am unable to do so. however cursor return the value within procedure but I am failed to capture the same in Forms
Pl advice suggestion if any, Here I am attaching full procedure for reference
CREATE PACKAGE winepkg
IS
TYPE wine IS RECORD ( mynumber number);
/* Define the REF CURSOR type. */
TYPE wine_type IS REF CURSOR RETURN wine;
END winepkg;
CREATE procedure find_wine
(col1_in in number,
c1 out winepkg.wine_type) as
vsql varchar2(1000);
cur sys_refcursor;
x number;
BEGIN
vsql:='select bo_id from bo_details where bo_details.bo_id = '||col1_in ;
open cur for vsql;
c1:=cur;
--fetch c1 into x;
--dbms_output.put_line(x);
END find_wine;
In front end forms
Declare
TYPE F is REF CURSOR;
CUR_F F;
rec number;
Begin
break;
find_wine( 1601480000011078,cur_f ) ;
Loop
fetch cur_f into rec ;
Message(rec ) ;pause;
exit when cur_f%notfound ;
End loop ;
exception
when others then
Message(sqlerrm) ;pause;
End ;yo can use
declare
c_cursor EXEC_SQL.CursType;
v_stmt varchar2(2000) = 'select a, b, c from mytab where cond1'; -- you can create this value dynamically
begin
c_cursor := Exec_SQL.Open_cursor;
EXEC_SQL.PARSE(c_articulos, v_stmt);
EXEC_SQL.DEFINE_COLUMN(c_articulos,1, v_colchar1, 30);
EXEC_SQL.DEFINE_COLUMN(c_articulos,2, v_colchar2, 15);
EXEC_SQL.DEFINE_COLUMN(c_articulos,3, v_colchar3, 30);
v_exec := EXEC_SQL.EXECUTE(c_cursor);
WHILE EXEC_SQL.FETCH_ROWS(c_cursor) > 0 LOOP
EXEC_SQL.COLUMN_VALUE(c_cursor,1,v_colchar1);
EXEC_SQL.COLUMN_VALUE(c_c_cursor,2,v_colchar2);
EXEC_SQL.COLUMN_VALUE(c_c_cursor,3,v_colchar3);
assign_values_to_block;
END LOOP;
EXEC_SQL.CLOSE_CURSOR(c_cursor);
end;
and WORKS IN FORMS 6 -
Example of Simple SP using REF Cursors
Hi All,
i want simple stored procedure using REF Cursors.
Select * From Emp Where Deptno='20'
Use Scott & Tiger, Default database.
i am poassing parameter deptno at runtime.i want all the records of deptno=20.
i know REF Cursors return Record Set.but i created,it will throw errors.
Anyone pls helpPost your code what you have tried. Also your requirement can be fulfilled with parametrized cursor.
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e17126/static.htm#LNPLS00602
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e17126/static.htm#LNPLS00605 -
Report using ref cursor or dynamic Sql
Hi,
I never create a report using a ref cursor or a dynamic sql. Could any one help me to solve the below issue.
I have 2 tables.
1. Student_Record
2. Student_csv_help
Student_Record the main table where the data is stored.
Student_csv_help will contain the all the column names of the Student_record.
CREATE TABLE Student_CSV_HELP
ENTRY_ID NUMBER,
RAW_NAME VARCHAR2(40 BYTE),
DESC_NAME VARCHAR2(1000 BYTE),
IN_OUTPUT_LIST VARCHAR2(1 BYTE)
SET DEFINE OFF;
Insert into TOA_CSV_HELP
(ENTRY_ID, RAW_NAME, DESC_NAME, IN_OUTPUT_LIST)
Values
(1, 'S_ID', 'Student ID', 'Y');
Insert into TOA_CSV_HELP
(ENTRY_ID, RAW_NAME, DESC_NAME, IN_OUTPUT_LIST)
Values
(2, 'S_Name', 'Student Name', 'Y');
Insert into TOA_CSV_HELP
(ENTRY_ID, RAW_NAME, DESC_NAME, IN_OUTPUT_LIST)
Values
(3, 'S_Join_date', 'Joining Date', 'Y');
Insert into TOA_CSV_HELP
(ENTRY_ID, RAW_NAME, DESC_NAME, IN_OUTPUT_LIST)
Values
(4, 'S_Address', 'Address', 'Y');
Insert into TOA_CSV_HELP
(ENTRY_ID, RAW_NAME, DESC_NAME, IN_OUTPUT_LIST)
Values
(5, 'S_Fee', 'Tution Fee', 'N');
commit;
CREATE TABLE Student_record
S_ID NUMBER,
S_Name VARCHAR2(100 BYTE),
S_Join_date date,
S_Address VARCHAR2(360 BYTE),
S_Fee Number
Insert into Student_record
(S_ID, S_Name, S_Join_date, S_Address,S_Fee)
Values
(101, 'john', TO_DATE('12/17/2009 08:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'CA-94777', 2000);
Insert into Student_record
(S_ID, S_Name, S_Join_date, S_Address,S_Fee)
Values
(102, 'arif', TO_DATE('12/18/2009 08:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'CA-94444', 3000);
Insert into Student_record
(S_ID, S_Name, S_Join_date, S_Address,S_Fee)
Values
(103, 'raj', TO_DATE('12/19/2009 08:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'CA-94555', 2500);
Insert into Student_record
(S_ID, S_Name, S_Join_date, S_Address,S_Fee)
Values
(104, 'singh', TO_DATE('12/20/2009 08:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'CA-94666', 2000);
Commit;
Now my requirement is:
I have a form with Student_record data block. When i Click on print Button on this form. It will open another window which has Student_CSV_HELP.DESC_NAME and a check box before this.
The window look like as below:
check_box DESC_NAME+
X S_ID+
-- S_Name+
X S_Join_date+
X S_Address+
-- S_Fee+
X means check box checked.+
-- means check box Unchecked.+
After i selected these check boxes i will send 2 parameters to the report server
1. a string parameter to the report server which has the value 'S_ID,S_Join_date,S_Address' (p_column_name := 'S_ID,S_Join_date,S_Address');
2. the s_id value from the student_record block (p_S_id := '101');
Now my requirement is when i click on run. I need a report like as below:
Student ID : 101+
Joining Date : 12/17/2009 08:00:00+
Address : CA-94777+
This is nothing but the ref cursor should run like as below:
Select S_id from student_record block S_id = :p_S_id;
Select S_Join_date from student_record block S_id = :p_S_id;
Select S_Address from student_record block S_id = :p_S_id;
So, according to my understanding i have to select the columns at the run time. I dont have much knowledge in creating reports using ref cursor or dynamic sql.
So please help me to solve this issue.
Thanks in advance.Plain sql should satisfy your need. Try ....
Select S_id, S_Join_date, S_Address
from student_record
where S_id = :p_S_id -
Cursors are not closed when using Ref Cursor Query in a report ORA-01000
Dear Experts
Oracel database 11g,
developer suite 10.1.2.0.2,
application server 10.1.2.0.2,
Windows xp platform
For a long time, I'm hitting ORA-01000
I have a 2 group report (master and detail) using Ref Cusor query, when this report is run, I found that it opens several cursors (should be only one cursor) for the detail query although it should not, I found that the number of these cursors is equal to the number of master records.
Moreover, after the report is finished, these cursors are not closed, and they are increasing cumulatively each time I run the report, and finally the maximum number of open cursors is exceeded, and thus I get ORA-01000.
I increased the open cursors parameter for the database to an unbeleivable value 30000, but of course it will be exceeded during the session because the cursors are increasing cumulatively.
I Found that this problem is solved when using only one master Ref Cursor Query and create a breake group, the problem is solved also if we use SQL Query instead of Ref Query for the master and detail queries, but for some considerations, I should not use neither breake group nor SQL Query, I have to use REF Cursor queries.
Is this an oracle bug , and how can I overcome ?
Thanks
Edited by: Mostafa Abolaynain on May 6, 2012 9:58 AMThank you Inol for your answer, However
Ref Cursor give me felxibility to control the query, for example see the following query :
function QR_1RefCurDS return DEF_CURSORS.JOURHEAD_REFCUR is
temp_JOURHEAD DEF_CURSORS.JOURHEAD_refcur;
v_from_date DATE;
v_to_date DATE;
V_SERIAL_TYPE number;
begin
SELECT SERIAL_TYPE INTO V_SERIAL_TYPE
FROM ACC_VOUCHER_TYPES
where voucher_type='J'
and IDENT_NO=:IDENT
AND COMP_NO=TO_NUMBER(:COMPANY_NO);
IF :no_date=1 then
IF V_SERIAL_TYPE =1 THEN
open temp_JOURHEAD for select VOCH_NO, VOCH_DATE
FROM JOURHEAD
WHERE COMP_NO=TO_NUMBER(:COMPANY_NO)
AND IDENT=:IDENT
AND ((TO_NUMBER(VOCH_NO)=:FROM_NO and :FROM_NO IS NOT NULL AND :TO_NO IS NULL)
OR (TO_NUMBER(VOCH_NO) BETWEEN :FROM_NO AND :TO_NO and :FROM_NO IS NOT NULL AND :TO_NO IS NOT NULL )
OR (TO_NUMBER(VOCH_NO)<=:TO_NO and :FROM_NO IS NULL AND :TO_NO IS NOT NULL )
OR (:FROM_NO IS NULL AND :TO_NO IS NULL ))
ORDER BY TO_NUMBER(VOCH_NO);
ELSE
open temp_JOURHEAD for select VOCH_NO, VOCH_DATE
FROM JOURHEAD
WHERE COMP_NO=TO_NUMBER(:COMPANY_NO)
AND IDENT=:IDENT
AND ((VOCH_NO=:FROM_NO and :FROM_NO IS NOT NULL AND :TO_NO IS NULL)
OR (VOCH_NO BETWEEN :FROM_NO AND :TO_NO and :FROM_NO IS NOT NULL AND :TO_NO IS NOT NULL )
OR (VOCH_NO<=:TO_NO and :FROM_NO IS NULL AND :TO_NO IS NOT NULL )
OR (:FROM_NO IS NULL AND :TO_NO IS NULL ))
ORDER BY VOCH_NO;
END IF;
ELSE
v_from_date:=to_DATE(:from_date);
v_to_date:=to_DATE(:to_date);
IF V_SERIAL_TYPE =1 THEN
open temp_JOURHEAD for select VOCH_NO, VOCH_DATE
FROM JOURHEAD
WHERE COMP_NO=TO_NUMBER(:COMPANY_NO)
AND IDENT=:IDENT
AND ((voch_date between v_from_date and v_to_date and :from_date is not null and :to_date is not null)
OR (voch_date <= v_to_date and :from_date is null and :to_date is not null)
OR (voch_date = v_from_date and :from_date is not null and :to_date is null)
OR (:from_date is null and :to_date is null ))
ORDER BY VOCH_DATE,TO_NUMBER(VOCH_NO);
ELSE
open temp_JOURHEAD for select VOCH_NO, VOCH_DATE
FROM JOURHEAD
WHERE COMP_NO=TO_NUMBER(:COMPANY_NO)
AND IDENT=:IDENT
AND ((voch_date between v_from_date and v_to_date and :from_date is not null and :to_date is not null)
OR (voch_date <= v_to_date and :from_date is null and :to_date is not null)
OR (voch_date = v_from_date and :from_date is not null and :to_date is null)
OR (:from_date is null and :to_date is null ))
ORDER BY VOCH_DATE,VOCH_NO;
END IF;
END IF;
return temp_JOURHEAD;
end; -
Unable to use ref cursor as a input parameter at the time of inserting reco
Hi
i am unable to use ref cursor when inserting the data to oracle 11g from visual studio 2008. please help me as early as possible my code is bellows
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Configuration;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
public partial class App_frmTest : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
protected void btnClick_Click(object sender, EventArgs e)
OracleCommand cmd=new OracleCommand();
Data objdata = new Data();
int i = 0;
string constr = "Data Source=Cwc;User Id=scott; Password=tiger;";// enlist=false; pooling=false;
OracleConnection con = new OracleConnection(constr);
/*Connection Open*/
con.Open();
cmd.Connection = con;
/*Connection Open End*/
/*Select Through Ref Cursor*/
cmd.CommandText = "scott.TEST_USER.getUSER";
cmd.CommandType = CommandType.StoredProcedure;
OracleParameter p_rc = cmd.Parameters.Add("p_rc", OracleDbType.RefCursor, DBNull.Value, ParameterDirection.Output);
OracleParameter p_rc1;
if (TextBox1.Text == "")
p_rc1 = cmd.Parameters.Add("p_rc", OracleDbType.Int16, DBNull.Value, ParameterDirection.Input);
else
p_rc1 = cmd.Parameters.Add("p_rc", OracleDbType.Int16, Convert.ToInt16(TextBox1.Text), ParameterDirection.Input);
// OracleParameter p_rc1 = cmd.Parameters.Add("p_rc", OracleDbType.Int16, 2, ParameterDirection.Input);
OracleDataReader reader = cmd.ExecuteReader();
DataSet ds = new DataSet();
DataTable dt1 = new DataTable();
dt1.Load(reader);
ds.Tables.Add(dt1);
GridView1.DataSource = ds;
GridView1.DataBind();
cmd.Parameters.Clear();
con.Close();
con.Dispose();
OracleCommand cmd1 = new OracleCommand();
OracleConnection con1 = new OracleConnection(constr);
con1.Open();
cmd1.Connection = con1;
cmd1.CommandText = "scott.TEST_USER.ADDUSER";
cmd1.CommandType = CommandType.StoredProcedure;
OracleParameter P_ADDUSER = cmd1.Parameters.Add("P_ADDUSER", OracleDbType.RefCursor, DBNull.Value, ParameterDirection.Input);
cmd1.ExecuteNonQuery(); // i am getting error when executing this line
Server Error in '/CWC' Application.
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source Error:
Line 77: OracleParameter P_ADDUSER = cmd1.Parameters.Add("P_ADDUSER", OracleDbType.RefCursor, DBNull.Value, ParameterDirection.Input);
Line 78: //OracleParameter P_MSG = cmd.Parameters.Add("P_MSG", OracleDbType.Varchar2, DBNull.Value, ParameterDirection.Output);
Line 79: cmd1.ExecuteNonQuery();
Line 80:
Line 81: DataTable dt = new DataTable();
Source File: d:\CWC\App\frmTest.aspx.cs Line: 79
Stack Trace:
[AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.]
Oracle.DataAccess.Client.OpsSql.ExecuteNonQuery(IntPtr opsConCtx, IntPtr& opsErrCtx, IntPtr& opsSqlCtx, IntPtr& opsDacCtx, IntPtr opsSubscrCtx, Int32& isSubscrRegistered, Int32 bchgNTFNExcludeRowidInfo, Int32 bQueryBasedNTFNRegistration, Int64& query_id, OpoSqlValCtx*& pOpoSqlValCtx, String pCommandText, IntPtr& pUTF8CommandText, IntPtr[] pOpoPrmValCtx, String[] ppOpoPrmRefCtx, OpoMetValCtx*& pOpoMetValCtx, Int32 prmCnt, Int32 bFromPool) +0
Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery() +4731
App_frmTest.btnClick_Click(Object sender, EventArgs e) in d:\CWC\App\frmTest.aspx.cs:79
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565Hi;
Its better to ask it at visual studio forum site:http://social.msdn.microsoft.com/Forums/en-US/category/visualstudio
Regard
Helios -
Using ref cursor in after parameter form in reports
hi everyone,
I have problem in usage of ref cursor in after parameter form. My actual requirement is I have user parameter :p_minval, :p_maxval. The values into these user parameters will be coming dynamically using sql_statement as shown below
select min(empid),max(empid) into :p_minval, :p_maxval from emp where empid in (:p_emp);
I will be writing this query in the after parameter form
:p_emp is a lexical parameter as per me but the after parameter form is taking it as a bind variable. so I decided to define a ref cursor and then use it for retrieve. But when I use ref cursor it is returning pl/sql error 591 saying that this is not supported by client side can anyone help me plz..
The following is the code i tried to use in after parameter form
function afterPform return boolean is
type rc is ref cursor;
l_rc rc;
sqlstmt varchar2(512);
begin
sqlstmt:='select min(empid),max(empid) from emp where empid in ('||:p_emp||')';
open l_rc for
select max(empid) from emp where empid in ('||:p_emp||')';
fetch l_rc into :p_maxval;
close l_rc;
return(true);
end;
thanks & regards
venkatI ran into the same problem. any body knows why?
Maybe you are looking for
-
How to put free games an music on my iphone
new at this need help with free apps always saying put email an password in
-
"Search Entire Message" not working in Mail
This week my company switched to a new hosting provider and now I'm having trouble configuring Mail.app to search my emails. The new accounts are IMAP accounts hosted by GoDaddy. They connect perfectly, send and receive perfectly. In the account sett
-
I have the following class (source code from java core tips): public class GetTime { final private static int DAYTIME_PORT = 13; public static void main(String args[]) throws IOException { if (args.length == 0) {
-
Hi, I have located a file that is slowing down my iMac, but it is impossible to delete as I just get the SPOD everytime I try! I'm used Omnidisksweeper in order to find it and also to delete it as well Thanks dudes :)
-
Who can I contact about my iTunes U Application status?
We have submitted an application for iTunes U for our teaching hospitals. Saint Barnabas Health Care System in New Jersey. It's been after 14 days, and we have not heard back yet. Who can I contact about our iTunes U application status? We are locat