PL/SQL query IN comma deliminated string

前端 未结 10 2174
攒了一身酷
攒了一身酷 2021-01-02 04:46

I am developing an application in Oracle APEX. I have a string with user id\'s that is comma deliminated which looks like this,

45,4932,20,19
10条回答
  •  南方客
    南方客 (楼主)
    2021-01-02 05:31

    I have faced this situation several times and here is what i've used:

    SELECT * 
      FROM users u 
     WHERE ','||to_char(:P5_USER_ID_LIST)||',' like '%,'||to_char(u.user_id)||',%'
    

    ive used the like operator but you must be a little carefull of one aspect here: your item P5_USER_ID_LIST must be ",45,4932,20,19," so that like will compare with an exact number "',45,'".

    When using it like this, the select will not mistake lets say : 5 with 15, 155, 55.

    Try it out and let me know how it goes;)

    Cheers , Alex

提交回复
热议问题