Batch submit DML in Oracle

Source: Internet
Author: User

Oracle batch submit DML SQL code/* refer to section 8.5 of TOM programming art submitted in a loop 1. batch operation does not increase the execution speed, and the execution efficiency is less than that of a single DML statement. 2. Batch insertion can reduce the usage of undo space, but frequent submission may cause the undo space previously committed to be occupied by other transactions and may cause ORA-0155 errors. 3. If half-cut operations fail in batches, your database will be placed in an unknown state. (This will not happen in the DELETE operation) */-- batch update drop table T2; create table T2 as select OBJECT_NAME FROM DBA_OBJECTS; SELECT * FROM T2; select count (*) FROM T2; -- is table of create an array OF xx type declare type ridarray is table of rowid; type vcarray is table of T2.OBJECT _ NAME % TYPE; L_RIDS RIDARRAY; L_NAMES VCARRAY; cursor c is select rowid, OBJECT_NAME FROM T2; begin open c; loop fetch c bulk collect into L_RIDS, L_NAMES LIMIT 10; forall I IN 1 .. rochelle rids.count UPDATE T2 SET OBJECT_NAME = LOWER (L_NAMES (I) where rowid = L_RIDS (I); COMMIT; EXIT WHEN C % NOTFOUND; END LOOP; CLOSE C; END; -- batch delete drop table T3; create table T3 as select * FROM DBA_OBJECTS; declare cursor mycursor is select rowid from T3 order by rowid; -------- CURSOR sorted by rowid, the deletion condition is xxx = XXXX. The actual TYPE ROWID_TABLE_TYPE is table of rowid index by PLS_INTEGER; V_ROWID ROWID_TABLE_TYPE; begin open mycursor; loop fetch mycursor bulk collect into V_ROWID LIMIT 5000; -------- each time 5000 rows are processed, that is, every 5000 rows are submitted. exit when V_ROWID.COUNT = 0; forall I in v_rowid.first.v_rowid.last delete from T3 where rowid = V_ROWID (I); COMMIT; END LOOP; close mycursor; END;/-- batch insert drop table T4; drop table T5; create table T4 as select * FROM DBA_OBJECTS; create table T5 as select * FROM T4 WHERE 1 = 0; declare cursor mycursor is select rowid from T4 order by rowid; -------- CURSOR sorted by rowid. The deletion condition is xxx = XXXX. TYPE ROWID_TABLE_TYPE is table of rowid index by PLS_INTEGER; v_ROWID ROWID_TABLE_TYPE; begin open mycursor; loop fetch mycursor bulk collect into V_ROWID LIMIT 5000; -------- submit exit when V_ROWID.COUNT = 0 each time 5000 rows are processed; forall I in v_rowid.first.v_rowid.last insert into T5 SELECT * FROM T4 where rowid = V_ROWID (I); COMMIT; END LOOP; CLOSE MYCURSOR; END;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.