How Can I Cut the Left Part of the String with Unknown Legth? (With Sql Function)
In the Etl Process, I Receive a Varchar Field, and the Length (Of the Value) Is Changed from Row to Row. I Need to Keep 5 Symbols from the Right Side of the...
In the ETL process, I receive a varchar field, and the length (of the value) is changed from row to row. I need to keep 5 symbols from the right side of the string. It means that I need to cut the left side but I can't, due to the unknown length.
I've tried the select substring('24:15:11',4, 5), but it doesn't help me, the string could be '2019-05-01 22:15:11'.
sql:
select substring('24:15:11',4, 5)
expected:
15:11
2 Answers
You can use substr. Negative starting position is interpreted as being relative to the end of the string.
select substr('24:15:11', -5)
You can use length() to determine the 2nd argument of substr():
select substr('24:15:11', length('24:15:11') - 4, 5)
or simply:
select substr('24:15:11', length('24:15:11') - 4)
Read about preosto's string functions.