Bulk collect / forall type what collection?
Hi I am trying to speed up the query below using bulk collect / forall:
SELECT h.cust_order_no AS custord, l.shipment_set AS Tess
Info.tlp_out_messaging_hdr h, info.tlp_out_messaging_lin l
WHERE h.message_id = l.message_id
AND h.contract = '12384'
AND l.shipment_set IS NOT NULL
AND h.cust_order_no IS NOT NULL
H.cust_order_no GROUP, l.shipment_set
I would like to get the 2 selected fields above in a new table as quickly as possible, but I'm pretty new to Oracle and I find it hard to sort out the best way to do it. The query below is not working (no doubt there are many issues), but I hope that's sufficiently developed, shows the sort of thing, I am trying to achieve:
DECLARE
TYPE xcustord IS TABLE OF THE info.tlp_out_messaging_hdr.cust_order_no%TYPE;
TYPE xsset IS TABLE OF THE info.tlp_out_messaging_lin.shipment_set%TYPE;
TYPE xarray IS the TABLE OF tp_a1_tab % rowtype INDEX DIRECTORY.
v_xarray xarray;
v_xcustord xcustord;
v_xsset xsset;
CUR CURSOR IS
SELECT h.cust_order_no AS custord, l.shipment_set AS Tess
Info.tlp_out_messaging_hdr h, info.tlp_out_messaging_lin l
WHERE h.message_id = l.message_id
AND h.contract = '1111'
AND l.shipment_set IS NOT NULL
AND h.cust_order_no IS NOT NULL;
BEGIN
Heart OPEN;
LOOP
News FETCH
LOOSE COLLECTION v_xarray LIMIT 10000;
WHEN v_xcustord EXIT. COUNT() = 0;
FORALL I IN 1... v_xarray. COUNTY
INSERT INTO TP_A1_TAB (cust_order_no, shipment_set)
VALUES (v_xarray (i) .cust_order_no, v_xarray (i) .shipment_set);
commit;
END LOOP;
CLOSE cur;
END;
I'm running on Oracle 9i release 2.
Short-term solution may be to a world point of view. Pay once per hour for the slow and complex query execution. Materialize the results in a table (with clues in support of queries on the materialized view).
Good solution - analysis logic and SQL, determine what he does, how he does it and then figure out how this can be improved.
Ripping separate cursors in SQL and PL/SQL code injection to stick together, are a great way to make performance even worse.
Tags: Database
Similar Questions
-
iHi.
Declare cursor c_1 is select col1,col2,col3,col4 from table1 type t_type is table of c_1%rowtype index by binary_integer; v_data t_type; BEGIN OPEN c_1; LOOP FETCH c_1 BULK COLLECT INTO v_data LIMIT 200; EXIT WHEN v_data.COUNT = 0; FORALL i IN v_data.FIRST .. v_data.LAST INSERT INTO xxc_table (col1, col3, col4 ) SELECT v_data (i).col1, v_data (i).col3, v_data (i).col4 FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM xxc_table a WHERE col1=col1 ..... ); --commit; INSERT INTO xxc_table1 (col1, col2, col3, col4 ) SELECT v_data (i).col1, v_data (i).col2, v_data (i).col3, 'Y' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM xxc_table1 a WHERE col1=col1 ..... ); --exit when c_1%notfound; END LOOP; CLOSE c_1; commit; END;
I get 40/28-PLS-00201: identifier 'I' must be declared what the problem in the above code please help me and I have lakhs of data
Thank you
Post edited by: Rajesh123 I changed IDX
Post edited by: Rajesh123 changed t_type c_1 in Fetch
But by using a SET of INSERT to insert into two tables at once in the same query would do the job without any collection of bulk of PL and avoid to query two times too.
for example, as a single INSERT...
SQL > create table table1 as
2. Select 1 as col1, col2 of 1, 1 as col3, 1 as col4 Union double all the
3 select 2,2,2,2 of all the double union
4 Select 3,3,3,3 Union double all the
5 Select 4,4,4,4 of all the double union
6 select 5,5,5,5 of all the double union
7 select 6,6,6,6 of all the double union
8 select 7,7,7,7 of all the double union
9 select 8,8,8,8 of all the double union
10. Select 9,9,9,9 to the Union double all the
11. Select double 10,10,10,10
12.Table created.
SQL > create table xxc_table like
2. Select 1 as col1, col3 2, 3 as col4 Union double all the
3. Select the 3, 4, 5 Union double all the
4. Select the 5, 6, 7 double
5.Table created.
SQL > create table xxc_table1 like
2. Select 3 as col1, col2, col3, 5 4 "n" as col4 Union double all the
3. Select the 6, 7, 8, double "n"
4.Table created.
SQL > insert all
2 when the xt_insert is null then
3 in xxc_table (col1, col3, col4)
4 values (col1, col3, col4)
5 when the xt1_insert is null then
6 in xxc_table1 (col1, col2, col3, col4)
7 values (col1, col2, col3, 'Y')
8. Select t1.col1 t1.col2, t1.col3, t1.col4
9, xt.col1 as xt_insert
10, xt1.col1 as xt1_insert
11 from table1 t1
12 left join external xxc_table xt (t1.col1 = xt.col1)
13 left xt1 xxc_table1 outer join (t1.col1 = xt1.col1)
14.15 rows created.
SQL > select * from xxc_table by 1.
COL1 COL3 COL4
---------- ---------- ----------
1 2 3
2 2 2
3 4 5
4 4 4
5 6 7
6 6 6
7 7 7
8 8 8
9 9 9
10-10-1010 selected lines.
SQL > select * from xxc_table1 by 1.
COL1 COL2 COL3 C
---------- ---------- ---------- -
1 1 1 Y
2 2 2 Y
3 4 5 N
4 4 4 Y
5 5 5 Y
6 7 8 N
7 7 7 Y
8 8 8 Y
9 9 9 Y
10-10-1010 selected lines.
SQL >
-
Hi all
I wrote a program... I have no doubt if I use if condition in FORALL INSERT or BULK COLLECT? I can't go for loop 'for '... Is it possible to INSERT FORALL RECUEILLENT validations in BULK as we do in the loop 'for '...
create or replace
Name of the PROCEDURE AS
CURSOR CUR_name IS
SELECT ancien_nom, NEW_name OF DIRECTORY_LISTING_AUDIT;
TYPE V_OLD_name IS TABLE OF THE DIRECTORY_LISTING_AUDIT. TYPE % Ancien_nom;
Z_V_OLD_name V_OLD_name;
TYPE V_NEW_name IS TABLE OF THE DIRECTORY_LISTING_AUDIT. NEW_name % TYPE;
Z_V_NEW_name V_NEW_name;
BEGIN
CUR_name OPEN;
LOOP
COLLECT the FETCH CUR_name in BULK IN Z_V_OLD_name, Z_V_NEW_name;
IF Z_V_NEW_name <>NULL THEN
Z_V_OLD_name: = Z_V_NEW_name;
Z_V_NEW_name: = NULL;
END IF;
FORALL I IN Z_V_NEW_name. COUNTY
INSERT INTO TEMP_DIREC_AUDIT (ancien_nom, NewName) VALUES (Z_V_OLD_name (I), Z_V_NEW_name (I));
WHEN the OUTPUT CUR_name % NOTFOUND;
END LOOP;
CLOSE CUR_name;
Name of the END;I think it's that it's good isn't?
I assumed that there was a!=
lack of
IF Z_V_NEW_name != NULL THEN Z_V_OLD_name := Z_V_NEW_name ; Z_V_NEW_name := NULL; END IF;
Who knows? I'm just guessing what lack us.
In any case, this is why the original "something like" warning ;)
-
Bulk collect and type returns nothing
Hello
I have the following code:
This code returns PL/SQL procedure successfully completed.declare type view_my_type is table of admuser.my_view%rowtype index by pls_integer; --x admuser.my_view%rowtype; my_array view_my_type; cursor c1 is select * from admuser.my_view; s long; i number := 1; begin s := 'crate table '; open c1; loop fetch c1 bulk collect into my_array limit 1; --s := s ||' decode (tf.fin_dates_id, '||my_array(i).fin_dates_id||', sum(tf.act_work_cost), 0) '; s := my_array(i).fin_dates_id; exit when c1%notfound; end loop; close c1; dbms_output.put_line(s); exception when others then null; end;
but don't show me is not the variable "s".
Can you help me with this?
Thank youThere a quite a number of things not just here.
First of all, allow me to reproduce your situation:SQL> create table my_view 2 as 3 select 'hello' fin_dates_id from dual 4 / Table created. SQL> declare 2 type view_my_type is table of my_view%rowtype index by pls_integer; 3 my_array view_my_type; 4 cursor c1 is 5 select * 6 from my_view; 7 s long; 8 i number := 1; 9 begin 10 s := 'crate table '; 11 open c1; 12 loop 13 fetch c1 bulk collect into my_array limit 1; 14 s := my_array(i).fin_dates_id; 15 exit when c1%notfound; 16 end loop; 17 close c1; 18 dbms_output.put_line(s); 19 exception 20 when others then 21 null; 22 end; 23 / PL/SQL procedure successfully completed.
And I SERVEROUTPUT on. Your exception handler is notoriously wrong. It is said: If something goes wrong, we'll pretend it didn't happen. And that's exactly what happened here: something has gone wrong and you have chosen to not know about it.
We will remove the exception handler to see what went wrong:
SQL> declare 2 type view_my_type is table of my_view%rowtype index by pls_integer; 3 my_array view_my_type; 4 cursor c1 is 5 select * 6 from my_view; 7 s long; 8 i number := 1; 9 begin 10 s := 'crate table '; 11 open c1; 12 loop 13 fetch c1 bulk collect into my_array limit 1; 14 s := my_array(i).fin_dates_id; 15 exit when c1%notfound; 16 end loop; 17 close c1; 18 dbms_output.put_line(s); 19 end; 20 / declare * ERROR at line 1: ORA-01403: no data found ORA-06512: at line 14
A no-data-found, because you are referencing my_array (i), when I is null. Just move the OUTPUT when a line upwards as well as your code runs better:
SQL> declare 2 type view_my_type is table of my_view%rowtype index by pls_integer; 3 my_array view_my_type; 4 cursor c1 is 5 select * 6 from my_view; 7 s long; 8 i number := 1; 9 begin 10 s := 'crate table '; 11 open c1; 12 loop 13 fetch c1 bulk collect into my_array limit 1; 14 exit when c1%notfound; 15 s := my_array(i).fin_dates_id; 16 end loop; 17 close c1; 18 dbms_output.put_line(s); 19 end; 20 / hello PL/SQL procedure successfully completed.
Then next to fix things are:
-do not use the long data type Use a VARCHAR2 or a CLOB.
-' Cashier' should probably be 'create '.
-in bulk, treatment with limit 1. Now you have the worst of both sides: line by line, treatment and slightly more complex syntax
-Variable increment I
-Easier (and thus better) use a loop FORI hope this helps.
Kind regards
Rob. -
On bulk collect forall vs fusion simple statement
I understand that a single DML statement is better that use bulk collect to have all the intermediary undertakes. My only concern is that if I load a large amount of data as a record 100 million records in a 800 million table with foreign keys and indexes and the session is killed, the cancellation may take some time which is not acceptable. Using bulk collect forall with interval of validations is slower than a declaration unique fusion straight, but in the case of dead session, the restore time will be not too bad and a reload of the not yet committed data will be not as bad. For the design of a load of recoverable data which may not be affected as badly, is in bulk collect + for all the right approach?
So if I chunk it upward in 50 lines, the child table must be loaded to its matching when records the parent table loaded and validate them.
... and then create a procedure that takes care of the parent AND child data at the same time.
SQL for DBMS_PARALLEL_EXECUTE would be:
"start load_parent_and_child (: start_id,: end_id); end; »
PS - you don't want to run ECD and DML PARALLEL at the same time...
MK
-
UNION operator with BULK COLLECT for one type of collection
Hi all
I created a table as given below:
create or replace type coltest is table of number;
Here are 3 blocks PL/SQL that populate the data in variables of the above mentioned type of table:
BLOCK 1:
DECLARE
col1 coltest: = coltest (1, 2, 3, 4, 5, 11);
col2 coltest: = coltest (6, 7, 8, 9, 10);
COL3 coltest: = coltest();
BEGIN
SELECT * BULK COLLECT
IN col1
FROM (SELECT *)
TABLE (CAST (coltest AS col1))
UNION ALL
SELECT * FROM TABLE (CAST (col2 AS coltest)));
dbms_output.put_line ('col1');
dbms_output.put_line ('col1.count: ' | col1.) (COUNT);
BECAUSE me in 1... col1. COUNTY
LOOP
dbms_output.put_line (col1 (i));
END LOOP;
END;
OUTPUT:
col1
col1. Count: 5
6
7
8
9
10
BLOCK 2:
DECLARE
col1 coltest: = coltest (1, 2, 3, 4, 5, 11);
col2 coltest: = coltest (6, 7, 8, 9, 10);
COL3 coltest: = coltest();
BEGIN
SELECT * BULK COLLECT
IN col2
FROM (SELECT *)
TABLE (CAST (coltest AS col1))
UNION ALL
SELECT * FROM TABLE (CAST (col2 AS coltest)));
dbms_output.put_line ('col2');
dbms_output.put_line ('col2.count: ' | col2.) (COUNT);
BECAUSE me in 1... col2. COUNTY
LOOP
dbms_output.put_line (col2 (i));
END LOOP;
END;
OUTPUT:
col2
col2. Count: 6
1
2
3
4
5
11
BLOCK 3:
DECLARE
col1 coltest: = coltest (1, 2, 3, 4, 5, 11);
col2 coltest: = coltest (6, 7, 8, 9, 10);
COL3 coltest: = coltest();
BEGIN
SELECT * BULK COLLECT
IN col3
FROM (SELECT *)
TABLE (CAST (coltest AS col1))
UNION ALL
SELECT * FROM TABLE (CAST (col2 AS coltest)));
dbms_output.put_line ('col3');
dbms_output.put_line ('col3.count: ' | col3.) (COUNT);
BECAUSE me in 1... Col3. COUNTY
LOOP
dbms_output.put_line (COL3 (i));
END LOOP;
END;
OUTPUT:
COL3
Col3.Count: 11
1
2
3
4
5
11
6
7
8
9
10
Can someone explain please the output of the BLOCK 1 and 2? Why not in bulk collect in col1 and col2 11 return as County?If I remember correctly, the part INTO the query to initialize the collection in which it will collect the data, and you gather in the collections that you are querying, you end up deleting the data out of this collection until she is interrogated.
Not really, wise trying to collect data in a collection that you are querying.
-
Error using BULK collect with RECORD TYPE
Hello
I wrote a simple procedure to declare a record type & then by a variable of type NESTED table.
I then selects the data using COLLECT in BULK & trying to access it via a LOOP... We get an ERROR.
------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE OR REPLACE PROCEDURE sp_test_bulkcollect
IS
TYPE rec_type () IS RENDERING
emp_id VARCHAR2 (20).
level_id NUMBER
);
TYPE v_rec_type IS TABLE OF THE rec_type;
BEGIN
SELECT employe_id, level_id
LOOSE COLLECTION v_rec_type
OF portfolio_exec_level_mapping
WHERE portfolio_execp_id = 2851852;
FOR indx IN v_rec_type. FIRST... v_rec_type. LAST
LOOP
dbms_output.put_line ('Emp-' | v_rec_type.emp_id (indx) |) » '|| v_rec_type.level_id (indx));
END LOOP;
END;
-----------------------------------------------------------------------------------------------------------------------------------
Here is the ERROR I get...
-Errors of compilation for the PROCEDURE DOMRATBDTESTUSER. SP_TEST_BULKCOLLECT
Error: PLS-00321: expression "V_REC_TYPE" is not appropriate for the left side of an assignment statement
Online: 15
Text: IN portfolio_exec_level_mapping
Error: PL/SQL: ORA-00904: invalid identifier
Online: 16
Text: WHERE portfolio_execp_id = 2851852;
Error: PL/SQL: statement ignored
Line: 14
Text: COLLECT LOOSE v_rec_type
Error: PLS-00302: component 'FIRST' must be declared
Online: 19
Text: LOOP
Error: PL/SQL: statement ignored
Online: 19
Text: LOOP
------------------------------------------------------------------------------------------------
Help PLZ.and with a complete code example:
SQL> CREATE OR REPLACE PROCEDURE sp_test_bulkcollect 2 IS 3 TYPE rec_type IS RECORD ( 4 emp_id VARCHAR2(20), 5 level_id NUMBER 6 ); 7 TYPE v_rec_type IS TABLE OF rec_type; 8 v v_rec_type; 9 BEGIN 10 SELECT empno, sal 11 BULK COLLECT INTO v 12 FROM emp 13 WHERE empno = 7876; 14 FOR indx IN v.FIRST..v.LAST 15 LOOP 16 dbms_output.put_line('Emp -- '||v(indx).emp_id||' '||v(indx).level_id); 17 END LOOP; 18 END; 19 / Procedure created. SQL> SQL> show error No errors. SQL> SQL> begin 2 sp_test_bulkcollect; 3 end; 4 / Emp -- 7876 1100 PL/SQL procedure successfully completed.
-
Bulk collect into the record type
Sorry for the stupid question - I do something really simple wrong here, but can not understand. I want to choose a few rows from a table in a cursor, then in bulk it collect in a folder. I'll possibly extended the record to include additional fields that I will select return of functions, but I can't get this simple test case to run...
PLS-00497 is the main error.
Thanks in advance.create table test ( id number primary key, val varchar2(20), something_else varchar2(20)); insert into test (id, val,something_else) values (1,'test1','else'); insert into test (id, val,something_else) values (2,'test2','else'); insert into test (id, val,something_else) values (3,'test3','else'); insert into test (id, val,something_else) values (4,'test4','else'); commit; SQL> declare 2 cursor test_cur is 3 (select id, val 4 from test); 5 6 type test_rt is record ( 7 id test.id%type, 8 val test.val%type); 9 10 test_rec test_rt; 11 12 begin 13 open test_cur; 14 loop 15 fetch test_cur bulk collect into test_rec limit 10; 16 null; 17 exit when test_rec.count = 0; 18 end loop; 19 close test_cur; 20 end; 21 / fetch test_cur bulk collect into test_rec limit 10; * ERROR at line 15: ORA-06550: line 15, column 38: PLS-00497: cannot mix between single row and multi-row (BULK) in INTO list ORA-06550: line 17, column 21: PLS-00302: component 'COUNT' must be declared ORA-06550: line 17, column 2: PL/SQL: Statement ignored
You must declare an array based on your registration type.
DECLARE CURSOR test_cur IS SELECT id, val FROM test ; type test_rt IS record ( id test.id%type, val test.val%type); type test_rec_arr is table of test_rt index by pls_integer; test_rec test_rec_arr; BEGIN OPEN test_cur; LOOP FETCH test_cur bulk collect INTO test_rec limit 10; NULL; EXIT WHEN test_rec.count = 0; END LOOP; CLOSE test_cur; END; 31 / PL/SQL procedure successfully completed. Elapsed: 00:00:00.06 ME_XE?
Notice that the difference is...
type test_rec_arr is table of test_rt index by pls_integer; test_rec test_rec_arr;
-
DBMS_OUTPUT in BULK COLLECT FORALL
Hello
I'm trying to figure out how I can output using DBMS_OUTPUT. Put_line in a BULK COLLECT / FORALL update?
Example:
SEARCH REF_CURSOR BULK COLLECT INTO l_productid, l_qty
ForAll indx in l_productid.first... l_productid. Last
Aa products update
The value of aa. LastInventorySent = l_qty (indx)
Where aa.productid = l_productid (indx);
DBMS_OUTPUT. Put_line ("ProductID: ' |") l_productid (indx) | "QTY: ' |" l_qty (indx);
Is this possible? If so how I can accomlish this?
Thank you
SFETCH REF_CURSOR BULK COLLECT INTO l_productid,l_qty forall indx in l_productid.first..l_productid.last Update products aa Set aa.LastInventorySent = l_qty(indx) Where aa.productid = l_productid(indx); for indx in 1..l_qty.count loop DBMS_OUTPUT.PUT_LINE('ProductID: ' || l_productid(indx)|| ' QTY: ' || l_qty(indx); end loop;
SY.
-
Problem with BULK collect and variable of Table type
Hi all
I defined a record type and then set an index - by table of this record type and in bulk has collected the data as shown in the code below. All this was done in an anonymous block.
Then when I tried to set the record as an object type and not the above activities type, I got the below error:
ORA-06550: line 34, column 6:
PL/SQL: ORA-00947: not enough values
ORA-06550: line 31, column 4:
PL/SQL: SQL statement ignored
Could you help me get the result of the first scenario with record type defined as an object?
Here's the code for num_char_object_1/* Formatted on 2009/08/03 17:01 (Formatter Plus v4.8.8) */ DECLARE TYPE obj_attrib IS TABLE OF num_char_object_1 INDEX BY PLS_INTEGER; obj_var obj_attrib; TYPE num_char_record IS RECORD ( char_attrib VARCHAR2 (100), num_attrib NUMBER ); TYPE rec_attrib IS TABLE OF num_char_record INDEX BY PLS_INTEGER; rec_var rec_attrib; BEGIN SELECT first_name, employee_id BULK COLLECT INTO rec_var FROM employees WHERE ROWNUM <= 10; FOR iloop IN rec_var.FIRST .. rec_var.LAST LOOP DBMS_OUTPUT.put_line ( 'Loop.' || iloop || rec_var (iloop).char_attrib || '###' || rec_var (iloop).num_attrib ); END LOOP; SELECT first_name, employee_id BULK COLLECT INTO obj_var FROM employees WHERE ROWNUM <= 10; END;
CREATE OR REPLACE TYPE NUM_CHAR_OBJECt_1 IS OBJECT ( char_attrib VARCHAR2 (100), num_attrib NUMBER );
Welcome to the forum!
You should be collecting objects in bulk, something like
SELECT NUM_CHAR_OBJECt_1 (first_name, employee_id) BULK COLLECT INTO obj_var FROM emp WHERE ROWNUM <= 10;
-
Hello Experts,
Please review the below excerpt as it errors with a PLS-00103: Encoountered synbol «END».
IF v_geospatial_coordinate_type = "None".
THEN
P_cursor OPEN;
LOOP
SEARCH p_cursor
LOOSE COLLECTION v_search_results_basic LIMIT 100;
BECAUSE me in 1.v_search_results_basic.count
WHEN the OUTPUT v_search_results_basic.count < 100;
END LOOP;
CLOSE P_cursor;
Thanks for the help and of course your professionalism.you missed "LOOP".
IF v_geospatial_coordinate_type = 'None' THEN OPEN p_cursor; LOOP FETCH p_cursor BULK COLLECT INTO v_search_results_basic LIMIT 100; FOR I in 1..v_search_results_basic.count LOOP --<--- EXIT WHEN v_search_results_basic.count < 100; END LOOP; CLOSE p_cursor;
-
Hi all
I want to know if using bulk collect into limit will help to avoid the TEMP tablespace error run out.
We use Oracle 11 g R1.
I am assigned to a task of creating journal facilitated for all tables in a query of the APEX.
I create procedures to execute some sql statements to create a DEC (Create table select), and then fires on these tables.
We have about three tables with more than 26 million records.
It seems very well running until we reached a table with more than 15 million record, we got an error says that Miss tablespace TEMP.
I googled on this topic and retrieve the tips:
Use NO LOG
Parallel use
BULK COLLECT INTO limited
However, the questions for those above usually short-term memory rather than running out of TEMPORARY tablespace.
I'm just a junior developer and does not have dealed with table more than 10 million documents at a time like this before.
The database support is outsourced. If we try to keep it as minimal contact with the DBA as possible. My Manager asked me to find a solution without asking the administrator to extend the TEMP tablespace.
I wrote a few BULK COLLECT INTO to insert about 300,000 like once on the development environment. It seems.
But the code works only against a 000 4000 table of records. I am trying to add more data into the Test table, but yet again, we lack the tablespace on DEV (this time, it's a step a TEMP data)
I'll give it a go against the table of 26 million records on the Production of this weekend. I just want to know if it is worth trying.
Thanks for reading this.
Ann
I really need check that you did not have the sizes of huge line (like several K by rank), they are not too bad at all, which is good!
A good rule of thumb to maximize the amount of limit clause, is to see how much memory you can afford to consume in the PGA (to avoid the number of calls to the extraction and forall section and therefore the context switches) and adjust the limit to be as close to that amount as possible.
Use the routines below to check at what threshold value would be better suited for your system because it depends on your memory allocation and CPU consumption. Flexibility, based on your limits of PGA, as lines of length vary, but this method will get a good order of magnitude.
CREATE OR REPLACE PROCEDURE show_pga_memory (context_in IN VARCHAR2 DEFAULT NULL)
IS
l_memory NUMBER;
BEGIN
SELECT st. VALUE
IN l_memory
SYS.v_$ session se, SYS.v_$ sesstat st, SYS.v_$ statname nm
WHERE se.audsid = USERENV ('SESSIONID')
AND st.statistic # nm.statistic = #.
AND themselves. SID = st. SID
AND nm.NAME = 'pga session in memory. "
Dbms_output.put_line (CASE
WHEN context_in IS NULL
THEN NULL
ELSE context_in | ' - '
END
|| 'Used in the session PGA memory ='
|| To_char (l_memory)
);
END show_pga_memory;
DECLARE
PROCEDURE fetch_all_rows (limit_in IN PLS_INTEGER)
IS
CURSOR source_cur
IS
SELECT *.
FROM YOUR_TABLE;
TYPE source_aat IS TABLE OF source_cur % ROWTYPE
INDEX BY PLS_INTEGER;
l_source source_aat;
l_start PLS_INTEGER;
l_end PLS_INTEGER;
BEGIN
DBMS_SESSION.free_unused_user_memory;
show_pga_memory (limit_in |) "- BEFORE"); "."
l_start: = DBMS_UTILITY.get_cpu_time;
OPEN source_cur.
LOOP
EXTRACTION source_cur
LOOSE COLLECTION l_source LIMITED limit_in;
WHEN l_source EXIT. COUNT = 0;
END LOOP;
CLOSE Source_cur;
l_end: = DBMS_UTILITY.get_cpu_time;
Dbms_output.put_line (' elapsed time CPU for limit of ')
|| limit_in
|| ' = '
|| To_char (l_end - l_start)
);
show_pga_memory (limit_in |) "- AFTER");
END fetch_all_rows;
BEGIN
fetch_all_rows (20000);
fetch_all_rows (40000);
fetch_all_rows (60000);
fetch_all_rows (80000);
fetch_all_rows (100000);
fetch_all_rows (150000);
fetch_all_rows (250000);
-etc.
END;
-
Bulk collect with sequence Nextval
Hello
Oracle Database 10 g Enterprise Edition Release 10.2.0.4.0 - 64 bit
Had a doubt about the collection in bulk with nextval sequence. You need to update a table with a sequence of Nextval.
where should I place select below in the proc is this before or after the loop
< font color = "red" > SELECT prop_id_s.nextval INTO v_prop_id FROM dual; < / make >
Published by: 960736 on January 23, 2013 12:51CREATE OR REPLACE PROCEDURE (state IN varchar2) AS CURSOR get_all IS SELECT /*+ parallel (A, 8) */ A .ROWID from Loads A WHERE A.Prop_id IS NULL; TYPE b_ROWID IS TABLE OF ROWID INDEX BY BINARY_INTEGER; lns_rowid b_ROWID; BEGIN OPEN Get_all; LOOP FETCH get_all BULK COLLECT INTO lns_rowid LIMIT 10000; FORALL I IN 1 .. lns_rowid.COUNT UPDATE loads a SET a.prop_id= v_prop_id (I) WHERE A.ROWID = lns_rowid (I) AND a.prop_id IS NULL; COMMIT; EXIT WHEN get_all%NOTFOUND; END LOOP; CLOSE Get_all; END; /
Hello
It depends on what results you want. All updated rows would take the same value, or should all get unique values?
Whatever it is, you don't need the sliders and loop. Just a simple UPDATE statement.
If each line requires a unique value of the sequence, then
UPDATE loads SET prop_id = prod_id_s.NEXTVAL WHERE prop_id IS NULL ;
If all the lines that have a need to the same value null, then:
SELECT prod_id_s.nextval INTO v_prop_id FROM dual; UPDATE loads SET prop_id = v_prop_id WHERE prop_id IS NULL ;
Don't forget to declare v_prop_id as a NUMBER.
I hope that answers your question.
If not, post a small example of data (instructions CREATE and INSERT, only relevant columns) for all the tables and the involved sequences and also publish outcomes from these data.
If you ask on a DML statement, such as UPDATE, the sample data will be the content of the or the tables before the DML, and the results will be the State of the or the tables changed when it's all over.
Explain, using specific examples, how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum {message identifier: = 9360002} -
Doubt on bulk collect with LIMIT
Hello
I have a doubt on in bulk to collect, when did Commit
I have an example in PSOUG
http://psoug.org/reference/array_processing.html
If my table servers were 3 000 000 files, when do we commit? When I insert all records?CREATE TABLE servers2 AS SELECT * FROM servers WHERE 1=2; DECLARE CURSOR s_cur IS SELECT * FROM servers; TYPE fetch_array IS TABLE OF s_cur%ROWTYPE; s_array fetch_array; BEGIN OPEN s_cur; LOOP FETCH s_cur BULK COLLECT INTO s_array LIMIT 1000; FORALL i IN 1..s_array.COUNT INSERT INTO servers2 VALUES s_array(i); EXIT WHEN s_cur%NOTFOUND; END LOOP; CLOSE s_cur; COMMIT; END;
could crash redo log?
using 9.2.08muttleychess wrote:
If my table servers were 3 000 000 files, when do we commit?Commit point has nothing to do with how many rows treat you. It's purely commercial leads. Your code implements a commercial operation, right? So if you're getting into before any trancaction (from the commercial point of view) other sessions will be already see changes that are (from a business point of view) incomplete. In addition, what happens if rest of trancaction (from the commercial point of view) goes down?
SY.
-
Msg of error taken in bulk collect?
Hello
In bulk below collect part i m having error of date code (i.e. cm_date = 12/12 k 2001 due to the issue of data).
So how can I catch exception msg bulk collect?
Can I use bulk collect as FORALL?
--------------------------------------------------------------------------
BECAUSE me in 1... % BULK_EXCEPTIONS SQL. COUNTY
LOOP
DBMS_OUTPUT. Put_line (' error :'||) SQLERRM (-SQL % BULK_EXCEPTIONS (i).) ERROR_CODE));
END LOOP;
--------------------------------------------------------------------------
looking at the o/p its only "str1" printing and the msg of error ora-01841
----------------------------------------------------------------------------------------------------------------
{
declare
VAR_TYP TYPE IS VARRAY (32767) OF VARCHAR2 (32767).
V_CASL_CM_DATE VAR_TYP;
Start
DBMS_OUTPUT. Put_line ('str 1');
Start
SELECT TO_DATE (casl. CM_DATE, "DD/MM/YYYY")
TO COLLECT FEES IN BULK
IN V_CASL_CM_DATE
The left outer JOIN of the DBMG_CM_A_STL-casl
B CO_CNY on B.CD_CNY_ISO = NVL (casl. Curr_Code, "AED")
WHERE casl. CM_NUMBER = 4203884;
EXCEPTION
WHILE OTHERS THEN
Tr_Ltm_Tnd_Err_Cnt: = Tr_Ltm_Tnd_Err_Cnt + SQL % BULK_EXCEPTIONS. COUNTY;
DBMS_OUTPUT. Put_line (' error: unexpected loading of SAL_DETL to Tr_Ltm_Tnd: ' |) SQLERRM);
BECAUSE me in 1... % BULK_EXCEPTIONS SQL. COUNTY
LOOP
DBMS_OUTPUT. Put_line (' error :'||) SQLERRM (-SQL % BULK_EXCEPTIONS (i).) ERROR_CODE));
END LOOP;
END;
DBMS_OUTPUT. Put_line ('str 2');
BEGIN
FORALL V_CASL_CM_DATE case. FIRST... V_CASL_CM_DATE. FINALLY SAVE THE EXCEPTIONS
INSERT INTO Tr_Ltm_Tnd
VALUES (V_CASL_CM_DATE (case),
);
Tr_Ltm_Tnd_Cnt: = Tr_Ltm_Tnd_Cnt + N_CASL_CM_NUMBER. COUNTY;
EXCEPTION
WHILE OTHERS THEN
Tr_Ltm_Tnd_Err_Cnt: = Tr_Ltm_Tnd_Err_Cnt + SQL % BULK_EXCEPTIONS. COUNTY;
Sqlerm: = SUBSTR (sqlerrm, 1, 200);
DBMS_OUTPUT. Put_line (' error: unexpected loading of SAL_DETL to Tr_Ltm_Tnd: ' |) Sqlerm);
BECAUSE me in 1... % BULK_EXCEPTIONS SQL. COUNTY
LOOP
DBMS_OUTPUT. Put_line (' error :'||) SQLERRM (-SQL % BULK_EXCEPTIONS (i).) ERROR_CODE));
END LOOP;
END;
end;
}
----------------------------------------------------------------------------------------------------------------
Rgds,
PCSame error 10 times?
Depends on what you mean.
You should get an exception recorded for each exception.
The collections are actually reset each outer loop.
Index numbers (i in this case) will be recycled for each loop.
So if the indexed collection value wrong 3 in the first loop, no you wouldn't not see that in following loop unless it was a different error.
Maybe you are looking for
-
Wireless for Windows XP Client of Lan Manager?
Hello Is it possible to install the Manager on windows XP wireless lan client? If there is a way someone can help me please? I can't install Windows 2 k because win 2 k is so slow. Thank you very much! A.
-
EE this MFP have 20 free in and on the ability of efax. Thought I saw then that the implementation, but can not find it now. Please let me know. Thank you.
-
ink system error message Oxc19a0035 failed. Unable to copy, receive faxes or print
When I receive the error message above, I can't turn off the printer, then back on, and it will work a few times, then the above message comes back.
-
This bar has appeared without reason, said "config." Through the top of the screen when he's at the office. Everything seems to work, but may not know what it means, what caused it appear, how to get rid of him.
-
Problem when I run an application
Hi, I have a problem when I run an app in the Simulator. When the application is sync for the Simulator the following error appears: "Synchronization, and start the application has encountered a problem. result::Failure 500 'ascii' codec can't decode