在项目的
PLSQL
部分中,第一次接触了内存表的概念,类似于
C
编程语言的数组,以前一直在找
PLSQL
中
COLLECITION
的概念。
1.
内存表
概念:
PL/SQL
表类似于
C
语言中的数组。如果要声明一个
PL/SQL
表,要先定义该表类型,然后在声明属于该类型的变量。内存表和物理表是相同的,可以把物理表中的数据完全拷贝到内存表中。表中的元素不是存储在连续的内存中。
声明内存表:
TYPE T_USRID_ARRAY IS TABLE OF TF_F_USRARCH_MAIN.USRID%TYPE INDEX BY BINARY_INTEGER;
G_USERID T_USRID_ARRAY;
我们也可以定义表类型为一个表的所有字段,例如:
TYPE T_USRREC IS RECORD(usrid tf_f_usrarch_main.usrid%TYPE,
mphonecode tf_f_usrarch_main.mphonecode%TYPE,
citycode tf_f_usrarch_main.citycode%TYPE,
servicecode tf_f_usrarch_main.servicecode%TYPE,
opendate tf_f_usrarch_main.opendate%TYPE,
firststoptime tf_f_usrarch_main.firststoptime%TYPE,
usrstatecodeset tf_f_usrarch_main.usrstatecodeset%TYPE,
utag3 tf_f_usrarch_main.utag3%TYPE,
callrankcode tf_f_usrarch_main.callrankcode%TYPE,
roamrankcode tf_f_usrarch_main.roamrankcode%TYPE,
advancepay tf_f_usrarch_main.advancepay%TYPE,
ureservvalue tf_f_usrarch_main.ureservvalue%TYPE,
creditfactor5 tf_f_usrarch_main.creditfactor5%TYPE);
mphonecode tf_f_usrarch_main.mphonecode%TYPE,
citycode tf_f_usrarch_main.citycode%TYPE,
servicecode tf_f_usrarch_main.servicecode%TYPE,
opendate tf_f_usrarch_main.opendate%TYPE,
firststoptime tf_f_usrarch_main.firststoptime%TYPE,
usrstatecodeset tf_f_usrarch_main.usrstatecodeset%TYPE,
utag3 tf_f_usrarch_main.utag3%TYPE,
callrankcode tf_f_usrarch_main.callrankcode%TYPE,
roamrankcode tf_f_usrarch_main.roamrankcode%TYPE,
advancepay tf_f_usrarch_main.advancepay%TYPE,
ureservvalue tf_f_usrarch_main.ureservvalue%TYPE,
creditfactor5 tf_f_usrarch_main.creditfactor5%TYPE);
定义表类型
TYPE T_USRREC_ARRAY IS TABLE OF T_USRREC INDEX BY BINARY_INTEGER;
G_USERID T_USRREC_ARRAY;
TYPE T_USRREC_ARRAY IS TABLE OF T_USRREC INDEX BY BINARY_INTEGER;
G_USERID T_USRREC_ARRAY;
表的属性
和操作
:
count:返回PL/SQL表中行的当前数目。
delete:删除表中的行。
exists:如果指定的表项在表中存在那么返回ture。
first:返回表中第一行的索引。
last:返回表中最后一行的索引。
next:返回表中指定行的下一行的索引。
prior:返回表中指定行的上一行的索引
count:返回PL/SQL表中行的当前数目。
delete:删除表中的行。
exists:如果指定的表项在表中存在那么返回ture。
first:返回表中第一行的索引。
last:返回表中最后一行的索引。
next:返回表中指定行的下一行的索引。
prior:返回表中指定行的上一行的索引