oracle使用数组变量,Oracle 中的表变量(数组变量)

表类型变量又称index_by表或则PL/SQL表,和数据表是有区别的,是类似于数组的键和值的两列结构。

其定义语法如下:

type 表类型名 is table of 类型 index by binary_integer;

表变量名 表类型;

类型可以是number 、varchar2、date 等数据类型,index by binary_integer 子句代表以符号整数为索引,

这样访问表类型变量中的数据方法就是“表变量名(索引符号整数)”,注意与数组不同的是该索引可以是不连续的,而且与数据库表不同

不能在index-by 表中使用select、insert、update 等sql操作。

下面的程序定义了名为tabletype1和tabletype2的两个一维表类型,相当于一维数组。table1和table2分别是两种表类型变量。

Declare

type tabletype1 is table of varchar2(10) index by binary_integer;

type tabletype2 is table of  scott.testtable.recordnumber%type  index by binary_integer;

table1 tabletype1;

table2 tabletype2;

begin

table1(1):='大学';

table1(2):='大专';

table2(1):=88;

table2(2):=55;

dbms_output.put_line(table1(1)||table2(1));

dbms_output.put_line(table1(2)||table2(2));

end;

定义多维表类型变量 :

Declare

type tabletype1 is table of testtable%rowtype index by binary_integer;

table1 tabletype1;

begin

select * into table1(60)

from scott.testtable

where recordnumber=60;

dbms_output.put_line(table1(60).recordnumber||'  '||table1(60).currentdate);

end;

该程序定义了名为tabletype1的多维表类型,相当于多维数组,table1是多维表类型变量,将数据表tempuser.testtable中recordnumber为60的记录提取出来存放在table1中并显示

在定义好的表类型变量里,可以使用count、delete、first、last、next、exists和prior等属性进行操作,使用方法为“表变量名.属性”,返回的是数字。0b1331709591d260c1c78e86d0c51c18.png

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值