Oracle's Multi-table Insert Learning note

Source: Internet
Author: User

----------------------------multitable Insert--------------------------------
----------------Insert All----------------------------------------------------
SELECT * from EMP;

CREATE TABLE Sal_history (
Empid Number (4), HireDate date, SAL number (7,2)
);
CREATE TABLE Mgr_history (
Empid Number (4), Mgr Number (4), SAL number (7,2)
);

INSERT All
Into Sal_history VALUES (empid,hiredate,sal)
Into Mgr_history VALUES (empid,mgr,sal)
SELECT empno EMPID, HireDate, SAL, MGR
From EMP
WHERE Empno < 7654;

commit;

SELECT * from Sal_history;
SELECT * from Mgr_history;

-------------------Conditional Insert All-------------------------------
TRUNCATE TABLE sal_history;
TRUNCATE TABLE mgr_history;

INSERT All
When Empid >= 7521 then
Into Sal_history VALUES (empid,hiredate,sal)
When Mgr >= 7839 then
Into Mgr_history VALUES (empid,mgr,sal)
SELECT empno EMPID, HireDate, SAL, MGR
From EMP
WHERE Empno < 7654;

commit;
Note: When statements can only use Pseudocolumn

--------------------conditional first INSERT-----------------------
Query The resulting statement, and if the first condition is met, then it will be executed, The returned rows that have already been processed are no longer considered in the following.
INSERT First
 when empid < 7654 then 
  into Sal_history VALUES (empid,hiredate,sal)
 when empid = 7499 then 
  into Sal_history VALUES (empid,hiredate,sal)
 else
  into Mgr_history values (empid,mgr,sal)
SELECT empno EMPID, HireDate, SAL, Mgr
from EMP
WHERE empno < 7654;

If a portion of the returned row does not satisfy the condition of the first statement, that part is treated as a conditional insert.
INSERT First
When Empid > 7654 Then
Into Sal_history VALUES (empid,hiredate,sal)
When mgr = 7499 Then
Into Sal_history VALUES (empid,hiredate,sal)
Else
into mgr_history values (empid,mgr,sal)
SELECT empno EMPID, HireDate, SAL, MGR
From EMP
WHERE Empno < 7654;


Oracle's Multi-table Insert Learning note

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.