简体   繁体   中英

How to pass an array of numbers to Oracle stored procedure?

To pass an array of number to oracle stored procedure, I created a type like this:

create or replace type wareconfig_array as table of NUMBER;

Then I created my procedure like this, when I compile, it shows success, then I pass an array like: [1,2] to m_array when I run it, it throws an error: "ORA-06531:Reference to uninitialized collection" Can you tell me what I did wrong? Thanks very much!

create or replace procedure delete_waregroup(m_array in wareconfig_array) is
begin
  for i in 1..m_array.count loop
      update "warehouse_group" set "deleted"=1 where "id"=m_array(i);
  end loop;
  commit;
EXCEPTION
   when others THEN
        save_proc_error('proc',sqlcode,'删除仓库组信息发生异常!',sqlerrm);
        raise_application_error(-20003,'数据操作异常!异常编码:'|| sqlcode || '异常描述:'|| sqlerrm||dbms_utility.format_error_backtrace());
        rollback; ---回滚
end delete_waregroup;

Try:

declare 
   x wareconfig_array;
begin
  x := wareconfig_array(1,3); -- initialize an array and fill it with values
  delete_waregroup( x );
end;
/

live (working) demo: http://sqlfiddle.com/#!4/af403e/1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM