Sending an array of values to Oracle procedure to use in WHERE IN clause

后端 未结 3 1731
时光说笑
时光说笑 2020-11-27 23:27

I have a stored procedure in Oracle as shown below:

CREATE PROCEDURE MY_TEST_PROC(
  CUR OUT SYS_REFCURSOR,
  PARAM_THAT_WILL_BE _USED_INSIDE_WHERE_IN
)
AS
B         


        
3条回答
  •  醉酒成梦
    2020-11-27 23:44

    You can add this comma separated input parameter as a varchar() and use following where statement:

    where (','||PARAM_THAT_WILL_BE||',' like '%,'||COL1||',%')
    

    for example if PARAM_THAT_WILL_BE='2,3,4,5' and col1=3 we get:

    where (',2,3,4,5,' like '%,3,%') 
    

    and it's TRUE if COL1 value is in this list. Here you don't use a dynamic query so you avoid concerns 1) and 2).

提交回复
热议问题