


下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quá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)遍歷游標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ù)組類型,定義方式見標題 6)i number;begini := 1;-存儲過程數(shù)組是起始位置是從1開始的,與java、C、C+等語言不同。因為在Oracle中本是沒有數(shù)組的概念的,數(shù)組其實就是一張-表(Table),每個數(shù)組元素就是表中的一個記錄,所以遍歷數(shù)組時就相當于從表中的第一條記錄開始遍歷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; - 使用時需要需要進行初始化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 ( 自定義使用參見標題 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ù)組時就需要進行初始化:varArray my
8、Package.TestArray;varArray := new myPackage.TestArray();end TestArray;7. 游標的使用Oracle 中 Cursor 是非常有用的,用于遍歷臨時表中的查詢結(jié)果。其相關(guān)方法和屬性也很多, 現(xiàn)僅就常用的用法做一二介紹:(1) Cursor 型游標 (不能用于參數(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 型游標,該游標是 Oracle 以預(yù)先定義的游標,可作出參數(shù)進行傳遞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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 《課間活動》(教案)2024-2025學(xué)年數(shù)學(xué)二年級上冊
- 2025年美容院會員協(xié)議模板
- 學(xué)習2025年雷鋒精神六十二周年主題活動方案 合計3份
- 2025年青海省安全員A證考試題庫
- 《游山西村》歷年中考古詩欣賞試題匯編(截至2024年)
- 全國河大音像版初中信息技術(shù)七年級下冊第一章第二節(jié)《文字素材的采集》教學(xué)設(shè)計
- 歷史-云南省師范大學(xué)附屬中學(xué)2025屆高三下學(xué)期開學(xué)考試試題和答案
- 2025年海口市單招職業(yè)適應(yīng)性測試題庫附答案
- 2025年度兒童游樂場主題包裝與品牌推廣合作協(xié)議書
- 2025年度個人公司資金走賬專項管理合同協(xié)議
- 腸內(nèi)營養(yǎng)考評標準終
- Mysql 8.0 OCP 1Z0-908 CN-total認證備考題庫(含答案)
- 三年級下冊音樂教學(xué)計劃含教學(xué)進度安排活動設(shè)計word表格版
- STEM教學(xué)設(shè)計與實施PPT完整全套教學(xué)課件
- 門窗加工制作合同
- 項目邊坡護坡工程施工組織設(shè)計
- 2023年全國各省高考詩歌鑒賞真題匯總及解析
- 四年級上冊音樂《楊柳青》課件PPT
- 安徽省廬陽區(qū)小升初語文試卷含答案
- 全國2017年4月自考00043經(jīng)濟法概論(財經(jīng)類)試題及答案
- 蘇教版六年級數(shù)學(xué)下冊《解決問題的策略2》優(yōu)質(zhì)教案
評論
0/150
提交評論