![](/img/trans.png)
[英]Oracle: How to call a stored procedure within a stored procedure with if-condition
[英]Call stored procedure with string variable inside IN condition
您好,低於 SP,對於單個值運行良好,例如 PARMPROFILES=wervbcjjlj
create or replace procedure OneView_Rpt_Get_Profile(PARMPROFILES varchar2,
out_curResults OUT sys_refcursor) is
begin
OPEN out_curResults FOR
select
upper(concat(concat(first_name, ' '), last_name)) User_Name,
ul.user_id as User_ID,
ul.Email_Id as EmailAddress,
p.profile_name as profilename,
upper(concat(concat(PW.OWNER_FIRST_NAME, ' '), PW.OWNER_LAST_NAME)) as OwnerName,
PU.ADDED_DATE
from User_List UL
join Profile_User PU on UL.USER_KEY = PU.USER_KEY
join Profile_Owner PW on PW.PROFILE_KEY = PU.PROFILE_KEY and PW.ACTIVE='Y'
join Profile p on p.profile_key= pu.profile_key
where 1=1
AND UL.GU_ID IS NOT NULL
and ul.active_flag = 'Y'
and p.profile_name in (PARMPROFILES );
end OneView_Rpt_Get_Profile;
但我想在 PARMPROFILES 中傳遞多個值。 我只運行具有多個值的簡單查詢,它運行良好
select
upper(concat(concat(first_name, ' '), last_name)) User_Name,
ul.user_id as User_ID,
ul.Email_Id as EmailAddress,
p.profile_name as profilename,
upper(concat(concat(PW.OWNER_FIRST_NAME, ' '), PW.OWNER_LAST_NAME)) as OwnerName,
PU.ADDED_DATE
from User_List UL
join Profile_User PU on UL.USER_KEY = PU.USER_KEY
join Profile_Owner PW on PW.PROFILE_KEY = PU.PROFILE_KEY and PW.ACTIVE='Y'
join Profile p on p.profile_key= pu.profile_key
where 1=1
AND UL.GU_ID IS NOT NULL
and ul.active_flag = 'Y'
and p.profile_name in ('wervbcjjlj','test_shub_prt' )
不確定如何在 SP 中傳遞多個值。 請指教 !!
一種選擇是將輸入的逗號分隔值拆分為行(第 9 - 11 行)並將其用作子查詢。
這是 function 的示例(為簡單起見):
SQL> create or replace function f_test (par_in in varchar2)
2 return sys_refcursor
3 is
4 l_rc sys_refcursor;
5 begin
6 open l_rc for
7 select empno, ename, job, sal
8 from emp
9 where job in (select regexp_substr(par_in, '[^,]+', 1, level)
10 from dual
11 connect by level <= regexp_count(par_in, ',') + 1
12 );
13 return l_rc;
14 end;
15 /
Function created.
SQL> select f_test('MANAGER,CLERK') from dual;
F_TEST('MANAGER,CLER
--------------------
CURSOR STATEMENT : 1
CURSOR STATEMENT : 1
EMPNO ENAME JOB SAL
---------- ---------- --------- ----------
7369 SMITH CLERK 1000
7566 JONES MANAGER 2975
7698 BLAKE MANAGER 2850
7782 CLARK MANAGER 2450
7876 ADAMS CLERK 1100
7900 JAMES CLERK 950
7934 MILLER CLERK 1300
7 rows selected.
SQL>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.