Home > other >  Does array like function exist in SQL
Does array like function exist in SQL

Time:06-24

Using SQL I would like to know if its possible to do the following:

If I have a variable that the user inputs mutiple strings into seperated by a comma for example ('aa','bbb','c','dfd'), is it possible using LIKE with a wilcard at the end of each string in stead of having the user to enter each variations in multiple macros.

So say if user was looking for employee numbers that start with ('F','E','C') is it possible without using OR statements is the question I guess am asking?

It would be similar to that of an array I guess

CodePudding user response:

No, LIKE is its own operator and therefore needs separated by an OR.

You might prefer ILIKE to LIKE, as it is a case-insensitive comparison.

You can also try to use REGEXP_LIKE, which is similar to what you want, except you'll have to use regex expressions instead of 'FEC%'

CodePudding user response:

That depends on your SQL dialect; I don't know Impala at all, but other SQL engines have support for regular expressions in string matches, so that you can build a query string like

SELECT fld FROM tbl WHERE fld REGEXP '^[FEC].*$';

No matter what you do, you will need to build a query from your user's input. Passing through user input unprocessed into your SQL processor is a big "nope" anyways, from a "don't accidentally delete a table" point of view:

Her daughter is named Help I'm trapped in a driver's license factory.
  • Related