Question

How can I return the second word in a varchar2 data type and blank if there is nothing? The idea is to use a function within a function.

Was it helpful?

Solution 2

substr(column, instr(column, ' ') + 1)

edit (for second word only):

substr(col, instr(col, ' '), instr(col, ' ', instr(col, ' ') + 1) - instr(col, ' '))

edit again:

as pointed out by Colin, REGEXP_SUBSTR(col,'\S+',1,2) might be a better way of doing this

OTHER TIPS

regexp_substr(column, '\S+', 1, 2)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top