Replace the second repeated character

Asked

Viewed 87 times

1

I have the following value in an Oracle query.

SELECT '3.0.' FROM DUAL

I’d like you to return only 3.0 and remove the Last Point (.)

I tried to use the REGEXP_REPLACE thus:

SELECT REGEXP_REPLACE('3.0.','(.){2,.}','') FROM DUAL

But it didn’t work. You can help me?

2 answers

1


You can use the function TRIM oracle.

Leaving the query this way:

SELECT TO_CHAR(TRIM(TRAILING . FROM campo))
FROM tabela
WHERE condições
  • Trim does not remove the spaces you have in the text?

  • According to the documentation, you can specify what will be removed. If you do not specify, it removes spaces.

  • That’s right. Thank you very much!

1

Can do with the SUBSTR, removing the last character:

SELECT SUBSTR(VALOR, 0, LENGTH(VALOR)-1) FROM (SELECT '3.0.' VALOR FROM DUAL);

See working on SQL Fiddle.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.