版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、第18章批量SQL、牙齒章節(jié)中的目標(biāo)、了解FORALL語句的使用情況使用BULK COLLECT子句、批量SQL、基本概念PL/SQL和SQL引擎之間的通信稱為上下文切換。批量SQL是對(duì)SQL語句及其結(jié)果的批量處理。優(yōu)點(diǎn)上下文切換減少性能負(fù)載減少18.1 FORALL語句,例如for I in 1.10 loop insert into table _ name values();END LOOP說明:牙齒FOR循環(huán)重復(fù)INSERT語句10次,以生成10次上下文切換。因此,引入FORALL語句以批量處理SQL語句。18.1 FORALL敘述句,功能會(huì)將大量INSERT、UPDATE或DELET
2、E敘述句從PL/SQL引擎?zhèn)魉椭罶QL引擎,而不是一次傳送一個(gè)敘述句。語法for all loop _ counter in bounds _ clause save exceptions SQL _ statement;其中l(wèi)oop_counter是隱式定義的循環(huán)柜臺(tái)變量。SQL_STATEMENT,此語句是引用一個(gè)或多個(gè)集合的靜態(tài)或動(dòng)態(tài)INSERT、UPDATE或DELETE語句。SAVE EXCEPTIONS確保SQL_STATEMENT生成異常時(shí)FORALL語句繼續(xù)執(zhí)行。18.1 FORALL語句、bounds_clause和控制環(huán)柜臺(tái)變量的值。三種茄子格式:lower _ limit
3、.upper _ limit回圈計(jì)數(shù)器的上限與下限indices of collection _ name between lower _ limit . upper _ limit Ame參照特定集的個(gè)別元素值示例18-1 FORALL語句,declare type row _ num _ type is table of number index by pls _ integer;typerow _ text _ type is table of varchar 2(10)index by pls _ integer;Row _ num _ tab row _ num _ typeRow
4、_ text _ tab row _ text _ typeV _ total numberBegin for I in 1.10 loop row _ num _ tab(I):=I;row _ text _ tab(I):=val | | I;End loopFor all I in 1.10 insert into test values(row _ num _ tab(I),row _ text _ tab(I);Commitselect count(*)into v _ total from test;Dbms _ output.put _ line(測(cè)試表中的總計(jì)| v_total
5、 |個(gè)唱片);End,示例18-2批處理SQL的性能改善分析,declare -合并數(shù)組類型row _ num _ type is table of number index by pls _ integer定義Typerow _ textRow _ num _ tab row _ num _ typeRow _ text _ tab row _ text _ typeV _ total numberV _ start _ time integerV _ end _ time integerBegin - for I in 1.1000 loop row _ num _ tab(I):=I;r
6、ow _ text _ tab(I):=val | | I;End loop,- 1,000行唱片v _ start _ time :=DBMS _ utility . get _ time;For I in 1.1000 loop insert into test (row _ num,row _ text) values (row _ num _ tab (I),row .End loopv _ end _ time :=DBMS _ utility . get _ time;Dbms_output.put_line(執(zhí)行FOR語句所用的時(shí)間:| |(v _ end _ time-v _
7、start _ time);-1000行唱片v _ start _ time 3360=DBMS _ utility . get _ time;For all I in 1.1000 insert into test (row _ num,row _ text) values (row _ num _ tab (I),row V _ end _Dbms_output.put_line(執(zhí)行FORALL語句所用的時(shí)間:| |(v _ end _ time-v _ start _ time);CommitEnd,1,SAVE EXCEPTIONS選項(xiàng)(例如FORALL I in 1).10 sav
8、e exceptions insert into test values功能),即使該SQL語句引發(fā)異常,您也可以繼續(xù)執(zhí)行for all語句。這些異常情況存儲(chǔ)在SQL%BULK_EXCEPTIONS游標(biāo)屬性中。1,SAVE EXCEPTIONS選項(xiàng),SQL%BULK_EXCEPTIONS屬性每個(gè)記錄由兩個(gè)字段組成的唱片集合,這兩個(gè)字段為ERROR_INDEX和ERROR_CODE。ERROR_INDEX存儲(chǔ)引發(fā)異常的FORALL語句的重復(fù)編號(hào)。ERROR_CODE存儲(chǔ)與遇到的例外相對(duì)應(yīng)的Oracle錯(cuò)誤代碼。SQL%BULK_EXCEPTIONS。您可以使用COUNT來擷取執(zhí)行FORALL敘述
9、句時(shí)發(fā)生的異常狀況數(shù)目。您可以使用SQLERRM函數(shù)查詢錯(cuò)誤消息。,示例18-3使用SAVE EXCEPTION選項(xiàng),declare -合并數(shù)組類型row _ num _ type is table of number index by pls _ integer定義Typerow Row _ num _ tab row _ num _ typeRow _ text _ tab row _ text _ typeErrors exceptionPragmaexception _ init (errors,-24381);Begin是I in 1.10 loop row _ num _ tab(
10、I):=I;row _ text _ tab(I):=val | | I;End loop,-陣列DML錯(cuò)誤,row _ text _ tab(1):=rpad(row _ text _ tab(1),11,);row _ text _ tab(5):=rpad(row _ text _ tab(5),11,);row _ text _ tab(7):=rpad(row _ text _ tab(7),11,);-for all I in 1.10 save exceptions insert into test(row _ num,row _ text)values(row _ num _
11、Commit);exception when errors then DBMS _ output . put _ line(總計(jì)| SQL%BULK_EXCEPTIONS)。COUNT |個(gè)錯(cuò)誤);For I in 1.SQL % bulk _ exceptions . count loop DBMS _ output . put _ line(第一個(gè)| | SQL % bulk _ exceptions DBMS _ output)error _ code);End loopEnd,遇到的異常錯(cuò)誤數(shù),F(xiàn)ORALL語句的迭代數(shù),Oracle錯(cuò)誤代碼,2,INDICES OF選項(xiàng),如for al
12、l I in INDICES OF row _ num _ tab insert into test valuesRow _ num _ tab row _ num _ typeRow _ text _ tab row _ text _ typeV _ total numberBegin是I in 1.10 loop row _ num _ tab(I):=I;row _ text _ tab(I):=val | | I;End loop,-刪除合并數(shù)組的元素,使row_num_tab.delete(1)稀疏。row _ text _ tab . delete(1);row _ num _ t
13、ab . delete(5);row _ text _ tab . delete(5);row _ num _ tab . delete(7);row _ text _ tab . delete(7);-for all I in indices of row _ num _ tab insert into test(row _ num,row _ text) values (row _ num Commit)select count(*)into v _ total from test;Dbms_output.put_line(總| v_total |個(gè)記錄寫入測(cè)試表);End,3,VALUE
14、S OF選項(xiàng)(例如for all I in VALUES OF exc _ ind _ tab insert into test _ exc VALUES功能使用VALUES OF選項(xiàng)表示FORALL語句中循環(huán)柜臺(tái)的值),牙齒集合表示FORALL這些索引值可以不是唯一的,并且可以按任何順序列出。3,VALUES OF選項(xiàng),使用value OF選項(xiàng)的限制:如果VALUES OF子句中使用的集合是合并數(shù)組,則必須使用PLS_INTEGER或BINARY_INTEGER對(duì)合并數(shù)組進(jìn)行索引。VALUES OF子句中使用的集合的元素包括PLS_INTEGER或BINARY _ INTEGER必須是,F(xiàn)O
15、RALL語句會(huì)在VALUES OF子句引用的集合為空時(shí)引發(fā)異常。,示例18-5 VALUES OF選項(xiàng),使用declare合并數(shù)組type row _ num _ type is table OF number index by pls _ integer定義的type row _type exc _ ind _ type is table of pls _ integer index by pls _ integer;Row _ num _ tab row _ num _ typeRow _ text _ tab row _ text _ typeExc _ ind _ tab exc _
16、ind _ typeErrors exceptionPragmaexception _ init (errors,-24381);Begin是I in 1.10 loop row _ num _ tab(I):=I;row _ text _ tab(I):=val | | I;End loop,row _ text _ tab(1):=rpad(row _ text _ tab(1),11,);row _ text _ tab(5):=rpad(row _ text _ tab(5),11,);row _ text _ tab(7):=rpad(row _ text _ tab(7),11,);-for all I in 1.10 save exceptions insert into test(row _ num,row _ text)values(row _ num _ Commit);Exception when errors then for I in 1.SQL % bulk _ exceptions . count loop exc _ ind _ tab(I):=SQL % End loop;for all I
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 妊娠期尿路感染抗菌藥物劑量調(diào)整策略
- 鈑金工藝基礎(chǔ)試題及答案
- 慢病培訓(xùn)考試及答案
- 多組學(xué)整合在糖尿病精準(zhǔn)分型中的實(shí)踐
- 2025年中職(物業(yè)管理)物業(yè)基礎(chǔ)服務(wù)試題及答案
- 2025年中職機(jī)械設(shè)備維修(設(shè)備維護(hù)保養(yǎng))試題及答案
- 2026年露營(yíng)經(jīng)濟(jì)項(xiàng)目商業(yè)計(jì)劃書
- 2025年高職新聞出版(書刊編輯)試題及答案
- 2025年中職第二學(xué)年(焊接技術(shù)應(yīng)用)焊接變形控制試題及答案
- 多源數(shù)據(jù)融合提升慢病隨訪精準(zhǔn)度
- 新食品零售運(yùn)營(yíng)管理辦法
- 強(qiáng)制性產(chǎn)品認(rèn)證實(shí)施規(guī)則 低壓電器 低壓元器件(CNCA-C03-02:2024)
- 《實(shí)踐論》《矛盾論》導(dǎo)讀課件
- 農(nóng)村殺豬活動(dòng)方案
- 種子公司企業(yè)管理制度
- DB4201-T 617-2020 武漢市架空管線容貌管理技術(shù)規(guī)范
- 藥品追溯碼管理制度
- openEuler系統(tǒng)管理與服務(wù)器配置 課件 第9章DNS服務(wù)器
- 供銷集團(tuán)考試試題及答案
- 資產(chǎn)評(píng)估員工管理制度
- 《環(huán)境保護(hù)稅納稅申報(bào)表(A類)》
評(píng)論
0/150
提交評(píng)論