2

I have a query where I am using regex_like, and I need more than one parameter, something like this:

WHERE regexp_like (FILENAME,'_G_',) or (FILENAME,'_Z_',) or (FILENAME,'_M_',)

Thanks in advance

1
  • You would need multiple conditions to do this with like, but regexp_like lets you use a regular expression which is a more flexible type of search pattern. Commented Jan 18, 2020 at 19:56

3 Answers 3

3

You can factorize the regexp as follows:

WHERE regexp_like (FILENAME,'_[GMZ]_',)

[GMZ] represents a custom character class made of characters 'G', 'M' and 'Z'.

Sign up to request clarification or add additional context in comments.

Comments

1

You can use the following regexp:

regexp_like (FILENAME,'.{1}[GZM]{1}.{1}')
  • Here . (dot) represents any character
  • {1} represents only 1 character is allowed for the preceding pattern.

Cheers!!

3 Comments

There is actually no need for the {1} quantifier here, it is implicit when not specified. Also, '_' (a litteral underscore) and . (any character) are two different things.
Yes, I know about _ and . but I think OP is comparing LIKE and REGEXP_LIKE. In LIKE underscore _ means any character so I used .
Thank you so much and can i order by the it , like : Parameter Year sell N 2009 444 G 2009 555 M 2009 6666 F 2010 77
0

If you want to add two or more different parameters, that do not have a lots in common, then you can use | to separate them like this:

select * 
from table_name 
WHERE regexp_like (FILENAME,'_G_|-kk_|-AH-');

Here is a small DEMO

Do not know what exactly you want when you ask to "order by it" but try this:

select id, filename
from table_name 
WHERE regexp_like (FILENAME,'_G_|-kk_|-AH-')
order by filename

1 Comment

Thank you so much for ur very fast answer Thank you so much and can i order by the it , like : Parameter Year sell N 2009 444 G 2009 555 M 2009 6666 F 2010 77

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.