Search code examples
plsqlora-01722

pl/sql using array elements in loop gives ORA-01722 error


I write below script and I get ORA-01722 error at line 8. How can I solve this error? thanks in advance.

declare 
  type array_t is varray(2) of VARCHAR2(20);
  array array_t := array_t('5634', '5764');

 begin

  for i in 1..array.count loop   
      execute immediate 'select t.musteri_id from tms.isemri t where t.isemri_tarihi  = (select max(t.isemri_tarihi) from tms.isemri t where t.hizmet_no = '|| 
      array(i)||') and t.hizmet_no ='|| array(i);   

  end loop;
  end;

Solution

  • execute immediate 'select t.musteri_id from tms.isemri t where t.isemri_tarihi = (select max(t.isemri_tarihi) from tms.isemri t where t.hizmet_no = '''|| array(i)||''') and t.hizmet_no ='''|| array(i)||'''';