Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle get substring before a space

Tags:

regex

sql

oracle

I have a string with space in between, and I need to get the first string (it can be a number) before the space.

 WITH test_data AS (
  SELECT '123642134  10' AS quarter_cd FROM dual UNION ALL --VALID
)

 select *
  from test_data
 where regexp_like(quarter_cd, '', 'c')

The output should be:

123642134
like image 266
Vivek Avatar asked Jan 31 '13 08:01

Vivek


1 Answers

Substr (quarter_cd, 1,instr(quarter_cd,' ') - 1)

Should do that.

like image 156
DazzaL Avatar answered Oct 21 '22 13:10

DazzaL