Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass Comma Separated String to IN clause in stored procedure

I am having comma seperated String and i am passing this comma seperated to oracle stored procedure. Now how to handle this string in cursor to IN clause.

String codes = "ABCD','EEFF','GGHH";

And cursor query is like

    CURSOR cur_bill_cod
   IS
      SELECT a.*
  FROM bill_codes a
 WHERE a.code in (p_codes)  ;

I declared p_codes as varchar in procedure.

But it is not fetching records. I tried string passing in another way as

String codes = "ABCD,EEFF,GGHH";

But in both the ways it failing and it is not throwing any exception. Could you please help me out on this.

like image 946
Sarvesh V Avatar asked Nov 20 '25 13:11

Sarvesh V


1 Answers

Try to use:

CURSOR cur_bill_cod
   IS
      SELECT a.*
  FROM bill_codes a
 WHERE a.code in (  
            SELECT CAST (TRIM (REGEXP_SUBSTR (p_codes,
                                '[^,]+',
                                1,
                                LEVEL)) AS VARCHAR2 (30))
                    codes
                FROM DUAL
            CONNECT BY LEVEL <= REGEXP_COUNT (p_codes, ',') + 1) 
like image 83
IRomanov Avatar answered Nov 23 '25 02:11

IRomanov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!