Oracle inserts data into multiple tables at the same time

Source: Internet
Author: User

During Oracle operations, data is often inserted into multiple different tables at the same time. This statement is very suitable. "All" indicates a non-short-circuit operation, that is, if the First condition is met, you must run the following command to check whether other conditions are met. However, if the First condition is found for the short-circuit operation, the operation will not proceed downward. 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; Merging Rows into a Table

Merge into oe. product_information pi

USING (SELECT product_id, list_price, min_price

FROM new_prices) NP

ON (pi. product_id = np. product_id)

When matched then update set pi. list_price = np. list_price

, Pi. min_price = np. min_price

When not matched then insert (pi. product_id, pi. category_id

, Pi. list_price, pi. min_price)

VALUES (np. product_id, 33, np. list_price, np. min_price );

Related Article

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.