在declare中我一般是这样使用type
declare
type test_record is record(
name varchar2(100)
);
type test_table is table of test_record index by binary_integer;
test_table1 test_table;
begin
select 'name1' into test_table1(1).name from dual;
select 'name2' into test_table1(2).name from dual;
dbms_output.put_line( test_table1(1).name);
dbms_output.put_line( test_table1(2).name);
end;
但是因为要用在这次需求原因,我想将这个自定义的test_table1当做OUT参数在存储过程中返回,就遇到了几个问题
1. 在创建的时候不能用index by binary_integer ;
2.在使用的时候会出现ORA-06530
之类的问题。最后的解决方式是在这位大神这里找到的
他的博客链接:http://blog.itpub.net/12932950/viewspace-668712/
create or replace type typ_info as object
(
name varchar2(10),
sex varchar2(1)
);
create or replace type typ_infos as table of typ_info;
declare
v_infos typ_infos := typ_infos(); --初始化
begin
v_infos.extend; --扩大空间
v_infos(1) := typ_info(null, null); --初始化创建的type
v_infos(1).name := 'lyon';
v_infos(1).sex := 'M';
v_infos.extend; --扩大空间
v_infos(2) := typ_info(null, null);--初始化创建的type
v_infos(2).name := 'lyon';
v_infos(2).sex := 'M';
end;
放置在存储过程中就是
create or replace procedure testtype(v_infos out typ_infos) as
begin
v_infos := typ_infos();
v_infos.extend; --扩充空间;
v_infos(1) := typ_info(null, null); --初始化值
v_infos(1).name := 'name1';
---
--当然在这里你也可以写成
-- v_infos(1) := typ_info(null, null); --初始化值
-- v_infos(1).name := 'name1';
-- 将上面两步写成一步
-- v_infos(1) :=typ_info('name1',null);
v_infos.extend;
v_infos(2) := typ_info(null, null);
v_infos(2).name := 'name';
for var in 1 ..v_infos.count loop
dbms_output.put_line(v_infos(var).name);
end loop;
end testtype;
搞定睡觉,感谢大神们的博客对我们这些菜鸡的指引,哈哈哈哈谢谢谢谢。