Insert all, insert first from Oracle

Source: Internet
Author: User

Insert First/all makes it possible for INSERT statements to insert multiple tables at the same time, and to determine which table or tables each record is inserted into according to the criteria.
Insert First : for each row of data, insert only the table that was established when the condition is the only one, and do not continue to check for other conditions.
Insert All: For each row of data, each when condition is checked, and the insert operation is performed if the condition is met.

create table              Edw_int (agmt_no varchar2 (+ byte) not NULL, agmt_sub_no varchar2 (4 bytes) Not NULL, need_repay_int number (22,2), Curr_period number (4) is 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) is not NULL); CREATE TABLE Edw_int_2 (agmt_no varchar2 (+ byte) not NULL, Agmt_sub_no VARCHAR2 (4 b   Yte) not NULL, Need_repay_int number (22,2), Curr_period number (4) is not NULL  ); 
Insert into Edw_int (Agmt_no, Agmt_sub_no, Need_repay_int, Curr_period) VALUES (' 20003874 ', ' 2104 ', 3126.5, 7); Insert int   o 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_n O, Agmt_sub_no, Need_repay_int, Curr_period) VALUES (' 20003874 ', ' 2104 ', 3616.41, 4); insert into Edw_int (Agmt_no, agmt_s Ub_no, Need_repay_int, Curr_period) VALUES (' 20017143 ', ' 2104 ', 2350.86, 0); insert into Edw_int (Agmt_no, Agmt_sub_no, n Eed_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, cur R_period) VALUES (' 20018273 ', ' 2104 ', 2080.49, 0); COMMIT;
Insert All Example
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;

Delete data continue test plus condition when and else
TRUNCATE TABLE edw_int_1;
TRUNCATE TABLE edw_int_2;

Insert all when       curr_period = 0          and into edw_int_1 (Agmt_no, Agmt_sub_no, Need_repay_int, curr_period) VALUES (AG Mt_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;

Delete data test insert first

Insert first when      curr_period = 0         and 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;




Insert all, insert first from Oracle

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.