Oracle資料庫遊標案例講解與源碼 (2)

來源:互聯網
上載者:User

標籤:資料庫   oracle   預存程序   procedure   遊標   

關於此案例的詳細分析,請參看  《Oracle資料庫遊標案例講解與源碼》一文

http://blog.csdn.net/sinat_26342009/article/details/45199827

案例要求:
  利用遊標轉換兩張表的資料。
  首先,將滿足以下三個條件的資料插入到一張新表(productinfo_tmp)中 :
  <1>價格大於1000
  <2>產地為“中國”或“杭州”
  <3> 商品類型為“家電”或“電子產品”
  然後,在新表(productinfo_tmp)中進行如下兩個操作:
  <1>價格大於2000的下調5%

  <2>商品類型編號轉換為商品類型名稱

 由於《Oracle資料庫遊標案例講解與源碼》一文中的解決方案用到了子查詢與遊標,將會造成更大的系統開銷,造成查詢速度變慢,因此可以講解決方案更改為下面方式:

(建表語句與插入資料,請參照《Oracle資料庫遊標案例講解與源碼》一文)

create or replace procedure prcd_1isbegin  --清空暫存資料表中的原有記錄  delete from productinfo_tmp;  --把符合要求的資料查詢出來,插入新的資料並轉換CATEGORY欄位  insert into productinfo_tmp (pid,PNAME,PRICE,QUANTY,CATEGORY,DESPERATION,origin)  select pid,PNAME,PRICE,QUANTY,CATEGORY,DESPERATION,origin from productinfo,categoryinfo  where productinfo.category=categoryinfo.CID  and PRICE>1000 and origin in('中國','杭州') and CNAME in ('電子產品','家電');       --產品價格下調  update productinfo_tmp set productinfo_tmp.PRICE=productinfo_tmp.PRICE*0.95  where productinfo_tmp.PRICE>2000;   commit;   end prcd_1;

這樣既避免了子查詢,又不用使用遊標,可以很大的提高預存程序的執行效率!
   

Oracle資料庫遊標案例講解與源碼 (2)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.