Site icon Narayana Tutorial

How to get last characters from a string in oracle

In this article, I am sharing the steps to get last characters from string in oracle. Suppose we have a value in one of the columns as  ‘NarayanaTutorial‘ Then how to get only ‘Tutorial‘ string?

We can achieve this in two different ways as follows.

First way

By using substr function we can get the last characters using the following sql query

SQL> SELECT SUBSTR('NarayanaTutorial', -8) FROM DUAL;

Output
Tutorial

Minus(-) indicates that it will read string from right to left and get the specified number of characters from right to left.

Second way

By using SUBSTR and REVERSE functions we can get the last characters using the following sql query.

SQL> SELECT REVERSE(SUBSTR(REVERSE('NarayanaTutorial'), 1, 8)) FROM DUAL;

Output
Tutorial