-1

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.

Mat
  • 202,337
  • 40
  • 393
  • 406
Dave
  • 503
  • 1
  • 8
  • 21

2 Answers2

4
regexp_substr(column, '\S+', 1, 2)
Egor Skriptunoff
  • 23,359
  • 2
  • 34
  • 64
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

paul
  • 21,653
  • 1
  • 53
  • 54