首页 > 数据库 > Oracle > PL/SQL 索引表
索引表也叫做关联数组,不过和数组的区别就是没有上限,允许连续扩展,其作为索引的下标可以BINARYBINARY_INTEGER,PLS_ INTEGER,在Oracle 9i之后,下标可以为Varchar2。还有一点,作为下标的值可以使不连续的,但是不能重复,也就是说新扩展的值对应的下标值在之前是不存在的。唯一的缺点是不能作为一列存在于数据库中使用。
如下所示:
declare
type out_type is table of varchar2(50) index by binary_integer;
v_err out_type;
type type_ename is table of varchar2(50) index by binary_integer;
v_ename type_ename;
begin
for cur in (select empno from emp) loop
select ename,'输入信息测试' into v_ename(cur.empno),v_err(cur.empno) from emp where empno=cur.empno;
end loop;
for i in v_ename.first .. v_ename.last loop
dbms_output.put_line(v_ename(i));
end loop;
end;
执行的时候报如下错误:
ora-01403:未找到任何数据
ora-06512:在line 12
更改过之后如下:
declare
type out_type is table of varchar2(50) index by binary_integer;
v_err out_type;
type type_ename is table of varchar2(50) index by binary_integer;
v_ename type_ename;
begin
for cur in (select empno from emp) loop
select ename,'输入信息测试' into v_ename(cur.empno),v_err(cur.empno) from emp where empno=cur.empno;
dbms_output.put_line(v_ename(cur.empno)||'--'||v_err(cur.empno));
end loop;
end;
执行结果如下:
SMITH--输入信息测试
ALLEN--输入信息测试
WARD--输入信息测试
JONES--输入信息测试
MARTIN--输入信息测试
BLAKE--输入信息测试
CLARK--输入信息测试
KING--输入信息测试
TURNER--输入信息测试
JAMES--输入信息测试
FORD--输入信息测试
MILLER--输入信息测试
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22275400/viewspace-1794864/ ,如需转载,请注明出处,否则将追究法律责任。