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.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming