forall在10g新功能
--all_orders所有訂單;new_records新增加訂單(狀態1);orders_archive無效訂單(狀態0)
create table all_orders(id number(18) primary key,mc varchar2(60),order_status number(2));
create table new_orders(id number(18) primary key,mc varchar2(60),order_status number(2));
create table orders_archive(id number(18) primary key,mc varchar2(60),order_status number(2));
insert into all_orders values(1,'mc1',0);
insert into all_orders values(2,'mc2',2);
insert into all_orders values(3,'mc3',2);
insert into all_orders values(4,'mc4',2);
insert into all_orders values(5,'mc5',1);
insert into all_orders values(6,'mc6',0);
insert into all_orders values(7,'mc7',1);
insert into all_orders values(8,'mc8',1);
insert into all_orders values(9,'mc9',1);
insert into all_orders values(10,'mc10',1);
insert into all_orders values(11,'mc11',0);
insert into all_orders values(12,'mc12',1);
insert into all_orders values(13,'mc13',1);
insert into all_orders values(14,'mc14',1);
insert into all_orders values(15,'mc15',1);
insert into all_orders values(16,'mc16',1);
insert into all_orders values(17,'mc17',0);
insert into all_orders values(18,'mc18',1);
insert into all_orders values(19,'mc19',1);
insert into all_orders values(20,'mc20',1);
commit;
SET SERVEROUTPUT ON
DECLARE
TYPE orders_type IS TABLE OF all_orders%ROWTYPE;
TYPE orders_index_type IS TABLE OF PLS_INTEGER INDEX BY PLS_INTEGER ;
orders_archive orders_type;
new_order orders_type;
all_order orders_type;
orders_archive_index orders_index_type;
order_status INTEGER;
new_orders_count INTEGER := 0;
old_orders_count INTEGER := 0;
BEGIN
SELECT * BULK COLLECT INTO all_order FROM all_orders;
new_order := all_order;
FOR i IN all_order.FIRST .. all_order.LAST LOOP
order_status := all_order(i).order_status ;
IF ( order_status = 2 ) THEN
new_order.DELETE(i);
ELSE
new_orders_count := new_orders_count+1;
END IF;
IF order_status = 0 THEN
orders_archive_index(old_orders_count) := i;
old_orders_count := old_orders_count+1;
END IF;
END LOOP;
DBMS_OUTPUT.PUT_LINE('Inserting '|| TO_CHAR(new_orders_count) || ' new ORDERS into NEW_ORDERS table');
DBMS_OUTPUT.PUT_LINE(' ');
FORALL indx IN INDICES OF new_order
INSERT INTO new_orders VALUES all_order(indx);
DBMS_OUTPUT.PUT_LINE('Inserting ' ||TO_CHAR(old_orders_count) ||' old ORDERS data into ORDERS_ARCHIVE table');
FORALL indx IN VALUES OF orders_archive_index
INSERT INTO orders_archive VALUES all_order(indx);
commit;
END;
/
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/756652/viewspace-242380/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- bulk forall 的測試(轉)
- [20181029]避免表示式在sql語句中(10g).txtSQL
- 聯機重定義表在10g的改進
- oracle 10g在linux下的安裝及簡單命令Oracle 10gLinux
- [20181030]避免表示式在sql語句中(10g)(補充).txtSQL
- 10g RAC on AIXAI
- oracle 10g flashback databaseOracle 10gDatabase
- 10G DG SWITCH OVER
- Oracle 10g 在linux redhat as4 系統安裝圖解全過程Oracle 10gLinuxRedhat圖解
- Oracle 10g 下載地址Oracle 10g
- oracle 10G特性之awrOracle 10g
- 10G FGA的增強
- Scheduler in Oracle Database 10g(轉)OracleDatabase
- macOS 12 Monterey正式版來襲,全新功能盡在掌握!Mac
- Instrumentation 新功能
- ISO 映象安裝oracle 10gOracle 10g
- Oracle 10g RAC故障處理Oracle 10g
- [20190530]DISABLE TABLE LOCK(10g).txt
- Oracle 10g 增刪節點Oracle 10g
- 10g sqlplus的一個bugSQL
- 如何手工重建10g database consoleDatabase
- [20190215]那個更快(10g).txt
- Nodejs 的新功能NodeJS
- 10g NewFeatures學習筆記(轉)筆記
- [20180412]logminer使用問題(10g).txt
- 糟糕,在錯誤的分支開發了新功能,該怎麼處理呢?
- LEADTOOLS的新功能Document Composer可以讓你在多個檔案中建立文件
- Tinder在印度測試最新功能 女士可以優先選擇約會物件物件
- Solaris 10下遷移10G RAC (二)
- Solaris 10下遷移10G RAC (七)
- Solaris 10下遷移10G RAC (三)
- Solaris 10下遷移10G RAC (一)
- Solaris 10下遷移10G RAC (五)
- Poor Performance On Certain Dictionary Queries After Upgrade To 10gORMAI
- 10g透明閘道器訪問sqlserverSQLServer
- Solaris 10下遷移10G RAC (六)
- Solaris 10下遷移10G RAC (八)
- Solaris 10下遷移10G RAC (四)