1 , build a test table
[C-sharp]view plaincopyprint?
- CREATE TABLE Edw_int
- (
- Agmt_no VARCHAR2 (+ BYTE) not NULL,
- Agmt_sub_no VARCHAR2 (4 BYTE) not NULL,
- Need_repay_int number (22,2),
- Curr_period Number (4) Not NULL
- );
- CREATE TABLE edw_int_1
- (
- Agmt_no VARCHAR2 (+ BYTE) not NULL,
- Agmt_sub_no VARCHAR2 (4 BYTE) not NULL,
- Need_repay_int number (22,2),
- Curr_period Number (4) Not NULL
- );
- CREATE TABLE edw_int_2
- (
- Agmt_no VARCHAR2 (+ BYTE) not NULL,
- Agmt_sub_no VARCHAR2 (4 BYTE) not NULL,
- Need_repay_int number (22,2),
- Curr_period Number (4) Not NULL
- );
2 , inserting test data
[C-sharp]view plaincopyprint?
- INSERT into Edw_int
- (Agmt_no, Agmt_sub_no, Need_repay_int, Curr_period)
- VALUES
- (' 20003874 ', ' 2104 ', 3126.5, 7);
- INSERT into Edw_int
- (Agmt_no, Agmt_sub_no, Need_repay_int, Curr_period)
- VALUES
- (' 20003874 ', ' 2104 ', 3290.76, 6);
- INSERT into Edw_int
- (Agmt_no, Agmt_sub_no, Need_repay_int, Curr_period)
- VALUES
- (' 20003874 ', ' 2104 ', 3454.06, 5);
- INSERT into Edw_int
- (Agmt_no, Agmt_sub_no, Need_repay_int, Curr_period)
- VALUES
- (' 20003874 ', ' 2104 ', 3616.41, 4);
- INSERT into Edw_int
- (Agmt_no, Agmt_sub_no, Need_repay_int, Curr_period)
- VALUES
- (' 20017143 ', ' 2104 ', 2350.86, 0);
- INSERT into Edw_int
- (Agmt_no, Agmt_sub_no, Need_repay_int, Curr_period)
- VALUES
- (' 20017143 ', ' 2104 ', 3566.55, 0);
- INSERT into Edw_int
- (Agmt_no, Agmt_sub_no, Need_repay_int, Curr_period)
- VALUES
- (' 20018273 ', ' 2104 ', 1639.46, 0);
- INSERT into Edw_int
- (Agmt_no, Agmt_sub_no, Need_repay_int, Curr_period)
- VALUES
- (' 20018273 ', ' 2104 ', 2080.49, 0);
- COMMIT;
3 , Insert All/first Statement Example
(1) , Insert all- without conditions
[C-sharp]view plaincopyprint?
- Insert All
- Into Edw_int_1 (agmt_no,agmt_sub_no,need_repay_int,curr_period)
- VALUES (Agmt_no,agmt_sub_no,need_repay_int,curr_period)
- Into Edw_int_2 (agmt_no,agmt_sub_no,curr_period)
- VALUES (agmt_no, ' 1234 ', curr_period)
- Select Agmt_no,agmt_sub_no,need_repay_int,curr_period from Edw_int;
- Commit
(2) , Insert all- with conditions
[C-sharp]view plaincopyprint?
- Insert All
- When Curr_period=0 Then
- Into Edw_int_1 (agmt_no,agmt_sub_no,need_repay_int,curr_period)
- VALUES (Agmt_no,agmt_sub_no,need_repay_int,curr_period)
- Else
- Into Edw_int_2 (agmt_no,agmt_sub_no,need_repay_int,curr_period)
- VALUES (Agmt_no,agmt_sub_no,need_repay_int,curr_period)
- Select Agmt_no,agmt_sub_no,need_repay_int,curr_period from Edw_int;
- Commit
(3) , Insert first- with conditions
[C-sharp]view plaincopyprint?
- Insert First
- When Curr_period=0 Then
- Into Edw_int_1 (agmt_no,agmt_sub_no,need_repay_int,curr_period)
- VALUES (Agmt_no,agmt_sub_no,need_repay_int,curr_period)
- When agmt_sub_no= ' 2104 ' then
- Into Edw_int_2 (agmt_no,agmt_sub_no,need_repay_int,curr_period)
- VALUES (Agmt_no,agmt_sub_no,need_repay_int,curr_period)
- Select Agmt_no,agmt_sub_no,need_repay_int,curr_period from Edw_int;
- Commit
4 , Data results View
[C-sharp]view plaincopyprint?
- TRUNCATE TABLE edw_int_1;
- TRUNCATE TABLE edw_int_2;
- SELECT * from Edw_int;
- SELECT * from Edw_int_1;
- SELECT * from Edw_int_2;
5 , All with the First the Difference
All : do not consider the relationship, as long as the conditions are satisfied, all inserted;
First : consider a succession relationship if there is data that satisfies the first when condition satisfies the second one . when condition, the first one is executed Then Insert a statement, the second Then you don't insert the first one . Then the data that has been inserted.
The difference can also be described as, All repeated insertions may be made as long as the conditions are met; First The first thing to do is to satisfy the condition, then filter, not repeat the insert.
6. use Insert all to implement row and column conversions (insert all rotation function)
[C-sharp]view plaincopyprint?
- 1. Build a line multi-list and test data insertion
- CREATE TABLE Week_bal (ID int,w1_bal number,w2_bal number,w3_bal number,w4_bal number,w5_bal number);
- INSERT into Week_bal values (1,10.09,12.98,23.89,89.08,1098.01);
- Commit
- SELECT * from Week_bal;
- 2, build a small number of rows of the table
- CREATE TABLE week_bal_new (ID int,week int,bal number);
- 3. Insert with INSERT all statement
- Insert All
- Into Week_bal_new (Id,week,bal) VALUES (Id,1,w1_bal)
- Into Week_bal_new (Id,week,bal) VALUES (Id,2,w2_bal)
- Into Week_bal_new (Id,week,bal) VALUES (Id,3,w3_bal)
- Into Week_bal_new (Id,week,bal) VALUES (Id,4,w4_bal)
- Into Week_bal_new (Id,week,bal) VALUES (Id,5,w5_bal)
- Select Id,w1_bal,w2_bal,w3_bal,w4_bal,w5_bal from Week_bal;
- SELECT * from Week_bal_new;
Oracle inserts multiple tables (insert All/first)