views:

51

answers:

2

Hi,

i am trying to fetch an id from an oracle table. Its something like "TN0001234567890345". What i want is to sort the values according to the right most 10 positions. I am using oracle 11g. Is there any funcrion to cut the rightmost 10 places in oracle ?

thanks in advance

tismon

+7  A: 

You can use SUBSTR function as:

select substr('TN0001234567890345',-10) from dual;

Output:

4567890345
codaddict
+1. Also, the third parameter is not required: `substr('TN0001234567890345',-10)` yields the same result.
Jeffrey Kemp
@Jeffrey: Thanks for pointing.
codaddict
+2  A: 

Calling substr(id,-10,10) will return the rightmost 10 characters of id.

Peter G.
which version of Oracle did you test this on?
Jeffrey Kemp
@Jeffrey, no test, just reading doc. After testing now, I see I misinterpreted the doc. Corrected and thanks!
Peter G.