Trim last two characters of a String
821422Dec 6 2010 — edited Nov 15 2011Hi,
I have a task to trim the last two characters of a string in a column and get the rest as output for comparison purpose.
the length of column value is not fixed.
For example
I/p O/p
India_1 India
America_2 America
I achieved the result using the below query:
SELECT SUBSTR (TRIM ('India_1'), 1, LENGTH (TRIM ('India_1')) - 2) FROM DUAL;
I have used the trim function to remove the leading and trailing spaces in the column value.
Could somebody please let me know if there is a better way to get the result .. like in one shot query.
Thanks,
Pratik