Welcome 微信登录

首页 / 数据库 / MySQL / 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分别是两种表类型变量。Declaretype 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;begintable1(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;定义多维表类型变量 :Declaretype tabletype1 is table of testtable%rowtype index by binary_integer;table1 tabletype1;beginselect * into table1(60)from scott.testtablewhere 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等属性进行操作,使用方法为“表变量名.属性”,返回的是数字。Oracle SQL 时间查询执行Commit时Oracle做哪些工作相关资讯      oracle 
  • [INS-32052] Oracle基目录和Oracle  (07/22/2014 07:41:41)
  • Oracle 4个大对象(lobs)数据类型  (02/03/2013 12:33:05)
  • Oracle按时间段分组统计  (07/26/2012 10:36:48)
  • [Oracle] dbms_metadata.get_ddl的  (07/12/2013 07:37:30)
  • Liferay Portal 配置使用Oracle和  (07/31/2012 20:07:18)
  • Concurrent Request:Inactive   (07/20/2012 07:44:05)
本文评论 查看全部评论 (0)
表情: 姓名: 字数