Dynamic 'LIKE' Statement in SQL (Oracle) Dynamic 'LIKE' Statement in SQL (Oracle) oracle oracle

Dynamic 'LIKE' Statement in SQL (Oracle)


You can use the CONCAT() function:

SELECT * FROM MATERIALS WHERE longname LIKE CONCAT(shortname, '%')

or even better, the standard || (double pipe) operator:

SELECT * FROM MATERIALS WHERE longname LIKE (shortname || '%')

Oracle's CONCAT() function does not take more than 2 arguments so one would use the cumbersome CONCAT(CONCAT(a, b), c) while with the operator it's the simple: a || b || c


CONCAT() is probably the most technically correct.

For convenience, however, ORACLE does have an equivalent operator to +...

SELECT * FROM MATERIALS WHERE longname LIKE (shortname || '%')