新聞中心
我們大家都知道在Oracle里的變量主要有四種類型:即,數(shù)字型,字符型,以及引用型和復合型,其中,Oracle 復合類型包括,table 表與數(shù)組 array,table 的表又可分為, 1. 索引表 index table 2.嵌套表 nested table。

創(chuàng)新互聯(lián)堅持“要么做到,要么別承諾”的工作理念,服務領(lǐng)域包括:網(wǎng)站建設(shè)、網(wǎng)站設(shè)計、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣等服務,滿足客戶于互聯(lián)網(wǎng)時代的邵東網(wǎng)站設(shè)計、移動媒體設(shè)計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡建設(shè)合作伙伴!
一.索引表:
定義:(練習中表名均為 v_table)
type 索引表名 is table of 類型 index by binary_integer;
使用: 因為不能直接使用 索引表名 所以先定義個變量
- v_temptable_table v_table;
索引表的特點:
① 索引表中只有兩列
②只能放在內(nèi)存中
③不能使用DML 操作
④使用較簡單
索引表練習
declare
定義索引表
- type v_table is table of emp%rowtype index by binary_integer;
定義索引表變量
- v_emp v_table;
- cursor cur_emp is select * from emp;
- v_num number:=0;
- begin
把EMP中的每一條數(shù)據(jù)放入索引表中
- for v_e in cur_emp loop
- v_numv_num:=v_num+1;
- select * into v_emp(v_num) from emp where ename=v_e.ename;
- end loop;
輸出每一條記錄的名字
- for I in 1..v_emp.count loop
- dbms_output.put_line(v_emp(i).ename);
- end loop;
- end;
- /
二.嵌套表:
定義:(練習中表名均為v_nested)
type 表名 is table of 類型 ;
使用:定義變量并初始化
- v_my_nested v_nested := v_nested(‘a(chǎn)a’,’bb’);
特點:
1.可以使用DML 操作
2.使用前需要初始化
3.可用EXTEND方法擴展
練習:
- declare
- type v_nested is table of varchar2(20);
- v_my_nested v_nestedv_nested:=v_nested('aa','bb');初始化
- begin
- v_my_nested.extend(3);
- v_my_nested(5):='ee';
- end;
- /
三.數(shù)組:array
定義:
type 數(shù)組名 is varry(***下標值界限) of 類型 ;
注意:使用時先初始化,能使用DML 操作
- v_my_varry[100]:=v_varray('aa','bb');
- declare
定義數(shù)組***100上限
- type v_array is array(100) of emp.ename%type;
定義數(shù)組變量并開空間
- v_arr v_arrayv_array:=v_array();
- cursor cur_emp is select * from emp;
- v_num number:=0;
- begin
- v_arr.extend(100);
- for v_e in cur_emp loop
- v_numv_num:=v_num+1;
- select ename into v_arr(v_num) from emp where ename=v_e.ename;
- end loop;
- for I in 1..v_arr.count loop
- dbms_output.put_line(v_arr(i));end loop;
- end;
- /
四.Oracle 復合類型的方法:
關(guān)鍵字 extend 只用于嵌套表和數(shù)組中
count 用于計算長度
first 指向***個
extend 擴展空間個數(shù)
Last 指向***一個
exist 判斷是否存在 存在 is not null 不存在 is null
next 向下移
priev 向上移
delete(n) 刪除記錄(n可指定具體一行)
文章出自:http://www.programbbs.com/doc/4894.htm
【編輯推薦】
- 如何配置Oracle數(shù)據(jù)庫
- Oracle數(shù)據(jù)庫的四種基本的啟動方式
- 不為人知的Oracle控制文件重建
- OraclePL編程語言的優(yōu)點介紹
- Oracle控制文件如何高效管理
網(wǎng)頁名稱:Oracle 復合類型所包含的表有哪些
文章源于:http://www.fisionsoft.com.cn/article/cogdpoc.html


咨詢
建站咨詢
