Skip to content
Advertisement

SUBSTR in oracle not working when there is line break in the string

Okay so I am working with a database that has data in many formats. I was asked to split a string into 3 columns by 150 length in each column

The data in the table is stored as this

I want to split this data into 3 columns , COL1, COL2, COL3

When I use this query it works fine.

but I had to replace It's with It''s. How do I replace when the value is stored in column but that will not count ' as a character and will eventually return wrong count. Also when there is a line break I want it to be take as 2 character /b.

Cheers!

Advertisement

Answer

When you actually represent the data as a column in a query or DML command then you shouldn’t have that problem. In other words, when you do this:

it should work fine. You only have to worry about escaping special characters when you are typing in the literal text yourself, as in your example.

Also, be aware the the second number in substr is the length of the string, not the ending position of the segment, so if you want 140 characters, this should always be 140. From the documentation, “The SUBSTR functions return a portion of char, beginning at character position, substring_length characters long.”

https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/SUBSTR.html#GUID-C8A20B57-C647-4649-A379-8651AA97187E

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement