Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove last character from string in sql plus

I'm trying to remove the last character from a column output in sql plus. The length of the column entries is not fixed

For e.g XYZA should output as XYZ

I've tried using the substr() function but it doesn't seem to work.

SUBSTR(ooo.CO_NAME,1,LENGTH(ooo.CO_NAME-1))
like image 764
Ali Anwar Avatar asked Oct 20 '14 12:10

Ali Anwar


People also ask

How do I get the last 3 characters of a string in SQL?

It could be this using the SUBSTR function in MySQL: SELECT `name` FROM `students` WHERE `marks` > 75 ORDER BY SUBSTR(`name`, -3), ID ASC; SUBSTR(name, -3) will select the last three characters in the name column of the student table.

How do I remove the last character from a string in Peoplecode?

Use the RTrim function to remove characters, usually trailing blanks, from the right of a string.

How do you remove the first and last character of a string in Oracle?

The Oracle LTRIM() function is used to remove all specified characters from the left end side of a string. Optionally you can specify an initial character or characters to trim to, or it will default to a blank.


1 Answers

A closing parenthesis is in the wrong place. It should be:

SUBSTR(ooo.CO_NAME, 1, LENGTH(ooo.CO_NAME) - 1)
like image 74
Troy Gizzi Avatar answered Sep 22 '22 18:09

Troy Gizzi