1

I'm attempting to retrieve all rows that include two specific characters within a set of characters corresponding to the attributable column of data. However, the specified characters can't be included within the beginning or the end of that series of characters.

My attempt currently displays the specified characters but includes beginning and ending characters. However I only want to display those characters contained in between the sequence.

I tried this query:

SELECT table_id,
       table_number
FROM TABLE
WHERE table_number LIKE '%99%';
  • Should 1999 be returned or not? – ypercubeᵀᴹ Feb 10 '16 at 8:03
2

You could just use %_99_% instead of %99%.

  • % means 0 ore more characters
  • _ means exactly 1 character

So %_99_% means at least 1 character before and after 99, and anything before and after.

SQL> select * from t1;

C1
--------------------
1991
1199
9911

SQL> select * from t1 where c1 like '%_99_%';

C1
--------------------
1991

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.