Select character on the right

Hi,

I have a column with comma separated values and i only need the ones at the right.

Example;

Original
1,3
2,5,6
3
4,7,9

Result
3
6
3
9

I want to use this as a caculated field in IDT


tantetruus (BOB member since 2008-11-11)

Hi,

Which database do you use? The syntax may depend on it.


Marek Chladny :slovakia: (BOB member since 2003-11-27)

ah, Oracle 12 c


tantetruus (BOB member since 2008-11-11)

Hi,

Use the INSTR() function to locate the last comma and then use the SUBSTR() function to get the required substring.

When one of the arguments (I can’t tell which one now) is negative then the search for a string (INSTR) and cutting of a string (SUBSTR) is done from the right side, not from the left. Check the documentation:

INSTR:

SUBSTR:


Marek Chladny :slovakia: (BOB member since 2003-11-27)

there is no way to “look” from the right and pick everything from the right until you meet the first comma?

(that must be THE MOST layman terms anyone has ever used on this forum…)
By me that is, obviously:)


tantetruus (BOB member since 2008-11-11)

Is the number always a single digit? If it is, then just use right([your string];1).


Maddye :uk: (BOB member since 2009-01-09)

Unfortunately the numbers go from 1 to 10


tantetruus (BOB member since 2008-11-11)

Hi,

I don’t have an Oracle database for testing so writing this just from my memory:

This should return the position of the last comma in your string. Just change table.column to what you have:

INSTR( table.column, ',', -1, 1)

Now use the result of the above in the SUBSTR() function to get what is after the last comma:

SUBSTR(table.column, INSTR( table.column, ',', -1, 1) + 1, 10)

Marek Chladny :slovakia: (BOB member since 2003-11-27)

thx Marek!


tantetruus (BOB member since 2008-11-11)

Did it work?


Marek Chladny :slovakia: (BOB member since 2003-11-27)

i will tell you as soon as i can access the system. Waiting on update…


tantetruus (BOB member since 2008-11-11)