brucezepplin brucezepplin - 4 months ago 11
SQL Question

How to split a string based on delimiter?

I have a column of variable length character strings where some end in

.


i.e.

EU...
EU
EU.
EEU.
EEU...


and I want to select the entire string where a
.
is not present, or the string before the first
.
so that I get:

EU
EU
EU
EEU
EEU


I am aware of the
substr()
function but that requires fixed positions to be given as paramaters. As you can see this is not possible. Can I insert regex into a SQL DB2 statement?

Answer

You can also try this:

db2 "SELECT * from test"

TEST

EU...
EU
EU.
EEU.
EEU...

5 record(s) selected.

db2 "SELECT Replace(test, '.', '') as test from test"

1

EU
EU
EU
EEU
EEU

5 record(s) selected.

Comments