• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Oracle 中的表变量(数组变量)

mysql 搞代码 4年前 (2022-01-09) 13次浏览 已收录 0个评论

该程序定义了名为tabletype1的多维表类型,相当于多维数组,table1是多维表类型变量,将数据表tempuser.testtable中recordnumber

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

其定义语法如下:

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

表变量名 表类型;

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

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

本文来源gao!%daima.com搞$代*!码9网(

引可以是不连续的,而且与数据库表不同

不能在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等属性进行操作,使用方法为“表变量名.属性”,返回的是数字。


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Oracle 中的表变量(数组变量)
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址