Oracle Multi-Table Insert Syntax?

2019-02-26 04:40发布

问题:

I'm taking my first look at Oracle's multi-table insert (I'm fairly new to SQL overall), and I'm not quite understanding the purpose/need for the SELECT at the end of the statement.

With a single-table INSERT, it's my understanding that either the VALUES clause or a subquery are used, but not both. Can someone explain the significance of the SELECT clause at the end of this INSERT statement? I've looked online, but I haven't found a clear answer.

INSERT ALL
WHEN prod_category='B' THEN
INTO book_sales(prod_id,cust_id,qty_sold,amt_sold)
VALUES(product_id,customer_id,sale_qty,sale_price)
WHEN prod_category='V' THEN
INTO video_sales(prod_id,cust_id,qty_sold,amt_sold)
VALUES(product_id,customer_id,sale_qty,sale_price)
WHEN prod_category='A' THEN
INTO audio_sales(prod_id,cust_id,qty_sold,amt_sold)
VALUES(product_id,customer_id,sale_qty,sale_price)
SELECT prod_category ,product_id ,customer_id ,sale_qty, sale_price
FROM sales_detail;

回答1:

The select is used to determine the values of the variable prod_category used in WHEN prod_category='B' THEN