plsql中索引表(pls/ql表)的使用

 

pl/sql表,又称为索引表,在oracle9i以后就被称之为pl/sql表了。它是plsql语言数据类型中集合类型。Pl/sql是plsql所特有的、单维的、无容量限制的、离散的存储的列表结构。用于存储多行单列的数据。

语法:

Type <表类型名> is table of <数据类型> index by <索引的类型>;

<表变量名> <表类型名>;

注意:‘表类型名’是用户自己定义的,‘数据类型’是表中字段的数据类型 ,‘索引的类型’现在可以是binary_integer,varchar2。‘表变量名’也是用户自己定义的。

例1:

       我的oracle数据库中有这么一个表emp,

表中字段有empno(number型的),empname(varchar2型的)

 

declare
       type name_index is table of emp.empname%type index by binary_integer;
       names name_index;
       type charindex is table of emp.empname%type index by varchar2(10);
       names2 charindex;
       begin
       names(1):='love';
       names(2):='u';
       names2('girl'):='Nora';
       names2('boy'):='Alent';
       dbms_output.put_line(names(1));
       --dbms_output.put_line(names(3));
       dbms_output.new_line;
       dbms_output.put_line(names(2));
       dbms_output.put_line(names2('girl'));
       dbms_output.put_line(names2('boy'));
       end;

输出结果如下:

love

u
Nora
Alent

 

 

例2:

declare
       type name_index is table of emp.empname%type index by binary_integer;
       names name_index;
       type charindex is table of emp.empname%type index by varchar2(10);
       names2 charindex;
       begin
       select empname into names(1) from emp where empno=10;
       select empname into names2('name') from emp where empno=100;
       dbms_output.put_line(names(1));
       dbms_output.put_line(names2('name'));
       --dbms_output.put_line(names(3));
     
       end;


输出结果:

郭丽

Nora


 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值