2

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
  • 1
    read the select first: select x,y from table1. For each row, when x='Foo', insert into table2, when x='Bar', then insert into table3, etc ... Commented Feb 16, 2014 at 22:04

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.