Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Trim last two characters of a String

821422Dec 6 2010 — edited Nov 15 2011
Hi,

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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 13 2011
Added on Dec 6 2010
8 comments
109,639 views