PostgreSQL String() Function: Extract the last four characters of phone numbers
9. Write a query to extract the last four characters of phone numbers.
Sample Solution:
Code:
SELECT RIGHT(phone_number, 4) as "Ph.No."
FROM employees;
Sample table: employees
Output:
pg_exercises=# SELECT RIGHT(phone_number, 4) as "Ph.No." pg_exercises-# FROM employees; Ph.No. -------- 4567 4568 4569 4560 5567 4561 4562 4563 4564 4567 4568 4565 4566 1934 1834 1734 1634 2034 2019 1834 8009 ... 7777 8888 8080 8181 (106 rows)
Practice Online
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a query to find all the employees which first name contains all the uppercase letter.
Next: Write a query to get the information about those locations which contain the characters in its street address is on and below the minimum character length of street_address.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework