


下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、1、創(chuàng)建存儲過程 create or replace procedure test(var_name_1 in type,var_name_2 out type) as -聲明變量 (變量名 變量類型 )begin-存儲過程的執(zhí)行體end test;打印出輸入的時間信息E.g:create or replace procedure test(workDate in Date) isbegindatedbms_output.putline('The input is:'|to_date(workDate,'yyyy-mm-dd&apo
2、s;);end test;2、變量賦值變量名 := 值 ;E.g:create or replace procedure test(workDate in Date) isx number(4,2);beginx := 1;end test;3、判斷語句 : if 比較式 then begin end; end if;E.g create or replace procedure test(x in number) isbeginif x >0 thenbeginx := 0 - x;end;end if;if x = 0 thenbeginx: = 1;end;end if;end t
3、est;4、For 循環(huán)For . in . LOOP-執(zhí)行語句end LOOP;(1)循環(huán)遍歷游標(biāo)create or replace procedure test() asCursor cursor is select name from student; name varchar(20);beginfor name in cursor LOOP begindbms_output.putline(name);end;end LOOP;end test;(2)循環(huán)遍歷數(shù)組create or replace procedure test(varArray in myPackage.TestArr
4、ay) as-( 輸入?yún)?shù) varArray 是自定義的數(shù)組類型,定義方式見標(biāo)題 6)i number;begini := 1;-存儲過程數(shù)組是起始位置是從1開始的,與java、C、C+等語言不同。因為在Oracle中本是沒有數(shù)組的概念的,數(shù)組其實就是一張-表(Table),每個數(shù)組元素就是表中的一個記錄,所以遍歷數(shù)組時就相當(dāng)于從表中的第一條記錄開始遍歷for i in 1.varArray.count LOOPdbms_output.putline('The No.'| i | 'record in varArray is:&ap
5、os;|varArray(i);end LOOP;end test;5、While 循環(huán)while 條件語句 LOOPbegin end;end LOOP;E.gcreate or replace procedure test(i in number) asbeginwhile i < 10 LOOPbegini:= i + 1;end;end LOOP;end test;6、數(shù)組首先明確一個概念:Oracle中本是沒有數(shù)組的概念的,數(shù)組其實就是一張表(Table),每個數(shù)組 元素就是表中的一個記錄。使用數(shù)組時,用戶可以使用 Oracle 已經(jīng)定義好的數(shù)組類型,或可根據(jù)自己的需要定義數(shù)組
6、 類型。(1)使用 Oracle 自帶的數(shù)組類型x array; - 使用時需要需要進(jìn)行初始化e.g:create or replace procedure test(y out array) isx array;beginx := new array();y := x;end test;(2)自定義的數(shù)組類型(自定義數(shù)據(jù)類型時, 建議通過創(chuàng)建 Package 的方式實現(xiàn), 以便于管理 )E.g ( 自定義使用參見標(biāo)題 4.2) create or replace package myPackage is- Public type declarations type info is recor
7、d(name varchar(20), y number);type TestArray is table of info index by binary_integer;-此處聲明了一個 TestArray 的類型數(shù)據(jù),其實其為一張存儲 Info 數(shù)據(jù)類型的 Table 而已,及 TestArray 就是一張表,有兩個字 段,一個是name, 個是y。需要注意的是此處使用了Index by binary_integer編制該Table的索引項,也可以不寫,直接寫成: type TestArray istable of info ,如果不寫的話使用數(shù)組時就需要進(jìn)行初始化:varArray my
8、Package.TestArray;varArray := new myPackage.TestArray();end TestArray;7. 游標(biāo)的使用Oracle 中 Cursor 是非常有用的,用于遍歷臨時表中的查詢結(jié)果。其相關(guān)方法和屬性也很多, 現(xiàn)僅就常用的用法做一二介紹:(1) Cursor 型游標(biāo) (不能用于參數(shù)傳遞 )create or replace procedure test() iscusor_1 Cursor is select std_name from student where.; -Cursor 的使用方式 1 cursor_2Cursor;beginsele
9、ct class_name into cursor_2 from class where .;-Cursor 的使用方式 2可使用 For x in cursor LOOP end LOOP; 來實現(xiàn)對 Cursor 的遍歷end test;(2) SYS_REFCURSOR 型游標(biāo),該游標(biāo)是 Oracle 以預(yù)先定義的游標(biāo),可作出參數(shù)進(jìn)行傳遞create or replace procedure test(rsCursor out SYS_REFCURSOR) iscursor SYS_REFCURSOR; name varhcar(20);beginOPEN cursor FOR select name from student where . -SYS_REFCURSOR 只能通過 法來打開和賦值LOOPfetch cursor into name -SYS_REFCURSOR 只能通過 fetch into 來打開和遍歷 cursor%NOTFOUND;-SYS_REFCURSOR 中 可使用 三個狀-%NOTFOU
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- DB32/T 3134-2016瀝青路面就地?zé)嵩偕┕ぜ夹g(shù)規(guī)范
- DB32/T 1261-2020壽眉茶加工技術(shù)規(guī)程
- DB31/T 948-2015地下空間安全使用管理基本要求
- 【正版授權(quán)】 ISO/IEC 18584-1:2025 EN Information technology - Test methods for on-card biometric comparison applications - Part 1: General principles and specifications
- DB31/T 841-2014用人單位職業(yè)病危害現(xiàn)狀評價技術(shù)導(dǎo)則
- DB31/T 790-2014家用和類似用途電器安裝維修服務(wù)規(guī)范
- DB31/T 685-2019養(yǎng)老機構(gòu)設(shè)施與服務(wù)要求
- DB31/T 319-2013活禽市場交易規(guī)范
- DB31/T 1181-2019天然飾面石材加工單位產(chǎn)品能源消耗限額
- DB31/ 283-2015戶外廣告設(shè)施設(shè)置技術(shù)規(guī)范
- 水電站收購分析報告
- 水泥粉助磨劑項目可行性研究報告發(fā)改委立項模板
- 濟南公共交通集團有限公司招聘筆試題庫2025
- 工貿(mào)行業(yè)重大安全生產(chǎn)事故隱患判定標(biāo)準(zhǔn)解讀課件
- 委托裝訂合同協(xié)議
- 無氟防水劑研發(fā)及在紡織品中的實際應(yīng)用研究
- 水泥長期購銷合同范本
- 2025-2030年中國制罐行業(yè)現(xiàn)狀調(diào)研分析及發(fā)展趨勢預(yù)測報告
- 體檢醫(yī)學(xué)知識科普
- 2025年臨床帶教老師心得感想(7篇)
- 新北師版一年級數(shù)學(xué)下冊教案教學(xué)設(shè)計全冊
評論
0/150
提交評論