如何接收过程为table类型的输出参数

billlyh 2014-08-20 09:20:00
建表语句:
create table employee is(
id number not null,
name varchar2(20) not null,
salary number not null
);

表插入值语句:
declare

begin
for i in 1..10 loop
insert into employee(id,name,salary) values(i,i,i);
end loop;

end;


create or replace package my_package is
type my_record is record is(
id employee.id%type,
name employee.name%type,
salary employee.salary%type,
);
type my_table is table of my_record index by binary_integer;
procedure pro_test(p_rec out my_table);
end my_package ;

create or replace package body my_package is
procedure pro_test(p_rec out my_table);
begin
for i in 1..10 loop
p_rec(i).id:=i;
p_rec(i).name:=i;
p_rec(i).salary=i;
insert into employee(id,name,salary) values (p_rec(i).id,p_rec(i).name,p_rec(i).salary);
dbms_output.put_line('id is: '||p_rec(i).id,);
end loop;
commit;
end pro_test;
end my_package ;
这个包可以正常编译,(如果你copy这个包的代码编译有错,那是我在家里电脑敲错了,在公司电脑可以正常编译)
我是pl/sql中调用这个过程,报错

declare
type my_record2 is record is(
id employee.id%type,
name employee.name%type,
salary employee.salary%type,
);
type my_table2 is table of my_record2 index by binary_integer;
begin
my_package.p_rec(my_table2);
/*
for i in 1..10 loop
y_package.p_rec(my_table2(i));
end loop;
*/
end;

哪位帮帮我啊????
...全文
310 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
小灰狼W 2014-08-22
  • 打赏
  • 举报
回复
这里贴出来的代码到处是错误,又说真实代码不是这样。这是让别人帮忙找问题呢,还是误导 你要别人认真帮你,提问同样不要含糊 包里定义的存储过程的传入参数那里,要求的类型是my_table 而执行的时候,传入的参数类型是my_table2 。虽然实际上是一样的,但属于不同的类型 因此执行的时候,不应该再去定义一个my_table2,而是直接定义: t2 my_package.my_table;
CT_LXL 2014-08-21
  • 打赏
  • 举报
回复
引用 5 楼 billlyh 的回复:
declare type my_record2 is record is( id employee.id%type, name employee.name%type, salary employee.salary%type, ); type my_table2 is table of my_record2 index by binary_integer; t2 my_table2 begin my_package.p_rec(t2); end; 我在公司电脑的是这样的,
如果行不通的话,建议你用ref游标或者先建立type对象来实现
bw555 2014-08-21
  • 打赏
  • 举报
回复
用这个类型,重新定义变量,下面都使用变量应该就可以了
declare
    type my_record2 is record is(
    id employee.id%type,
    name employee.name%type,
    salary employee.salary%type,
 );
 type my_table2 is table of my_record2 index by binary_integer; 
 v_table  my_table2;
begin
    my_package.p_rec(v_table);

end;
billlyh 2014-08-21
  • 打赏
  • 举报
回复
declare type my_record2 is record is( id employee.id%type, name employee.name%type, salary employee.salary%type, ); type my_table2 is table of my_record2 index by binary_integer; t2 my_table2 begin my_package.p_rec(t2); end; 我在公司电脑的是这样的,
billlyh 2014-08-21
  • 打赏
  • 举报
回复
引用 2 楼 bw555 的回复:
用这个类型,重新定义变量,下面都使用变量应该就可以了
declare
    type my_record2 is record is(
    id employee.id%type,
    name employee.name%type,
    salary employee.salary%type,
 );
 type my_table2 is table of my_record2 index by binary_integer; 
 v_table  my_table2;
begin
    my_package.p_rec(v_table);

end;
我在公司电脑的是这样的 ,涅磐重生NPCS 你可以试试,会报错的,
billlyh 2014-08-21
  • 打赏
  • 举报
回复
引用 1 楼 wildwave 的回复:
my_table2在你的过程中是一个类型,而不是一个变量。就像你定义一个字符串,可以用varchar类型的变量a,而不能直接用varchar拿去传参
那是我在家里电脑敲错了,少了一句 t2 my_table2 ; type my_table2 is table of my_record2 index by binary_integer; begin my_package.p_rec(t2 ); end; 我在公司电脑的是这样的
小灰狼W 2014-08-20
  • 打赏
  • 举报
回复
my_table2在你的过程中是一个类型,而不是一个变量。就像你定义一个字符串,可以用varchar类型的变量a,而不能直接用varchar拿去传参

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧