0

The question is about searching name starting with letter 'G' in employees table. I am using Oracle 12c Version.

I came across the answer:

select * 
from employees 
where first_name >= 'G' 
  and first_name < 'H';

Could you please help me to understand the logic behind this.

1
  • 1
    they're just string comparisons, which means 'g' < 'harrison' is TRUE, because g comes before h in the alphabet. the length of the strings is irrelevant. the characters are compared in lock step, as soon as there's s mismatch, you get the comparison results. Commented Sep 9, 2016 at 20:19

2 Answers 2

2

Other than what is being commented, you can as well use LIKE operator since you are eventually trying to get all first_name starting with G

select * from employees where first_name like 'G%'
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Marc & Rahul
1

You can use regexp as well to search your names starting with G as below:

select * from employees 
WHERE REGEXP_LIKE (first_name, '^G','i');

here parameter 'i' will ignore the case of the name.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.