INSERT高级应用

INSERT INTO departments 
   VALUES  (departments_seq.nextval, 'Entertainment', 162, 1400); 

INSERT INTO employees (employee_id, last_name, email, hire_date, job_id, salary) VALUES (employees_seq.nextval, 'Doe', 'john.doe@example.com', SYSDATE, 'SH_CLERK', 2400) RETURNING salary*12, job_id INTO :bnd1, :bnd2;

ALL

If you specify ALL, the default value, then the database evaluates each WHEN clause regardless of the results of the evaluation of any other WHEN clause. For each WHEN clause whose condition evaluates to true, the database executes the corresponding INTO clause list.

FIRST

If you specify FIRST, then the database evaluates each WHEN clause in the order in which it appears in the statement. For the first WHEN clause that evaluates to true, the database executes the corresponding INTO clause and skips subsequent WHEN clauses for the given row.

CREATE TABLE small_orders 
   (order_id       NUMBER(12)   NOT NULL,
    customer_id    NUMBER(6)    NOT NULL,
    order_total    NUMBER(8,2),
    sales_rep_id   NUMBER(6)
   );

CREATE TABLE medium_orders AS SELECT * FROM small_orders;

CREATE TABLE large_orders AS SELECT * FROM small_orders;

CREATE TABLE special_orders 
   (order_id       NUMBER(12)    NOT NULL,
    customer_id    NUMBER(6)     NOT NULL,
    order_total    NUMBER(8,2),
    sales_rep_id   NUMBER(6),
    credit_limit   NUMBER(9,2),
    cust_email     VARCHAR2(30)
   );

Puts orders greater than 290,000 into thespecial_orders table.
INSERT ALL
   WHEN ottl <= 100000 THEN
      INTO small_orders
         VALUES(oid, ottl, sid, cid)
   WHEN ottl > 100000 and ottl <= 200000 THEN
      INTO medium_orders 
         VALUES(oid, ottl, sid, cid)
   WHEN ottl > 200000 THEN
      into large_orders  --不仅存放大于200000的数据,而且存放大于290000的数据
          VALUES(oid, ottl, sid, cid)
   WHEN ottl > 290000 THEN
      INTO special_orders  --仅存放大于290000的数据
   SELECT o.order_id oid,
    o.customer_id cid,
          o.order_total ottl,
          o.sales_rep_id sid,
        c.credit_limit cl,
        c.cust_email cem
      FROM orders o, customers c
      WHERE o.customer_id = c.customer_id;

put orders greater than 200,000 into the large_orders table andspecial_orders table is null:
INSERT FIRST
   WHEN ottl <= 100000 THEN
      INTO small_orders
         VALUES(oid, ottl, sid, cid)
   WHEN ottl > 100000 and ottl <= 200000 THEN
      INTO medium_orders
         VALUES(oid, ottl, sid, cid)
   WHEN ottl > 200000 THEN
      into large_orders  --不仅存放大于200000的数据,而且存放大于290000的数据
          VALUES(oid, ottl, sid, cid)
   WHEN ottl > 290000 THEN
      INTO special_orders  --没有大于290000的数据,此表为空
   SELECT o.order_id oid,
          o.customer_id  cid,
          o.order_total  ottl,
          o.sales_rep_id sid,
          c.credit_limit cl,
          c.cust_email   cem
      FROM orders o, customers c
      WHERE o.customer_id = c.customer_id;

 

转载于:https://www.cnblogs.com/wwxbi/p/4175814.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值