Performace optimization using Fetch cursor
Hi All,
I want to optimize this code
IF NOT i_package_data IS INITIAL.
REFRESH: i_gbfi150000.
SELECT *
FROM /bic/agbfi150000
INTO TABLE i_gbfi150000
FOR ALL ENTRIES IN i_package_data
WHERE /bic/gsrccocd = i_package_data-/bic/gsrccocd AND
/bic/gsrcpctr = i_package_data-/bic/gsrcpctr AND
/bic/gsrcjvnd = i_package_data-/bic/gsrcjvnd AND
/bic/gsrctpun = i_package_data-/bic/gsrctpun AND
/bic/gsrcacct = i_package_data-/bic/gsrcacct AND
/bic/gsrcmtyp = i_package_data-/bic/gsrcmtyp AND
/bic/gsrcactv = i_package_data-/bic/gsrcactv AND
/bic/gsrcfact = i_package_data-/bic/gsrcfact AND
/bic/gsrcpcat = i_package_data-/bic/gsrcpcat AND
/bic/gsrcf1 = i_package_data-/bic/gsrcf1 AND
/bic/gsrcf2 = i_package_data-/bic/gsrcf2 AND
/bic/gsrcf3 = i_package_data-/bic/gsrcf3 AND
/bic/gsrcf4 = i_package_data-/bic/gsrcf4 AND
/bic/gsrcf5 = i_package_data-/bic/gsrcf5 AND
/bic/gsrcf6 = i_package_data-/bic/gsrcf6 AND
/bic/gsrcf7 = i_package_data-/bic/gsrcf7 AND
/bic/gsrcf8 = i_package_data-/bic/gsrcf8 AND
/bic/gsrcf9 = i_package_data-/bic/gsrcf9 AND
/bic/gsrcf10 = i_package_data-/bic/gsrcf10.
the internal table i_package data is having 5000 entries so whn i am using for all entries it is taking a lot of time to execute.
i am thinking of fetch cursor technique but am not able to implement it.kindly help
regards,
Sharad
Moderator message - Please see Please Read before Posting in the Performance and Tuning Forum before posting in the performance and tuning forum
I don't see how using a cursor would help here at all
Rob
Similar Messages
-
How to trigger n number of jobs by processing using fetch cursor.
We have report which retrieves all the data from the master table using the open fetch cursor with the packet size 10,000
FOR EXAMPLE:
If there are 50,000 records(total)
For each 10,000 records it should trigger a job (we are trying to call a common program and submit the program in background through the main program ) were all the validation will be done only through the program
Totally we are expecting 5 job's to be trieggered.
Purpose : we want all the records validation to be completed Simultaneously with fraction of difference.Hi,
You might need to rethink on your scenario.
Where are the values for Vendor Region are getting stored for a PO? You might not be able to handle N number of Vendor regions for N number of Plants....You actually have to come to a 1:1 mapping. -
Problem with fetch cursor statement
Hi,
I am using FETCH CURSOR statement to fetch the data from a database table with package size. For the fetched records I am doing parallel processing using parallel processing frame work in banking system.
Here the problem is for the first iteration it works fine but when it comes to FETCH NEXT CURSOR in the second iteration , programs gets dumping by saying that 'CURSOR already closed'.
I am not closing the cursor in the program but some how it got closed some where in the standard function module which I used for parallel processing.
I used WITHHOLD also along with FETCH CURSOR but no use. Please let me know how to avoid the cursor to get close.
Below is my code
IF NOT l_tab_product IS INITIAL.
OPEN CURSOR WITH HOLD lv_cursor FOR
SELECT contract_int prodint cn_currency mig_grp
INTO TABLE gt_cont
FROM bca_contract
FOR ALL ENTRIES IN l_tab_product
WHERE prodint = l_tab_product-prodint
AND mig_grp IN s_migrp.
DO.
FETCH NEXT CURSOR lv_cursor
INTO TABLE gt_cont
PACKAGE SIZE lv_size.
IF sy-subrc <> 0.
CLOSE CURSOR lv_cursor.
EXIT.
ELSE.
parallel processing logic
ENDDO.
ENDIF.Using Withhold will not make sure that the cursor will not get closed because of commits.
SAP Doc says
If the addition WITH HOLD is specified, the database cursor is not closed by a database commit executed using Native SQL. The addition does not have an influence, however, on implicit database commits or on any rollbacks which always close the database cursor.
You have to check the part written in your parallel processing logic.
As Brad said please donot dump your old threads like this. -
How to fetch columns in cursor using FETCH?
create or replace PROCEDURE newprocedur(outname OUT VARCHAR2,outroll OUT NUMBER) AS
CURSOR c1 IS
select Name,Rollno,Section from emp;
BEGIN
Open c1;
fetch c1 into outname,outroll;
Here out of 3 columns in cursor is it possible to fetch only two columns using FETCH like i did above??
Edited by: im_asa on Nov 1, 2012 3:58 AMHi,
If you need only two why to fetch three ?
Just doing it by yourself will show you what will happen.
Regards
Yoonas -
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 -
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 -
Error while using a cursor on select
Hello,
I am using a cursor for a select statement below is the code.
OPEN CURSOR g_cursor FOR
SELECT bkpf~blart
bkpf~budat
bkpf~usnam
bsegc~bukrs
bsegc~belnr
bsegc~rfzei
bsegc~kunnr
bsegc~aunum
bsegc~ccins
bsegc~ccnum
bsegc~rcrsp
FROM bkpf
INNER JOIN bsegc
ON bkpf~bukrs = bsegc~bukrs AND
bkpf~belnr = bsegc~belnr AND
bkpf~gjahr = bsegc~gjahr
WHERE bkpf~budat IN s_budat
AND bsegc~bukrs IN s_bukrs
AND bsegc~rcrsp NE space.
DO.
FETCH NEXT CURSOR g_cursor APPENDING CORRESPONDING FIELDS OF TABLE i_bkpf PACKAGE SIZE g_pack.
IF sy-subrc <> 0.
EXIT.
ENDIF.
ENDDO.
CLOSE CURSOR g_cursor.
CLEAR g_cursor.
The program gives me a dump on the fetch statement , can anyone help me understand the possible cause of this dump and suggest a solution?
Thanks,
Alok.Hi,
What is the message that you get in the Dump?
Regards
Prasenjit -
Interoperability problem in fetching cursor b/w oracle 8.1.7 and oracle 9i
I have got the problem while executing the Fetch
cursor statement (The statement is used to fetch
record from the table by using cursor) through PROC
from Oracle 9i(client) on one m/c to Oracle
8i(server)version 8.1.7 on the other m/c
The Operating system is HP-UX 11.0.
We are getting the Oracle Errno as -932 ie
"inconsistent datatypes".
The code is given as follows
#include <stdio.h> /* UNIX */
#include <string.h> /* System include header files */
#include <stdlib.h>
EXEC SQL INCLUDE sqlca;
EXEC SQL begin declare section;
VARCHAR uid[20];
VARCHAR pwd[40];
VARCHAR dbname[40];
VARCHAR tblname[40];
char a_szSqlString[1024];
int h_nCount; /* balance */
EXEC SQL end declare section;
int main()
strcpy ((char *)uid.arr,"user");
uid.len=strlen((char *)uid.arr);
strcpy ((char *)pwd.arr,"pass");
pwd.len=strlen((char *)pwd.arr);
strcpy ((char *)dbname.arr,"net1");
dbname.len=strlen((char *)dbname.arr);
strcpy ((char *)tblname.arr,"ctltbl");
tblname.len=strlen((char *)tblname.arr);
fprintf(stdout," B4 CONNECTING\n");
fflush(stdout);
EXEC SQL CONNECT :uid IDENTIFIED BY :pwd USING :dbname;
fprintf(stdout," AFTER CONNECTING\n");
fflush(stdout);
if ( sqlca.sqlcode != 0 )
printf("Sqlconnect return code = %d\n", sqlca.sqlcode);
fflush(stdout);
return;
fprintf(stdout," AFTER CONNECT STATEMENT\n");
fflush(stdout);
sprintf(a_szSqlString, "%s%s%s%s ","select count(*) into :h_nCount from tab "," where TNAME=UPPER('", tblname,"') " );
EXEC SQL DECLARE sCheckTblName STATEMENT;
if ( sqlca.sqlcode != 0 )
printf("Sqlat = %d\n", sqlca.sqlcode);
fflush(stdout);
return;
EXEC SQL PREPARE sCheckTblName from :a_szSqlString;
if ( sqlca.sqlcode != 0 )
printf("Sqlprep = %d\n", sqlca.sqlcode);
fflush(stdout);
return;
fprintf(stdout," AFTER PREPARE STATEMENT\n");
fflush(stdout);
EXEC SQL DECLARE cCheckTblName CURSOR FOR sCheckTblName;
if ( sqlca.sqlcode != 0 )
printf("Sqldec = %d\n", sqlca.sqlcode);
fflush(stdout);
return;
fprintf(stdout," AFTER CURSOR DECLARE STATEMENT\n");
fflush(stdout);
EXEC SQL OPEN cCheckTblName;
if ( sqlca.sqlcode != 0 )
printf("Sqlopen = %d\n", sqlca.sqlcode);
fflush(stdout);
return;
fprintf(stdout," AFTER CURSOR OPEN STATEMENT\n");
fflush(stdout);
printf("THE VALUE OF COUNT is %d\n",h_nCount);
EXEC SQL FETCH cCheckTblName INTO :h_nCount;
if ( sqlca.sqlcode != 0 )
printf("Sqlfetch = %d\n", sqlca.sqlcode);
fflush(stdout);
return;
fprintf(stdout," AFTER CURSOR FETCH STATEMENT\n");
fflush(stdout);
EXEC SQL CLOSE cCheckTblName;
* If the return code is not ok and first_time is true, no data
* existed.
EXEC SQL AT :dbname COMMIT WORK RELEASE;
/*EXEC SQL COMMIT WORK RELEASE;*/
The Makefile contents is as follows
proc sqlcheck=full define=_PROC userid=user/pass@net1 CHAR_MAP=VARCHAR2, DBM
S=V9 iname=srini1.pc include=/back/app/oracle/rdbms/demo include=/back/app/oracl
e/plsql/public include=/back/app/oracle/network/public include=/back/app/oracle/
precomp/public
cc -g -o sri srini1.c -I/back/app/oracle/precomp/public -I/back/app/oracle/rdbm
s/demo -I/back/app/oracle/network/public -I/back/app/oracle/plsql/public -I/opt/
mqm/inc -L/back/app/oracle/lib32 -lclntsh
Please treat this as an very urgent one!!!!!!!!!!
V.arunachalam and J.srinivasanhi,
try deleting the into :... from the statement
that you are parsing as the cursor
rgds -
Multiple record insert problem in Oracle Procedure that uses a cursor
Dear X-pert guies,
I have a oracle procedure that use a cursor, I repeatedly make query on 1st table using cursor value and insert that queried value(of 1st table) to 2nd table
y_summary. y_summary has composite primary key :PK_Y_SUM (BILL_DATE, TRUNK_MGR, IDD_FLAG, PK_FLAG, PREFIX).*
when i run the procedure explicit2('201001'); the it gives me the error:::: begin explicit2('201001'); end;_
ORA-00001: unique constraint (PRM.PK_Y_SUM) violated_
ORA-06512: at "PRM.EXPLICIT2", line 413_
ORA-06512: at line 1_
but when i remove the composite primary key from y_summary table then, the procedure runs ok and make so many duplicate entries in y_summary.
but i want the single record to be inserted for single time in y_summary ,so You guies are honorly requested to make the required help .
the structure of y_summary Table and Procdure code is given below.
Table:
-- Create table
create table Y_SUMMARY
BILL_DATE VARCHAR2(10) not null,
TRUNK_MGR VARCHAR2(20) not null,
IDD_FLAG VARCHAR2(10) not null,
PK_FLAG NUMBER(2) not null,
OUTCALLS NUMBER(20,2),
OUTDUR NUMBER(20,2),
PREFIX VARCHAR2(10) not null
tablespace TBS_PRM_D01
pctfree 10
pctused 40
initrans 1
maxtrans 255
storage
initial 64K
minextents 1
maxextents unlimited
-- Create/Recreate primary, unique and foreign key constraints
alter table Y_SUMMARY
add constraint PK_Y_SUM primary key (BILL_DATE, TRUNK_MGR, IDD_FLAG, PK_FLAG, PREFIX)
using index
tablespace TBS_PRM_D01
pctfree 10
initrans 2
maxtrans 255
storage
initial 64K
minextents 1
maxextents unlimited
Procedure:
create or replace procedure explicit2( month_val in varchar2) is
cursor explicit_cur is select dest_code from y_table where dest_code like '44%' order by dest_code desc;
dummy varchar2(100);
lv_length Number(9);
sqlstr varchar2(2500);
rec_count1 number;
rec_count2 number;
rec_count3 number;
begin
open explicit_cur;
LOOP
fetch explicit_cur into dummy;
EXIT WHEN explicit_cur%NOTFOUND;
rec_count1 :=0;
rec_count2 :=0;
rec_count3 :=0;
lv_length := length(dummy);
sqlstr := 'select count(*) from y_table_data1 t where t.fee_dur_1_1 <> 0
and t.out_trunk in (''MHISRM'', ''GEISRM'', ''GEIMRP'', ''MHIMRP'', ''13'', ''ITAX1B'', ''ITAX3B'',''ITAX5B'', ''ITAX6B'', ''ITAX7B'', ''BTIMRP'', ''BTI5RP'', ''BTI6RP'', ''BTI7RP'')
and t.service_code = ''00'' and substr(t.orig_called_num,1,'||lv_length||')='||''''||dummy||'''';
execute immediate sqlstr into rec_count1;
sqlstr := 'select count(*) from y_table_data1 t where t.fee_dur_1_2 <> 0
and t.out_trunk in (''MHISRM'', ''GEISRM'', ''GEIMRP'', ''MHIMRP'', ''13'',
''ITAX1B'',''ITAX3B'',''ITAX5B'', ''ITAX6B'', ''ITAX7B'', ''BTIMRP'', ''BTI5RP'', ''BTI6RP'', ''BTI7RP'')
and t.service_code = ''00'' and substr(t.orig_called_num,1,'||lv_length||')='||''''||dummy||'''';
execute immediate sqlstr into rec_count2;
sqlstr := 'select count(*) from y_table_data1 t where t.fee_dur_1_1 <> 0
and t.out_trunk in (''MHISRM'', ''GEISRM'', ''GEIMRP'', ''MHIMRP'', ''13'',
''ITAX1B'', ''ITAX3B'',''ITAX5B'', ''ITAX6B'', ''ITAX7B'', ''BTIMRP'', ''BTI5RP'', ''BTI6RP'', ''BTI7RP'')
and t.service_code = ''012'' and substr(t.orig_called_num,1,'||lv_length||')='||''''||dummy||'''';
execute immediate sqlstr into rec_count3;
if(rec_count1>0) then
sqlstr := 'insert into y_summary(BILL_DATE ,PREFIX, TRUNK_MGR,OUTCALLS , OUTDUR , IDD_FLAG , PK_FLAG )
select '|| month_val||' ,substr(t.orig_called_num,1,'||lv_length||'),t.trunkout_operator ,count(*) , round(sum(ceil(t.duration / 15) * 15) / 60, 0),''00'',''1'' from y_table_data1 t where t.fee_dur_1_1 <> 0
and t.out_trunk in (''MHISRM'', ''GEISRM'', ''GEIMRP'', ''MHIMRP'', ''13'', ''ITAX1B'', ''ITAX3B'',''ITAX5B'', ''ITAX6B'', ''ITAX7B'', ''BTIMRP'', ''BTI5RP'', ''BTI6RP'', ''BTI7RP'')
and t.service_code = ''00'' and substr(t.orig_called_num,1,'||lv_length||')='||''''||dummy||''''|| ' group by t.trunkout_operator,substr(t.orig_called_num,1,'||lv_length||')';
execute immediate sqlstr;
commit;
sqlstr :='DELETE from y_table_data1 t where t.fee_dur_1_1 <> 0
and t.out_trunk in (''MHISRM'', ''GEISRM'', ''GEIMRP'', ''MHIMRP'', ''13'', ''ITAX1B'', ''ITAX3B'',''ITAX5B'', ''ITAX6B'', ''ITAX7B'', ''BTIMRP'', ''BTI5RP'', ''BTI6RP'', ''BTI7RP'')
and t.service_code = ''00'' and substr(t.orig_called_num,1,'||lv_length||')='||''''||dummy||'''';
execute immediate sqlstr;
commit;
end if ;
if(rec_count2>0) then
sqlstr :='insert into y_summary(BILL_DATE ,PREFIX, TRUNK_MGR,OUTCALLS , OUTDUR , IDD_FLAG , PK_FLAG )
select '|| month_val||' ,substr(t.orig_called_num,1,'||lv_length||'),t.trunkout_operator ,count(*) , round(sum(ceil(t.duration / 15) * 15) / 60, 0),''00'',''0'' from y_table_data1 t where t.fee_dur_1_2 <> 0
and t.out_trunk in (''MHISRM'', ''GEISRM'', ''GEIMRP'', ''MHIMRP'', ''13'', ''ITAX1B'', ''ITAX3B'',''ITAX5B'', ''ITAX6B'', ''ITAX7B'', ''BTIMRP'', ''BTI5RP'', ''BTI6RP'', ''BTI7RP'')
and t.service_code = ''00'' group by t.trunkout_operator,substr(t.orig_called_num,1,'||lv_length||')';
execute immediate sqlstr;
commit;
sqlstr :='DELETE from y_table_data1 t where t.fee_dur_1_2 <> 0
and t.out_trunk in (''MHISRM'', ''GEISRM'', ''GEIMRP'', ''MHIMRP'', ''13'', ''ITAX1B'', ''ITAX3B'',''ITAX5B'', ''ITAX6B'', ''ITAX7B'', ''BTIMRP'', ''BTI5RP'', ''BTI6RP'', ''BTI7RP'')
and t.service_code = ''00'' and substr(t.orig_called_num,1,'||lv_length||')='||''''||dummy||'''';
execute immediate sqlstr;
commit;
end if;
if(rec_count3>0) then
sqlstr :='insert into y_summary(BILL_DATE ,PREFIX, TRUNK_MGR,OUTCALLS , OUTDUR , IDD_FLAG , PK_FLAG )
select '|| month_val||',substr(t.orig_called_num,1,'||lv_length||'),t.trunkout_operator ,count(*) , round(sum(ceil(t.duration / 15) * 15) / 60, 0),''012'',''0'' from y_table_data1 t where t.fee_dur_1_1 <> 0
and t.out_trunk in (''MHISRM'', ''GEISRM'', ''GEIMRP'', ''MHIMRP'', ''13'', ''ITAX1B'', ''ITAX3B'',''ITAX5B'', ''ITAX6B'', ''ITAX7B'', ''BTIMRP'', ''BTI5RP'', ''BTI6RP'', ''BTI7RP'')
and t.service_code = ''012'' group by t.trunkout_operator,substr(t.orig_called_num,1,'||lv_length||')';
execute immediate sqlstr;
commit;
sqlstr :='DELETE from y_table_data1 t where t.fee_dur_1_1 <> 0
and t.out_trunk in (''MHISRM'', ''GEISRM'', ''GEIMRP'', ''MHIMRP'', ''13'', ''ITAX1B'', ''ITAX3B'',''ITAX5B'', ''ITAX6B'', ''ITAX7B'', ''BTIMRP'', ''BTI5RP'', ''BTI6RP'', ''BTI7RP'')
and t.service_code = ''012'' and substr(t.orig_called_num,1,'||lv_length||')='||''''||dummy||'''';
execute immediate sqlstr;
commit;
end if;
end loop;
close explicit_cur;
end explicit2;
Edited by: user10951541 on 25.4.2010 12.08Dear concern
Really sorry not to make format listing because i am amature to this blog.
my anwser to your way .
1. I have Tested my SQL statements manually in SQL*Plus. this runs ok
2. "Cursor loops, such as the one you have coded here, have been obsolete in Oracle since version 8i 12+ years ago.
Look up BULK COLLECT and FORALL in the docs and use them instead."
I am trying to make use of the BULK COLLECT and FORALL statement in proper location.
3. "Your procedure never performs a commit so no work actually takes place" i need to get the anwser why........................?
4. "On what basis was the decision made to use the default PCTFREE and PCTUSED values of 10 and 40?"
is there any problem if default is used..? if any suggestion........pls
5." You did not format your listing using the CODE tags as explained in the FAQ making your listing unreadable ... so I've not read it.
Please read the FAQ and use the proper way to post code so we can understand it. Then perhaps we can help you further. " really sorry not to make understandable to you..? but i will try from next post..
I really will try to be synced..
My aim is to make query to Table A using the cursor value like( '4422','442','4411','441','44') and get some data in accordance of these values.Then i put the data into another Table B. same time i need to delete the record from Table A containing the prefix value in accordance for example- i compute value for '4422' from Table A and put the computed value to Table B .Then i delete the record from Table A where prefix is '4422' .so that computed value for the next prefix '442' should contain the computed value for 442[0-1] and 442[3-9] .Same way it will be happened for ('4411','441','44'....bla...bla).
Thanks in advance.. -
Dear All,
In one of the standard program the following code is used
FETCH NEXT CURSOR c_handle-db_cursor
INTO CORRESPONDING FIELDS OF l_s_ce0_enh.
Here the problem is sometimes at this line program getting timed out and gives dump as time limit exceeded.l_s_ce0_enh is workarea.
Please let me know the solution for this.
Regards
ShobanIn 10g,
FOR r IN c LOOPis optimized by the compiler into a bulk-fetch operation, whereas
OPEN c;
LOOP
FETCH c INTO r;
EXIT WHEN c%NOTFOUND;
etc...is not.
If your analysis shows that fetching from the cursor is where most of the time goes, it's possible the query itself needs optimising. Or it could be that it just has a lot of rows to work on and it's performing the best it can.
However, the whole cursor loop approach is inherently slower than a single SQL statement, so depending on what processing you need to perform inside the loop it may be possible to replace the whole thing with one INSERT or MERGE etc. Or as others have suggested you might explicitly bulk collect a couple of hundred rows at a time into a collection, and apply your INSERT/UPDATE/DELETE etc processing in FORALL statements using the collection. -
Alternative for Open , Fetch cursor command
Hi Experts,
I am populating data from glpca table using Open Cursor statement with hold as shown below:
OPEN CURSOR WITH HOLD cur1 FOR
Select data from the purchase order header table.
SELECT runit rprctr sprctr
racct rfarea hsl msl kostl aufnr ps_psp_pnr
FROM glpca
WHERE docnr IN s_docnr
AND rbukrs = p_rbukrs
AND rprctr IN s_rprctr
AND sprctr IN s_sprctr
AND rfarea IN s_rfarea
AND budat IN s_budat
AND kostl IN s_kostl
AND aufnr IN s_aufnr.
Now when i try to Fetch the cursor even restricting it with PACKAGE SIZE command ( value 998), my program get struck over here for 20-30 mins or more den that & session gets out for the user at client end coz of large data. I checked the value of cursor , it was around 670-700 approx.
The query is shown below:
DO.
fetch rows from cursor depending on package size
FETCH NEXT CURSOR cur1 INTO TABLE t_glpca
PACKAGE SIZE p_size.
IF sy-subrc NE 0.
CLOSE CURSOR cur1.
EXIT.
ENDIF.
The program get struck at above fetch next cursor command.
Kindly suggest me some other way to handle or populate the data or any alternative for Cursor command.
Thanks for your consideration.
Regards
MuditSiegfried Boes wrote:
> there is a reason why OPEN CURSOR WITH HOLD is usually used.
>
> Siegfried
Sorry for hijacking this thread and asking here. I am here in the forums on daily basis just reading and learning.
This got me curious and I googled and read SAP tutorial about cursors:
http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb3b23358411d1829f0000e829fbfe/content.htm
also read an answer from Thomas after searching forum:
The combination with OPEN CURSOR ... WITH HOLD allows package processing of tasks that require a database commit inside the loop. A normal SELECT loop without holding the cursor would be interrupted by a commit -> short dump.
MY TWO QUESTIONs
1. In SAP tutorial it states that
"WITH HOLD addition in the OPEN CURSOR statement allows you to prevent a cursor from being closed when a database commit occurs in Native SQL"
If I don't specify any commit statements in my abap code and user cursor without the addition with hold.
Can a commit be executed anyway and I get an unwanted commit and thus an unwanted close of my cursor?
Or do they mean that "if you specify commit in native sql"?
2. Thomas says a normal select loop without the cursor holding would be interrupted. Interrupted by who? Again, it seems like there is an "unwanted" commit here? Again, can there be any commits and unwanted interrupts if I dont specify it somewhere in my code?
regards
Baran
Edited by: Baran Sölen on Feb 25, 2009 11:39 AM -
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?
-
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 -
Can I use a cursor to display multipla records (just as an EXECUTE_QUERY)?
is it possible?
so I can display about 10 records at the same time in a block (in forms)
just like a tabular form?
using a cursor, fetch, etc.what I want is this...
do you see when in a tabular forms (multiple records, i.e 5 records at the same time).
if you press F8 (execute query), it will fetch all records.
ok, now instead of using the execute_query key, how can I get the same thing by using cursors? -
is there a way to use x11 cursors, such as found on http://www.kde-look.org/content/show.php?content=5533, on osx? thanks.
These are the variables and pseudo code:
declare
tcode varchar2(4);
--tcode1 varchar2(4);
vno varchar2(9);
--v1no varchar2(9);
recno varchar2(3);
--recno1 varchar2(3);
srcmjcd varchar2(4);
--srcmjcd1 varchar2(4);
--vdate date;
pnplan char(1);
--pnplan1 char(1);
vcharged char(1);
--vcharged1 char(1);
ddocode varchar2(4);
--ddocode1 varchar2(4);
grantno number(4);
--grantno1 number(4);
grossamt number(16,2):=0;
--grossamt1 number(16,2):=0;
fs char(1);
rttype char(3);
dday number(2):=0;
mjcd varchar(4);
Rank number:=0;
vno_p varchar2(9);
--v2no_p varchar2(9);
sno number:=1;
vdate date;
--vdate1 date;
vno1 varchar2(9);
hcode varchar2(4);
--h_code varchar2(4);
hcode1 varchar2(9);
hcode2 varchar2(2);
hcode3 varchar2(2);
hcode4 varchar2(2);
FILE1 text_io.FILE_TYPE;
file2 text_io.file_type;
cursor1;
cursor2;
begin
open cursor1;
openfiles
loop
fetch cursor1 into tcode,recno,srcmjcd,vno,vdate,pnplan,vcharged,ddocode,grantno,grossamt;
text_io.PUT_LINE();
exit when cursor1%NOTFOUND;
--message(sno);
end loop;
text_io.fclose(file1);
open cursor2;
loop
fetch cursor2 into
tcode1,recno1,h_code,srcmjcd1,v1no,v2no_p,vdate1,
pnplan1,vcharged1,ddocode1,grantno1,grossamt1;
exit when cursor2%NOTFOUND;
text_io.PUT_LINE();
end loop;
text_io.FCLOSE(FILE2);
forms_ddl('commit');
message('Query Processed');
close cursor1;
close cursor2;
end;Message was edited by:
user588306
Maybe you are looking for
-
This picture says it all: It keeps saying "could not be synced because the connection was lost" which sometimes happened when doing a Wi-Fi sync, but this is a wired sync!
-
Hi, I am trying to get query list based on last used date. I ran query on stat cube 0BWTC_... Also, i got list of queries from the view v_compdir_compic in bw backend. But the query list i get from stat cube query is less than what i get from View ta
-
Problems with Edge Animate and back button ios and firefox
I've put a bit of Edge content in a draft webpage: http://cassidausa.com/indexy ..and am noticing a couple of issues: 1 When viewing in ios, I click through the content (there are links to products within the Edge animation), and then press the back
-
Training Proposal in Qualification Catalog
Hi, What are the settings required for generating Training Proposal when we are performing Profile Matchup?Also please let me know what data should be maintained for this purpose in BEG/BET/BE. With Regards, Kaustuv Goswami.
-
Could we change the marker's size in dvt:lineGraph?
I am using Jdeveloper 11.1, my code is like this: <dvt:lineGraph id="facetcharlineGraph3" shortDesc="chart" subType="LINE_VERT_ABS" ......> <dvt:seriesSet defaultMarkerShape="MS_CIRCLE" defaultAssignedToY2="DY2_FALSE" markerDisplayed="true" lineDispl