oracle命令参数数组,Oracle Procedure 数组参数的应用

因工作需要,数据库由PostgreSQL 转为Oracle 10g。由于之前的逻辑几乎都分布于存储过程,所以多代码的修改相对来说较小。

因对Oracle 数组参数的转换花了些时间,所以记录下来,分享一下。言归正传:

如果入参为字符串数组、整形数组或者GUID数组等等,并且把它作为一个查询条件,有两种方法可以做到。我采用了package,后面将介绍原因。

方法一:

在存储过程中使用for,相信大家对此应该不陌生。上例子:

create or replace package sbp_disablesyncpreset

as

type string_array is table of raw(16) index by binary_integer;

procedure disablesyncpreset(sync_computers in string_array, active_presets in string_array);

end sbp_disablesyncpreset;

Commit;

create or replace package body sbp_disablesyncpreset

as

procedure disablesyncpreset(sync_computers in string_array, active_presets in string_array)

as

begin

FOR i IN sync_computers.FIRST .. sync_computers.LAST

LOOP

UPDATE sparesync_last_sync SET preset_active='0'

WHERE

((destination_guid=sync_computers(i)) OR (src_guid=sync_computers(i))) AND (NOT preset_id=active_presets(i));

END LOOP;

end disablesyncpreset;

end sbp_disablesyncpreset;

Commit;

方法二:使用自己定义的全局数组类型,上例子:

create or replace package sbp_disablesyncpreset

as

type string_array is table of raw(16) index by binary_integer; //定义数组类型,与入参一致

procedure disablesyncpreset(sync_computers in string_array);//存贮过程名称

end sbp_disablesyncpreset;

Commit;

//主体部分

create or replace package body sbp_disablesyncpreset

as

procedure disablesyncpreset(sync_computers in string_array)

as

computerguids spu_nested_type20 := spu_nested_type20(); //自己定义的全局数组类型

begin

FOR i IN computerid.first..computerid.last loop

computerguids.extend;

computerguids(i) := computerid(i);

end loop;

UPDATE sparesync_last_sync SET preset_active='0'

WHERE

destination_guid in (select column_value from table(Cast(computerguids as spu_nested_type20)))

OR src_gui

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值