INSERT FIRST介紹
何謂INSERT FIRST
- INSERT FIRST要搭配WHEN......THEN語句使用,判對第一個WHEN語句條件如果為TRUE就插入資料列,而其後的WHEN語句就省略判斷,如果為FIRST就往下列WHEN語句判斷,以此類推,它跟INSERT ALL一樣在多表格插入資料列
格式
INSERT FIRST
WHEN condition THEN insert_into_clause [insert_into_clause...]
[WHEN condition THEN insert_into_clause [insert_into_clause...]...]
[ELSE insert_into_clause [insert_into_clause...]]
(subquery);
使用方式
如果salary大於4000新增到emp2表格,如果第一個WHEN條件就為TRUE,而其後的WHEN語句就省略判斷,以此類推
insert first
when salary>4000 then into emp2
when salary>5000 then into emp3
when salary>6000 then into emp4
select salary from employees;