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
相关文档:
Checking kernel parameters
Checking for semmsl=250; found semmsl=250. Passed
Checking for semmns=32000; found semmns=32000. Passed
Checking for semopm=100; found semopm=32. Failed <<<<
Checking for semmni=128; found semmni=128.&nb ......
update customers a
set city_name=(select b.city_name from tmp_cust_city b where b.customer_id=a.customer_id)
where exists (select 1
from ......
[精华] ORACLE的几种启动方式
http://www.chinaunix.net 作者:wuwenlong 发表于:2003-07-27 16:58:57
【发表评论】 【查看原文】 【Oracle讨论区】【关闭】
1、startup nomount
非安装启动,这种方式启动下可执行:重建控制文件、重建数据库
读取 ......
oracle常用经典SQL查询
常用SQL查询:
1、查看表空间的名称及大小
select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_size
from dba_tablespaces t, dba_data_files d
where t.tablespace_name = d.tablespace_name
group by t.tablespace_name;
2、查看表空间物理文件的名称 ......
17:00:59 SQL> desc dbms_random;
Element Type
---------- ---------
SEED PROCEDURE
VALUE FUNCTION
NORMAL FUNCTION
STRING FUNCT ......