Thursday, April 16, 2015

Select a substring in Oracle SQL up to a specific character

Using a combination of SUBSTR and INSTR you can get a substring in Oracle SQL up to a specific character

SELECT SUBSTR('ABC_blahblahblah', 0, INSTR('ABC_blahblahblah', '_')-1) AS output
  FROM DUAL

Result:
output
------
ABC

General Syntax
:

SELECT SUBSTR(t.column, 0, INSTR(t.column, '_')-1) AS output
  FROM YOUR_TABLE t

No comments: