Select query on REF CURSOR
Hi all,
I am trying see if we can use LINQ like functionality to query a ref cursor resultset. I have about 50 procedures( as part of 12 packages) which send the ref cursor output to a front end application when called individually. Now I need to create a procedure to get only specified records from each of these 50 ref cursors and output it to another ref curosr.
In other words how can I use the following
select col_2 from pkg_abc.pro_ref_cursor_out(arg1, arg2...) where col_1 = 'X':I am not inclined to use a fetch as I foresee performance issues?
Thanks
@ Tubby. Here is what I am looking to do. Let us say I have two packages as below each with one ref cursor. In reality there are about 15 packages and 50 procedures and hence 50 ref cursors.
CREATE OR REPLACE PACKAGE pkg_1
IS
TYPE resultset_typ IS REF CURSOR;
PROCEDURE pro_1 (
i_region IN VARCHAR2,
o_resultset OUT resultset_typ, -- 'recordset' output
END pkg_1;
CREATE OR REPLACE PACKAGE BODY pkg_1
IS
PROCEDURE pro_1 (
i_region IN VARCHAR2,
o_resultset OUT resultset_typ,
IS
BEGIN
OPEN o_resultset FOR
SELECT 'employees' AS person_type, employee_name FROM tbl_employees WHERE region = i_region;
END;
END pro_1;
END pkg_1;
CREATE OR REPLACE PACKAGE pkg_2
IS
TYPE resultset_typ IS REF CURSOR;
PROCEDURE pro_2 (
i_region IN VARCHAR2,
o_resultset OUT resultset_typ, -- 'recordset' output
END pkg_2;
CREATE OR REPLACE PACKAGE BODY pkg_2
IS
PROCEDURE pro_2 (
i_region IN VARCHAR2,
o_resultset OUT resultset_typ,
IS
BEGIN
OPEN o_resultset FOR
SELECT 'customers' AS person_type, customer_name FROM tbl_customers WHERE region = i_region;
END;
END pro_2;
END pkg_2;Currenlty the front end app calls these packages individually when required. But I want to create an additional package as follows so that I dont have to write the underlying queries again.
CREATE OR REPLACE PACKAGE pkg_3
IS
TYPE resultset_typ IS REF CURSOR;
PROCEDURE pro_3 (
i_region IN VARCHAR2,
i_name IN VARCHAR2,
o_resultset OUT resultset_typ, -- 'recordset' output
END pkg_3;
CREATE OR REPLACE PACKAGE BODY pkg_3
IS
PROCEDURE pro_3 (
i_region IN VARCHAR2,
i_name IN VARCHAR2,
o_resultset OUT resultset_typ,
IS
BEGIN
OPEN o_resultset FOR
SELECT * FROM pkg_1.pro_1(i_region) WHERE employee_name = i_name
UNION ALL
SELECT * FROM pkg_2.pro_2(i_region) WHERE customer_name = i_name
END;
END pro_3;
END pkg_3;
Similar Messages
-
Link Query and Ref Cursor Query
Hi all!!
How can I link Query and Ref Cursor Query??
I mean, How can I pass input parameters to the PL/SQL procedure if they are not User parameters but they come from another table??
Thanks a lot
F.I have searched the forum and this is the closest to my problem.
Just started using ref cursors in my reports.
The problem I am running into is that I have two ref cursor queries in my report - they each contain a column named seq_no which forms a join (in the database) .
My report returns the correct number of records in each query, but I can't find a way to enforce the join. I've tried all the methods I can think of including combining the results into one query.
The IDE won't let me join on a column and when I join on the group (which I make only contain the seq_no fields) that join is ignored.
Can anyone help me on this? -
I use ref cursor in function parameter "OUT"
On prodecedure call this function and execute loop on cursor. Is possible?
This error ora-22905
This example.
FUNCTION f1(p_cursor OUT curtyp
p_value IN number) return varchar2 is
begin
open p_cusor for select c1, c2, (c1+c2) c3, (c1/2) from table t1, table2 t2 where c5=p_value;
return 'SUCESS!';
exception
when no_data_found then
return 'ERROR!'.
end;
procedure test(p_value in number) is
v_cursor curtyp;
begin
vmsg := f1(v_cursor,p_value);
for cs in (select * from table(v_cursor)) loop
end loop;
end;
Thanks!I do not use fetch to not declare variables and minimize lines. If it were to declare a table type record, which would change the type every time you add a new field in the sql. Ja cursor type in the problem does not exist. but decided that using the fetch and through the cusor without the use of "is".
Solution:
v_menserro:= sisarr.pk_parcelamento2009.debitos_da_pessoa(v_resultado
,p_seq_debito
,null
,null
,null
,null);
if nvl(v_menserro,'nulo')<> 'nulo' then
return v_menserro;
end if;
loop
FETCH v_resultado INTO v_situacao, v_tip_pessoa, v_cod_uf, v_nom_municipio, v_sig_uf,
v_num_cpf_cnpj, v_num_cpf_cnpj_formatado , v_seq_debito, v_sig_unidade_ibama, v_des_debito,
v_sig_tipo_debito, v_cod_tipo_debito, v_dat_vencimento, v_sig_moeda_br, v_val_original,
v_val_saldo_real, v_num_processo;
if v_situacao = 'REPARCELAR' then
return 'Já existe um parcelamento prévio para o débito.';
end if;
end loop;
Even if it is a bad practice, need to read several cursor in the function above
Thanks
Julio
Edited by: JulioN64 on 06/07/2009 12:44 -
Dynamic query with ref cursors
please help me out there.
can you give an example of how to construct a procedure using ref cursors.
say if I had an employee table.
employee table
first name
last name
position
dept
I would have three input parameters, last name, position, dept. Sometimes only one parameters would be passed. Sometimes only two or sometimes all three.
How can I construct the procedure being that the parameters will be dynamic
thanks.Don't worry user484105 I don't do kicking, sarcasm and bad humour are other matters though.
Yes you can use sys_refcursor, in fact all the tests that Todd and I have supplied, have done just that. Do you have a development database to work in?
if so I would recommend
1. Run demobld.sql if you don't already have emp table.
2. Copy my second post in your other thread.
3. Edit out all the sqlplus output and the first four columns.
4. If any of this puzzles you see if you can find the answer in the SQL Reference, PL/SQL Guide or SQL*Plus manuals
http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14200/toc.htm
http://download-east.oracle.com/docs/cd/B19306_01/appdev.102/b14261/toc.htm
http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14357/toc.htm
5. If you can't find the answer post what you have and the error here.
6. It is probably best if you use sqlplus for this.
You will learn a lot if you can do this. -
How to optimize the select query that is executed in a cursor for loop?
Hi Friends,
I have executed the code below and clocked the times for every line of the code using DBMS_PROFILER.
CREATE OR REPLACE PROCEDURE TEST
AS
p_file_id NUMBER := 151;
v_shipper_ind ah_item.shipper_ind%TYPE;
v_sales_reserve_ind ah_item.special_sales_reserve_ind%TYPE;
v_location_indicator ah_item.exe_location_ind%TYPE;
CURSOR activity_c
IS
SELECT *
FROM ah_activity_internal
WHERE status_id = 30
AND file_id = p_file_id;
BEGIN
DBMS_PROFILER.start_profiler ('TEST');
FOR rec IN activity_c
LOOP
SELECT DISTINCT shipper_ind, special_sales_reserve_ind, exe_location_ind
INTO v_shipper_ind, v_sales_reserve_ind, v_location_indicator
FROM ah_item --464000 rows in this table
WHERE item_id_edw IN (
SELECT item_id_edw
FROM ah_item_xref --700000 rows in this table
WHERE item_code_cust = rec.item_code_cust
AND facility_num IN (
SELECT facility_code
FROM ah_chain_div_facility --17 rows in this table
WHERE chain_id = ah_internal_data_pkg.get_chain_id (p_file_id)
AND div_id = (SELECT div_id
FROM ah_div --8 rows in this table
WHERE division = rec.division)));
END LOOP;
DBMS_PROFILER.stop_profiler;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
WHEN TOO_MANY_ROWS
THEN
NULL;
END TEST;The SELECT query inside the cursor FOR LOOP took 773 seconds.
I have tried using BULK COLLECT instead of cursor for loop but it did not help.
When I took out the select query separately and executed with a sample value then it gave the results in a flash of second.
All the tables have primary key indexes.
Any ideas what can be done to make this code perform better?
Thanks,
Raj.As suggested I'd try merging the queries into a single SQL. You could also rewrite your IN clauses as JOINs and see if that helps, e.g.
SELECT DISTINCT ai.shipper_ind, ai.special_sales_reserve_ind, ai.exe_location_ind
INTO v_shipper_ind, v_sales_reserve_ind, v_location_indicator
FROM ah_item ai, ah_item_xref aix, ah_chain_div_facility acdf, ah_div ad
WHERE ai.item_id_edw = aix.item_id_edw
AND aix.item_code_cust = rec.item_code_cust
AND aix.facility_num = acdf.facility_code
AND acdf.chain_id = ah_internal_data_pkg.get_chain_id (p_file_id)
AND acdf.div_id = ad.div_id
AND ad.division = rec.division;ALSO: You are calling ah_internal_data_pkg.get_chain_id (p_file_id) every time. Why not do it outside the loop and just use a variable in the inner query? That will prevent context switching and improve speed.
Edited by: Dave Hemming on Dec 3, 2008 9:34 AM -
Will REF CURSOR support for Oracle Forms 6i?
Hi,
I need to use ref cursor in my from. My cursor query should be dynamically append the "where clause". Hence I used the dynamic query with ref cursor.
But my problem is , when I compile the form it gives error for the line " OPEN emp_record FOR l_query;"
You need to use "select" statement.
Is there any solution for this in forms?
I know it supports for other PL/SQL areas.
Please help me. below is my code sample,
DECLARE
TYPE emp_refcur IS REF CURSOR;
emp_record emp_refcur;
TYPE rec_emp_data IS RECORD
emp_no VARCHAR2(40),
emp_rec rec_emp_data;
l_query VARCHAR2(4000);
BEGIN
l_query := 'SELECT empno
FROM emp ';
IF :CONTROL.ename IS NOT NULL THEN
l_query := l_query||' AND ename = '''||:CONTROL.ename||''' ';
END IF;
OPEN emp_record FOR l_query;
LOOP
FETCH emp_record INTO emp_rec;
EXIT WHEN emp_record%NOTFOUND;
dbms_output.put_line(emp_rec.emp_no);
END LOOP;
CLOSE emp_record;
END; Thanks
RajeshHi,
It's been a while since I used Forms 6i, but I remember hitting a similar problem. I don't think (and stress think!) that the PLSQL engine that comes with Forms 6i recognises ref_cursors.
The work-around I used was to move the functionality to the database and call it from forms.
Hope this helps.
Regards
Ian -
Hi,
Is there any way to execute stored procedure via hyperion using ODBC and get back ref cursor data.
I tried to call a stored procedure that have a ref cursor out parameter but it gives me error.
My stored procedure code is below.
wrong number or types of arguments to in call to 'HYP_CURSOR'
create or replace package hyp_ref_cusrsor is
type t_cusror is ref cursor;
end;
create or replace procedure hyp_cursor(ret1 out hyp_ref_cusrsor.t_cusror) is
begin
open ret1 for select * from hyp_tmp1 m;
end;
Hyperion version is 9.3.1
Oracle version is 10.0.2
RegardsGeorge wrote:
Is there a limit to the volume of data a ref cursor can return via an Oracle Database Procedure call? No.
{thread:id=886365}
Re: OPEN cursor for large query
A ref cursor is a pointer to a compiled SQL statement, it has no rows so there is no limit to the number of rows that you can use it to fetch, just like there is no limit to the number of rows a select can return.
I am using a ref cursor to return data and testing using toad, it hangs the session. My Business Object report also hangs because of the large data volume 750,000 rows returned via a ref cursor. This is very confusing, it it hangs how do you know it returns 750,000 rows? -
Dynamic REF Cursor with Dynamic Fetch - Urgent
i have a pl/sql package with generates dynamic SQL statments. my problem is i want to open this SQL statment dynamically and fetch data in dynamic variable.
declare
type type_temp is REF CURSOR;
cur_temp type_temp;
mv_sql varchar2(4000);
begin
-- this will be dunamically generated and
-- hence could have any no. of columns.
mv_sql := select f1, f2, f3, f4 from table_temp;
open cur_temp for mv_sql;
fetch cur_temp into c1, c2, c3, c4;
close cur_temp;
end;
problem is my sql statment will have N no. of columns how can i fetch this N no. of columns.Very hard problem, because ref cursors do not (directly) support description!
Se mine (non-ideal) solution (it may be doable, but it isn't very practical
or easily maintainable):
1. "Generic" package
CREATE OR REPLACE PACKAGE dyn_fetch IS
TYPE ref_cur_t IS REF CURSOR;
g_query VARCHAR2 (32000);
g_count NUMBER;
g_desc_tab DBMS_SQL.DESC_TAB;
varchar2_type CONSTANT PLS_INTEGER := 1;
number_type CONSTANT PLS_INTEGER := 2;
date_type CONSTANT PLS_INTEGER := 12;
rowid_type CONSTANT PLS_INTEGER := 11;
char_type CONSTANT PLS_INTEGER := 96;
long_type CONSTANT PLS_INTEGER := 8;
raw_type CONSTANT PLS_INTEGER := 23;
mlslabel_type CONSTANT PLS_INTEGER := 106;
clob_type CONSTANT PLS_INTEGER := 112;
blob_type CONSTANT PLS_INTEGER := 113;
bfile_type CONSTANT PLS_INTEGER := 114;
PROCEDURE describe_columns;
FUNCTION record_def RETURN VARCHAR2;
END;
CREATE OR REPLACE PACKAGE BODY dyn_fetch IS
PROCEDURE describe_columns IS
l_cur INTEGER;
BEGIN
l_cur := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE (l_cur, g_query, DBMS_SQL.NATIVE);
DBMS_SQL.DESCRIBE_COLUMNS (l_cur, g_count, g_desc_tab);
DBMS_SQL.CLOSE_CURSOR (l_cur);
EXCEPTION
WHEN OTHERS THEN
IF DBMS_SQL.IS_OPEN (l_cur) THEN
DBMS_SQL.CLOSE_CURSOR (l_cur);
END IF;
RAISE;
END;
FUNCTION record_def RETURN VARCHAR2 IS
l_record_def VARCHAR2 (32000);
l_type VARCHAR2 (100);
l_col_type PLS_INTEGER;
l_col_max_len PLS_INTEGER;
l_col_precision PLS_INTEGER;
l_col_scale PLS_INTEGER;
BEGIN
FOR i IN 1..g_count LOOP
l_col_type := g_desc_tab(i).col_type;
l_col_max_len := g_desc_tab(i).col_max_len;
l_col_precision := g_desc_tab(i).col_precision;
l_col_scale := g_desc_tab(i).col_scale;
IF l_col_type = varchar2_type THEN
l_type := 'VARCHAR2(' || l_col_max_len || ')';
ELSIF l_col_type = number_type THEN
l_type := 'NUMBER(' || l_col_precision || ',' || l_col_scale || ')';
ELSIF l_col_type = date_type THEN
l_type := 'DATE';
ELSIF l_col_type = rowid_type THEN
l_type := 'ROWID';
ELSIF l_col_type = char_type THEN
l_type := 'CHAR(' || l_col_max_len || ')';
-- ELSIF l_col_type = ...
-- long_type, raw_type ...
END IF;
l_record_def := l_record_def || ' col_' || i || ' ' || l_type || ',';
END LOOP;
l_record_def := RTRIM (l_record_def, ',');
RETURN l_record_def;
END;
END;
Note that procedure "record_def" creates columns names as col_1 (col_2 ...)
because SELECT clause in your query can be without aliases, for example
"SELECT deptno || dname FROM dept".
2. Your package which returns query nad ref cursor
CREATE OR REPLACE PACKAGE test IS
PROCEDURE set_query (p_query VARCHAR2 := NULL);
FUNCTION ref_cur RETURN dyn_fetch.ref_cur_t;
END;
CREATE OR REPLACE PACKAGE BODY test IS
PROCEDURE set_query (p_query VARCHAR2 := NULL) IS
l_query VARCHAR2 (32000) :=
' SELECT e.empno, e.ename,' ||
' e.deptno, d.dname' ||
' FROM emp e,' ||
' dept d' ||
' WHERE e.deptno = d.deptno';
BEGIN
IF p_query IS NULL THEN
dyn_fetch.g_query := l_query;
ELSE
dyn_fetch.g_query := p_query;
END IF;
END;
FUNCTION ref_cur RETURN dyn_fetch.ref_cur_t IS
l_ref_cur dyn_fetch.ref_cur_t;
BEGIN
OPEN l_ref_cur FOR dyn_fetch.g_query;
RETURN l_ref_cur;
END;
END;
Why we need two separate procedures (functions) in your package ?
a) Receiving program must use dynamic SQL, but in dynamic block we can access
only PL/SQL code elements that have global scope (standalone functions and procedures,
and elements defined in the specification of a package).
Unfortunately, cursor variables cannot be defined in the specification of a package
(cannot be global variables).
b) Receiving program must get the column list before ref cursor.
So, we have two options: call (in receiving program) the same function two times
(once to get the column list and once to return a ref cursor)
or use one procedure (or function) for returning query (to get the column list)
and second function for returning a ref cursor.
3. Your receiving program
CREATE OR REPLACE PROCEDURE test_fetch_ref_cur (p_query VARCHAR2 := NULL) IS
l_statement VARCHAR2 (32000);
FUNCTION process_def RETURN VARCHAR2 IS
l_process_def VARCHAR2 (32000);
BEGIN
l_process_def := 'DBMS_OUTPUT.PUT_LINE (';
FOR i IN 1 .. dyn_fetch.g_count LOOP
l_process_def := l_process_def || ' l_record.col_' || i || ' || ''>>'' || ';
END LOOP;
l_process_def := RTRIM (l_process_def, ' || ''>>'' || ') || ');';
RETURN l_process_def;
END;
BEGIN
test.set_query (p_query);
dyn_fetch.describe_columns;
l_statement :=
' DECLARE' ||
' TYPE record_t IS RECORD (' ||
dyn_fetch.record_def || ');' ||
' l_record record_t;' ||
' l_ref_cur dyn_fetch.ref_cur_t;' ||
' BEGIN' ||
' l_ref_cur := test.ref_cur;' ||
' LOOP' ||
' FETCH l_ref_cur INTO l_record;' ||
' EXIT WHEN l_ref_cur%NOTFOUND;' ||
process_def ||
' END LOOP;' ||
' CLOSE l_ref_cur;' ||
' END;';
EXECUTE IMMEDIATE l_statement;
END;
You can test this with:
SET SERVEROUTPUT ON;
EXECUTE test_fetch_ref_cur;
Note that we can try to use more generic solution:
CREATE OR REPLACE PACKAGE dyn_fetch IS
-- SAME AS BEFORE, PLUS:
PROCEDURE fetch_ref_cur (
p_function_ref_cur VARCHAR2,
p_process_def VARCHAR2);
END;
CREATE OR REPLACE PACKAGE BODY dyn_fetch IS
-- SAME AS BEFORE, PLUS:
PROCEDURE fetch_ref_cur (
p_function_ref_cur VARCHAR2,
p_process_def VARCHAR2)
IS
l_statement VARCHAR2 (32000);
BEGIN
l_statement :=
' DECLARE' ||
' TYPE record_t IS RECORD (' ||
record_def || ');' ||
' l_record record_t;' ||
' l_ref_cur dyn_fetch.ref_cur_t;' ||
' BEGIN' ||
' l_ref_cur := ' ||
p_function_ref_cur || ';' ||
' LOOP' ||
' FETCH l_ref_cur INTO l_record;' ||
' EXIT WHEN l_ref_cur%NOTFOUND;' ||
p_process_def ||
' END LOOP;' ||
' CLOSE l_ref_cur;' ||
' END;';
EXECUTE IMMEDIATE l_statement;
END;
END;
CREATE OR REPLACE PROCEDURE test_fetch_ref_cur (p_query VARCHAR2 := NULL) IS
FUNCTION process_def RETURN VARCHAR2 IS
-- SAME AS BEFORE
END;
BEGIN
test.set_query (p_query);
dyn_fetch.describe_columns;
dyn_fetch.fetch_ref_cur (
p_function_ref_cur => 'test.ref_cur',
p_process_def => process_def);
END;
Regards,
Zlatko Sirotic -
Ref cursor help in Reports/pl sql
Hello , i am new to this , please help!
From oracle forms, we have a table and one of the columns from that table returns rows and the result are like ( select name, messaging_id, listing_id from dynamic_message group_query) ..I am trying to join this table with other tables based on a group type, based on if it returns 'D' or 'S' to other groups in report.
I am getting the following error when I uncomment the open cursor statemnt
PLS-00455: cursor 'TEMP_GRP_REC_REFCUR' cannot be used in dynamic
SQL OPEN statement
This is what i have so faar:
create or replace PACKAGE grp IS
TYPE grp_rec IS RECORD
(listing_id varchar2(16 ),
messaging_id varchar2(16 ),
name varchar2(256 ) ,
group_number Number);
TYPE grp_rec_refcur is REF CURSOR RETURN grp_rec;
function grprefc(P_group_number NUMBER, P_group_type CHAR) return grp_rec_refcur;
END;
CREATE OR REPLACE PACKAGE BODY grp IS
function grprefc(p_group_number Number )
return grp_rec_refcur
IS
temp_grp_rec_refcur grp.grp_rec_refcur;
v_stmt_str VARCHAR2(2000) := NULL;
v_cov_name listing.name%TYPE := NULL;
v_cov_mid listing.messaging_id%TYPE := NULL;
v_cov_lid listing.listing_id%TYPE := NULL;
v_grpnum message_group.group_number%TYPE := NULL;
BEGIN
v_stmt_str:='SELECT dmgq.resolved_query
INTO v_stmt_str
FROM dynamic_message_group_query dmgq
WHERE dmgq.group_number = p_group_number';
OPEN temp_grp_rec_refcur FOR v_stmt_str;
LOOP
FETCH temp_grp_rec_refcur INTO v_cov_lid , v_cov_mid ,v_cov_name, v_grpnum ;
EXIT WHEN temp_grp_rec_refcur %NOTFOUND;
END Loop;
RETURN temp_grp_rec_refcur;
END;
END;
show errors;
if there are any examples done by someone in reoprts or if you can help me solve the above, i would higghly appreciate it .
Thanks and Good Day!Maybe something like my second example "Dynamic Table in the Second Query with Oracle Reports"
- ref cursor or "simple" query Q1, which has a column "group_type", linked to a ref cursor query Q2.
Ref cursor query Q2 - pseudo code for function:
CREATE OR REPLACE PACKAGE BODY grp IS
FUNCTION A_join_B_or_A_join_C_join_D
(p_group_type CHAR(1), p_group_number NUMBER)
RETURN dynamic_refcur
IS
l_refcur dynamic_refcur;
l_stmt_str VARCHAR2(2000) := NULL;
BEGIN
IF p_group_type = 'S' THEN
-- join A and B
OPEN l_refcur FOR
SELECT ...
FROM A, B
WHERE A.x = B.y;
ELSE -- p_group_type = 'D'
SELECT resolved_query
INTO l_stmt_str
FROM dynamic_message_group_query
WHERE group_number = p_group_number;
-- join A, C and D (= dynamically created SELECT)
OPEN l_refcur FOR
'SELECT ...
FROM A, C, (' || l_stmt_str || ') D
WHERE A.x = C.y
AND A.z = D.t';
END IF;
RETURN l_refcur;
END;
END; Regards,
Zlatko -
Is there a limit to the volume of data a ref cursor can return via an Oracle Database Procedure call? I am using a ref cursor to return data and testing using toad, it hangs the session. My Business Object report also hangs because of the large data volume > 750,000 rows returned via a ref cursor.
The database procedure works fine when the number of rows is less than 2,000.
Has anyone had this problem before?
Many Thanks,
GeorgieGeorge wrote:
Is there a limit to the volume of data a ref cursor can return via an Oracle Database Procedure call? No.
{thread:id=886365}
Re: OPEN cursor for large query
A ref cursor is a pointer to a compiled SQL statement, it has no rows so there is no limit to the number of rows that you can use it to fetch, just like there is no limit to the number of rows a select can return.
I am using a ref cursor to return data and testing using toad, it hangs the session. My Business Object report also hangs because of the large data volume 750,000 rows returned via a ref cursor. This is very confusing, it it hangs how do you know it returns 750,000 rows? -
Need help in optimisation for a select query on a large table
Hi Gurus
Please help in optimising the code. It takes 1 hr for 3-4000 records. Its very slow.
My Select is reading from a table which contains 10 Million records.
I am writing the select on large table and Retrieving the values from large tables by comparing my table which has 3-4 k records.
I am pasting the code. please help
Data: wa_i_tab1 type tys_tg_1 .
DATA: i_tab TYPE STANDARD TABLE OF tys_tg_1.
Data : wa_result_pkg type tys_tg_1,
wa_result_pkg1 type tys_tg_1.
SELECT /BIC/ZSETLRUN AGREEMENT /BIC/ZREB_SDAT /BIC/ZLITEM1 from
/BIC/PZREB_SDAT *******************THIS TABLE CONTAINS 10 MILLION RECORDS
into CORRESPONDING FIELDS OF table i_tab
FOR ALL ENTRIES IN RESULT_PACKAGE***************CONTAINS 3000-4000 RECORDS
where
/bic/ZREB_SDAT = RESULT_PACKAGE-/BIC/ZREB_SDAT
AND
AGREEMENT = RESULT_PACKAGE-AGREEMENT
AND /BIC/ZLITEM1 = RESULT_PACKAGE-/BIC/ZLITEM1.
sort RESULT_PACKAGE by AGREEMENT /BIC/ZREB_SDAT /BIC/ZLITEM1.
sort i_tab by AGREEMENT /BIC/ZREB_SDAT /BIC/ZLITEM1.
loop at RESULT_PACKAGE into wa_result_pkg.
read TABLE i_tab INTO wa_i_tab1 with key
/BIC/ZREB_SDAT =
wa_result_pkg-/BIC/ZREB_SDAT
AGREEMENT = wa_result_pkg-AGREEMENT
/BIC/ZLITEM1 = wa_result_pkg-/BIC/ZLITEM1.
IF SY-SUBRC = 0.
move wa_i_tab1-/BIC/ZSETLRUN to
wa_result_pkg-/BIC/ZSETLRUN.
wa_result_pkg1-/BIC/ZSETLRUN = wa_result_pkg-/BIC/ZSETLRUN.
modify RESULT_PACKAGE from wa_result_pkg1
TRANSPORTING /BIC/ZSETLRUN.
ENDIF.
CLEAR: wa_i_tab1,wa_result_pkg1,wa_result_pkg.
endloop.Hi,
1) RESULT_PACKAGE internal table contains any duplicate records or not bassed on the where condotion like below
2) Remove the into CORRESPONDING FIELDS OF table instead of that into table use.
refer the below code is
RESULT_PACKAGE1[] = RESULT_PACKAGE[].
sort RESULT_PACKAGE1 by /BIC/ZREB_SDAT AGREEMENT /BIC/ZLITEM1.
delete adjustant duplicate form RESULT_PACKAGE1 comparing /BIC/ZREB_SDAT AGREEMENT /BIC/ZLITEM1.
SELECT /BIC/ZSETLRUN AGREEMENT /BIC/ZREB_SDAT /BIC/ZLITEM1
from /BIC/PZREB_SDAT
into table i_tab
FOR ALL ENTRIES IN RESULT_PACKAGE1
where
/bic/ZREB_SDAT = RESULT_PACKAGE1-/BIC/ZREB_SDAT
AND
AGREEMENT = RESULT_PACKAGE1-AGREEMENT
AND /BIC/ZLITEM1 = RESULT_PACKAGE1-/BIC/ZLITEM1.
and one more thing your getting 10 million records so use package size in you select query.
Refer the following link also For All Entry for 1 Million Records
Regards,
Dhina..
Edited by: Dhina DMD on Sep 15, 2011 7:17 AM -
Spliting SDO_JOIN in two ref cursors
Hi,
What is the best/most efficient way to return two ref cursor using a SDO_JOIN?
In other words, from this example taken from the Oracle Spatial User Guide
SELECT a.gid, b.gid FROM parks a, highways b,
TABLE(SDO_JOIN('PARKS', 'SHAPE', 'HIGHWAYS', 'SHAPE',
'mask=ANYINTERACT')) c
WHERE c.rowid1 = a.rowid AND c.rowid2 = b.rowid;
I would like to have a procedure that split the result of the above Select in two ref cursors. Something like this:
PROCEDURE "GET_PARKS_HIGHWAYS"
"P_PARKS" OUT SYS_REFCURSOR,
"P_HIGHWAYS" OUT SYS_REFCURSOR
as
BEGIN
/* Here I want every Parks that interact a highway
OPEN P_PARKS FOR
SELECT * FROM PARKS WHERE ....
/* Here I want every highway that interact a park
OPEN P_HIGHWAYS FOR
SELECT * FROM HIGHWAYS WHERE ....
END
Can I do this with a single SDO_JOIN or do I have to put one in the where clause of each select?
Hope that somebody understand! If not, let me know, I will try to be clearer.
Thanks
Frederic GouletHi Frederic,
You will get the complete set of answers for both questions when using the anyinteract mask, i.e. you will have in your result set:
All of the parks that interact with highways, and all of the highways that interact with parks.
If you want, you can order by a.gid, and for each park you would see all of the highways.
If you order by b.gid, for each highway you would see all the parks.
The result set is complete in both cases.
Hope this helps. -
Restrictions while using ref cursor inside an xmltype
Hi,
Looks like that getclobVal() can't be used in select where select statement is ref cursor for xmltype.
example
SQL> select xmltype(cursor(select xmltype('<a>1</a>').getclobval() from dual)) from dual;
select xmltype(cursor(select xmltype('<a>1</a>').getclobval() from dual)) from dual
ERROR at line 1:
ORA-03001: unimplemented feature
ORA-22806: not an object or REF also doesn't work the following select
SQL> select xmltype(cursor(select xmltype('<a>'||lpad('a',1,'a')||'</a>') from dual)) from dual;
ERROR:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00234: namespace prefix
"XMLTYPE_x0028__x0027__x003C_A_x003E__x0027__x007C__x007C_LPAD_x0028_" is not
declared
Error at line 4
ORA-06512: at "SYS.XMLTYPE", line 334
ORA-06512: at line 1DB version 10.2.0.1
Ants
Message was edited by:
Ants HindpereI'm not sure if it is about datatypes per se. Looks to more of a restriction of the XMLTYPE object itself:
SQL> select cursor (select xmltype ('<A>1</A>').getclobval () a from dual) from dual
select cursor (select xmltype ('<A>1</A>').getclobval () a from dual) from dual
Error at line 0
ORA-03001: unimplemented feature
ORA-22806: not an object or REF
but astonishingly
SQL> select cursor (select xmlelement(A, 1).getclobval () a from dual) from dual
Cursor (A)
<A>1</A> -
Is Ref Cursor Supported in Froms 10g . If not is there any built-ins
Hi Experts,
I need to use ref cursor in my from 10g. My cursor query should be dynamically append the "where clause column name". Hence I used the dynamic query with ref cursor.
But my problem is , when I compile the form it gives error "this feature is not supported in clinet-side programs'
Is there any solution for this in forms?
Will "EXEC_SQL" package works.
Is there any alternative other than writing pl/sql refcursor....
Thanks
JanaThere are only strong ref cursors allowed in forms (they are not dynamic). you can use exec_sql in forms, or you can use a record group to do dynamic sql. Third option would be to write a database procedure where you can make use ref cursors.
regards -
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
Maybe you are looking for
-
PL/SQL web service - how to use XML schema to define inputs/outputs?
Hello, let us say I want to publish a PL/SQL web service. The package spec that I want to expose is: CREATE OR REPLACE PACKAGE myWebService AS FUNCTION loadResults( username IN VARCHAR2, password IN VARCHAR2, resultData IN XMLType)
-
Burn to disk plug in installed but it does not appear under Photo, plug ins
I installed my first plug in for a trial, Burn to Disk. I went through install process and at end it said plug in is installed. I then go to Aperture, Photo, edit with plug ins and do not find it. What am I missing? thanks
-
This may be difficult to explain, but I am not seeming to find the exact wording in my searches so I am going to ask here... I have several lines of text boxes at the end of a form, and rather than making it all one big block of text and wrapping tex
-
Plugging my iPod into my computer...
Whenever I plug my iPod into my computer, it freezes up and I have to push the center and menu buttons to reset it before it will unfreeze and my computer will recognize it. The screen lights up when I first plug it in, but everything freezes and it
-
Can anybody tell me the global trust uses in weblogic and how to configure it between domains?