【问题标题】:How to test PL/SQL procedure with varray input如何使用可变数组输入测试 PL/SQL 过程
【发布时间】:2021-07-30 09:10:33
【问题描述】:

我已经制作了一个使用可变数组作为输入的过程,虽然一切都正确编译,但我无法弄清楚如何准确地测试/执行实际工作的过程。 varray 至少有两个值:第一个是事件 ID (eid),之后是人员 ID (pid)。两者都是最多 38 位的数字。

我习惯在结尾有一个语句,比如 exec event_attendees(3,9);工作正常,但它给了我一个错误。

我想制作不同的测试用例,以确保每个 if/else 部分都能正常工作(一个带有无效的 eid,一个带有无效的 pid,一个带有 eid 和 pid 组合已经是表格的一部分,以及一个应该不会导致错误)。为什么我尝试的 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;

【问题讨论】:

    标签: sql testing plsql procedure


    【解决方案1】:

    您需要先构造一个 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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-26
      • 1970-01-01
      • 2020-08-14
      • 1970-01-01
      • 2015-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多