如何使用 varray 输入测试 PL/SQL 过程
How to test PL/SQL procedure with varray input
我制作了一个使用 varray 作为输入的过程,虽然一切都可以正确编译,但我无法弄清楚如何 test/execute 实际工作的过程。
varray 至少有两个值:第一个是事件 ID (eid),后面的任何其他值是人员 ID (pid)。两者都是最多 38 位的数字。
我已经习惯了在最后有一个语句,比如 exec event_attendees(3,9);工作正常,但它给了我一个错误。
我想制作不同的测试用例以确保每个 if/else 部分都能正常工作(一个具有无效的 eid,一个具有无效的 pid,一个具有 eid 和 pid 组合已经是table 和一个应该不会导致错误的)。为什么我尝试的 exec 语句不起作用,我如何在我的 varray 中测试多个不同的值?
这是我目前拥有的:
set serveroutput on;
create or replace type pe_varray as varray(10) of number(38);
/
create or replace procedure event_attendees(combo pe_varray)
is
eid_valid_check int;
pid_valid_check int;
combo_exist_check int;
begin
select count(*) into eid_valid_check from event where eid = combo(1);
if eid_valid_check = 0 then
dbms_output.put_line('Event does not exist');
else
for i in 2..combo.count loop
select count(*) into pid_valid_check from people where pid = combo(i);
if pid_valid_check = 0 then
dbms_output.put_line('Person does not exist');
else
select count(*) into combo_exist_check from Person_Event where eid = combo(1) and pid = combo(i);
if combo_exist_check > 0 then
dbms_output.put_line('No need to insert');
else
insert into Person_Event values(combo(1), combo(i));
dbms_output.put_line('Attendee(s) for event with id ' || combo(1) || ' added');
end if;
end if;
end loop;
end if;
end;
您需要先构建一个VARRAY。您可以使用不同的值重新构建它并重新调用您的存储过程。
请尝试以下操作。
declare
l_param pe_varray;
begin
l_param := pe_varray(3, 9);
event_attendees(l_param);
l_param := pe_varray(0, -5);
event_attendees(l_param);
end;
我制作了一个使用 varray 作为输入的过程,虽然一切都可以正确编译,但我无法弄清楚如何 test/execute 实际工作的过程。 varray 至少有两个值:第一个是事件 ID (eid),后面的任何其他值是人员 ID (pid)。两者都是最多 38 位的数字。
我已经习惯了在最后有一个语句,比如 exec event_attendees(3,9);工作正常,但它给了我一个错误。
我想制作不同的测试用例以确保每个 if/else 部分都能正常工作(一个具有无效的 eid,一个具有无效的 pid,一个具有 eid 和 pid 组合已经是table 和一个应该不会导致错误的)。为什么我尝试的 exec 语句不起作用,我如何在我的 varray 中测试多个不同的值?
这是我目前拥有的:
set serveroutput on;
create or replace type pe_varray as varray(10) of number(38);
/
create or replace procedure event_attendees(combo pe_varray)
is
eid_valid_check int;
pid_valid_check int;
combo_exist_check int;
begin
select count(*) into eid_valid_check from event where eid = combo(1);
if eid_valid_check = 0 then
dbms_output.put_line('Event does not exist');
else
for i in 2..combo.count loop
select count(*) into pid_valid_check from people where pid = combo(i);
if pid_valid_check = 0 then
dbms_output.put_line('Person does not exist');
else
select count(*) into combo_exist_check from Person_Event where eid = combo(1) and pid = combo(i);
if combo_exist_check > 0 then
dbms_output.put_line('No need to insert');
else
insert into Person_Event values(combo(1), combo(i));
dbms_output.put_line('Attendee(s) for event with id ' || combo(1) || ' added');
end if;
end if;
end loop;
end if;
end;
您需要先构建一个VARRAY。您可以使用不同的值重新构建它并重新调用您的存储过程。 请尝试以下操作。
declare
l_param pe_varray;
begin
l_param := pe_varray(3, 9);
event_attendees(l_param);
l_param := pe_varray(0, -5);
event_attendees(l_param);
end;