您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Oracle编写带数组参数的存储过程

2025/3/14 19:03:13发布72次查看
--功能:采用存储过程、type组合来实现批量操作,以节省系统开销,提高效率。 --创建 type bodies create or replace ty
--功能:采用存储过程、type组合来实现批量操作,以节省系统开销,提高效率。
--创建 type bodies 
create or replace type type_array as object 

  id    number(10), 
  remark varchar2(10) 

--创建 types 
create or replace type type_array_tbl as table of type_array 
--创建表 
create table t_temp(id number(10) not null, remark number(10)) 
--创建存储过程 
 create or replace procedure proc_array_param(type_object in type_array_tbl) is
begin
  insert into t_temp
    (id, remark)
    select id, remark
      from the (select cast(type_object as type_array_tbl) from dual);
for i in 1 .. type_object.count loop
    delete from t_temp where id = to_number(type_object(i));
  end loop;
  commit;
 end;
end proc_array_param;
--创建包 
create or replace package pkg_param as 
  type array_params is table of varchar2(20) index by binary_integer; --先定义包,这个就相当于一个数组 
  procedure proc_param(params in array_params); 
end pkg_param; 
--创建包体 
create or replace package body pkg_param as 
  procedure proc_param(params in array_params) as 
    i number := 1; --这个可以不写 
  begin 
    savepoint sp1; 
    for i in 1 .. params.count loop 
      delete from t_temp where id = to_number(params(i)); 
    end loop; 
    commit; 
  exception 
    when others then 
      rollback to savepoint sp1; 
  end proc_param; 
end pkg_param;

该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product