0

Is it possible to use LIKE inside an IN? The following query produces an error.

    Select * 
    from employees
    where salary between 2500 and 10000
    and job_id NOT in (like '%MAN%', like '%CLERK%');

What is the correct syntax? I'm using Oracle 11g

Ben
  • 50,172
  • 36
  • 122
  • 141

2 Answers2

4

You can't do both 'like' and 'in' at the time, but you can do this

    Select * 
      from employees
     where salary between 2500 
       and 10000
       and job_id NOT like '%MAN%' 
       and job_id NOT like '%CLERK%';
GitaarLAB
  • 14,134
  • 11
  • 55
  • 76
Elfentech
  • 747
  • 5
  • 10
3

Unfortunately, there is no "in like" operator. You could break it up to a series of LIKE conditions like @Elfentech suggested, or you could emulate it with the REGEXP_LIKE function:

SELECT *
FROM   employees
WHERE  salary BETWEEN 2500 AND 10000
AND    NOT REGEXP_LIKE (job_id, '.*[MAN|CLERK].*')

Alternatively, you could join on a bunch of UNION ALL queries from dual:

SELECT *
FROM  employees
JOIN  (SELECT 'MAN' AS search FROM dual 
       UNION ALL
       SELECT 'CLERK' FROM dual) jobs 
ON    employee.jod_id LIKE CONCAT ('%', jobs.search, '%')
WHERE salary BETWEEN 2500 AND 10000
Adi Inbar
  • 11,603
  • 13
  • 53
  • 68
Mureinik
  • 277,661
  • 50
  • 283
  • 320