I'm looking for a way to print all the phone numbers (10 digit number) in collumn Phone_num of table Customer that has digit 5 6 7 in 5th 6th 7th position in the whole number, using SELECT FROM WHERE format.
CodePudding user response:
You want to use the SUBSTRING function in the WHERE clause. Different databases have slightly different syntax, so you will need to look up the syntax of your database.
In SQL Server, you could write:
select phone_num from customer where substring(phone_num, 5, 3) = '567'
CodePudding user response:
You want to find all numbers that have 567 in the 5th, 6th, and 7th position. You can do this with a regular expression:
SELECT * FROM table WHERE number ~ '^[0-9]{4}567[0-9]{3}$'