0

Unable to append string arrays with SQL in operator dynamically. If more values are passed to the array dynamically, how to append it within operator in Oracle SQL query?

    String[] rsIdArr = dObj.getRsId().split(",");
    int length = rsIdArr.length;

    for(int k=0; k<length; k++){
        String appendArr[] = new String[k];
         appendArr[k] =  "'"+rsIdArr[k]+"'" ;
         if(ValidationUtil.isValid(dObj.getRsId())){
             strQuery  = strQuery.append("AND TAppr.RS_ID IN " + appendArr[k] );
         }

    }

Expected result:

AND tappr.rs_id IN ('W0079', 'F002', 'P002159', 'D0701', ........)

heiwil
  • 612
  • 4
  • 8

1 Answers1

-1

Not sure why are you creating another array inside the for loop. From the looks of it, this is what you need -

    String[] rsIdArr = dObj.getRsId().split(",");
    strQuery.append("AND TAppr.RS_ID IN (");
    for(int k=0; k< rsIdArr.length; k++){
        String id = rsIdArr[k];
        if (ValidationUtil.isValid(id)) {
           strQuery.append("'" + id + "'" );
        }
    }
    strQuery.append(")");
Anand Mattikopp
  • 332
  • 2
  • 11