Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

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?