Examples of Oracle Merge into

Source: Internet
Author: User

Content from Oracle 11g practical Tutorials Zheng Achi, etc.

In Oracle 11g, there is a merge statement that performs an INSERT, update, or delete operation on the target table based on the results of the connection to the original table. For example, by inserting, updating, or deleting rows in another table based on the differences found in one table, this method can synchronize information for two tables. The syntax format is as follows

Merge into < target table name >

Using < original table name >on < conditional expressions >

When matched and then {update Set ... | Delete

When isn't matched then insert (...) VALUES ()

Merge into a
Using XSB on (a.xh=xsb. Number)
When matched then update set a.xm = XSB. Name, A.XB=XSB. Gender, A.CSSJ = xsb. Time of birth, A.zy=xsb. Major, A.zxf=xsb. Total credits, A.BZ=XSB. Notes
When isn't matched then insert values (XSB, XSB. Name, xsb. Sex, xsb. Birth time, Xsb. Major, Xsb. Total credits, XSB. Notes)

Database

 Create TableA (XHChar(6) not NULL Primary Key, XMChar(8) not NULL, XBChar(2) not NULL, CSSJ date not NULL, ZYChar( -)NULL, ZXF Number(2)NULL, BZvarchar( $)NULL );

----------------------------------------------------------file created-Sunday-July -24-2016------------------------------------------------------------------------------------------------------------------DDL for Table XSB--------------------------------------------------------  CREATE TABLE" SCOTT". " XSB "(" Study No. "CHAR(6BYTE), "name"CHAR(8BYTE), "gender"CHAR(2BYTE)DEFAULT 'male', "date of birth", "professional"CHAR( ABYTE), "Total Credits" Number(2,0), "Remarks"VARCHAR2( $BYTE)) SEGMENT CREATION IMMEDIATE PCTFREETenPctused +Initrans1Maxtrans255nocompress LOGGING STORAGE (INITIAL65536 NEXT 1048576Minextents1MAXEXTENTS2147483645Pctincrease0Freelists1FREELIST GROUPS1Buffer_poolDEFAULTFlash_cacheDEFAULTCell_flash_cacheDEFAULT) tablespace "USERS"; REM INSERTING intoSCOTT. XSBSETDEFINEOFF;Insert  intoSCOTT. XSB (School number, name, gender, time of birth, major, total credits, notes)Values('151114','Zhou Ho Jun','male', To_date ('2 May-September on -98','DD-MON-RR'),'Computer', -,NULL);Insert  intoSCOTT. XSB (School number, name, gender, time of birth, major, total credits, notes)Values('151101','Wang Lin','male', To_date ('February-October on -97','DD-MON-RR'),'Computer', -,NULL);Insert  intoSCOTT. XSB (School number, name, gender, time of birth, major, total credits, notes)Values('151103','Wang','female', To_date ('October-June on -96','DD-MON-RR'),'Computer', -,NULL);Insert  intoSCOTT. XSB (School number, name, gender, time of birth, major, total credits, notes)Values('151202','Wang Lin','male', To_date ('2 September-January on -96','DD-MON-RR'),'Communication Engineering', +,'One of the classes failed, to be retake');Insert  intoSCOTT. XSB (School number, name, gender, time of birth, major, total credits, notes)Values('151108','Lin Yi-Fan','male', To_date ('August-May on -96','DD-MON-RR'),'Computer', the,'have completed a course in advance');Insert  intoSCOTT. XSB (School number, name, gender, time of birth, major, total credits, notes)Values('151204','Ma Linlin','female', To_date ('February-October on -96','DD-MON-RR'),'Communication Engineering', the,NULL);----------------------------------------------------------DDL for Index sys_c0011202--------------------------------------------------------  CREATE UNIQUE INDEX"SCOTT". " sys_c0011202 " on" SCOTT". " XSB "(" study number ") PCTFREETenInitrans2Maxtrans255 COMPUTE STATISTICSSTORAGE (INITIAL65536 NEXT 1048576Minextents1MAXEXTENTS2147483645Pctincrease0Freelists1FREELIST GROUPS1Buffer_poolDEFAULTFlash_cacheDEFAULTCell_flash_cacheDEFAULT) tablespace "USERS";----------------------------------------------------------Constraints for Table XSB--------------------------------------------------------  ALTER TABLE"SCOTT". " XSB "MODIFY" ("School Number") not NULLENABLE); ALTER TABLE"SCOTT". " XSB "MODIFY" ("Name" not NULLENABLE); ALTER TABLE"SCOTT". " XSB "MODIFY" ("Gender" not NULLENABLE); ALTER TABLE"SCOTT". " XSB "MODIFY" ("Birth Time") not NULLENABLE); ALTER TABLE"SCOTT". " XSB "ADD PRIMARY KEY("study number") USINGINDEXPCTFREETenInitrans2Maxtrans255 COMPUTE STATISTICSSTORAGE (INITIAL65536 NEXT 1048576Minextents1MAXEXTENTS2147483645Pctincrease0Freelists1FREELIST GROUPS1Buffer_poolDEFAULTFlash_cacheDEFAULTCell_flash_cacheDEFAULT) tablespace "USERS" ENABLE;

Examples of Oracle Merge into

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.