萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> oracle教程 >> oracle同時向多表插入數據

oracle同時向多表插入數據

  在Oracle操作過程中經常會碰到同時向多個不同的表插入數據,此時用該語句就非常合適。 All表示非短路運算,即滿足了第一個條件也得向下執行查看是否滿足其它條件,而First是短路運算找到合適條件就不向下進行。 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);

copyright © 萬盛學電腦網 all rights reserved