1
SELECT user_id
FROM
USER_DUMPS
WHERE USER_ID like 'AB%'

I need to trim the whitespace from the right side of the USER_DUMPS table results. Results have 3 whitespaces.

pfx
  • 20,323
  • 43
  • 37
  • 57
pthfndr2007
  • 93
  • 1
  • 10

2 Answers2

2

You could use TRIM:

SELECT TRIM(TRAILING FROM user_id) AS user_id
FROM USER_DUMPS 
WHERE USER_ID like 'AB%'
Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275
  • What if it is not just spaces but other whitespace characters? – Patrick Szalapski Aug 02 '22 at 12:53
  • @PatrickSzalapski Assuming that there are other characters(tab) they could be defined to be removed: [db<>fiddle demo](https://dbfiddle.uk/?rdbms=oracle_21&fiddle=6f94c49671cf54ce911cf73d88b7359b) – Lukasz Szozda Aug 02 '22 at 14:30
2

You might use

RTRIM

( no need to use any argument, since the RTRIM(string) function removes all trailing spaces from string if no argument specified. ) :

SELECT RTRIM(user_id) as "Trimmed Text"
FROM
USER_DUMPS
WHERE USER_ID like 'AB%';
Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55