oracle cursor参数作为集合

时间:2017-06-27 08:35:26

标签: sql oracle plsql

它的工作原理如下:

DECLARE
rc SYS_REFCURSOR;
 BEGIN
victom.back_end_proc2(:rc );
END;

调用程序时:

 DATA
    27.06.2017 11:25:02
    26.06.2017 11:25:02

将有一个输出行:

using 'a','b'

问题是:

如何将'a','b'参数修改为一个数组或某些包含public static Process GetParentProcess(Process process) { string query = "SELECT ParentProcessId FROM Win32_Process WHERE ProcessId = " + process.Id; using (ManagementObjectSearcher mos = new ManagementObjectSearcher(query)) { foreach (ManagementObject mo in mos.Get()) { if (mo["ParentProcessId"] != null) { try { var id = Convert.ToInt32(mo["ParentProcessId"]); return Process.GetProcessById(id); } catch { } } } } return null; } 的集合数据作为一个字符串或smth像一个单独的值?

1 个答案:

答案 0 :(得分:0)

如果你的目标查询看起来像这样......

select * from whatever
where id in ( .... )

传递一个集合会非常简单。

create or replace type tt1 as table of varchar2(1);
/

create or replace procedure back_end_proc(
     p_ids in tt1
     , p_rc OUT SYS_REFCURSOR) is
begin
     open p_rc for 
         'select * from whatever
          where id member of :1'
         using p_ids;
end;

但是,您发布的案例稍微复杂一些,因为您希望在每个子查询中分配集合中的特定值。这意味着您需要使用VARRAY,因为这是唯一保证排序的集合类型。所以:

create or replace type va1 as varray(10) of varchar2(1);
/

create or replace procedure back_end_proc(
     p_ids in va1
     , p_rc OUT SYS_REFCURSOR) is
begin
     open p_rc for 
         'select sysdate from dual where ''a'' = :1
          union all
          select sysdate-1 from dual where ''b'' = :2' 
         using p_ids(1), p_ids(2);
end;