How to get string after character oracle
You can use regexp_substr()
:
select regexp_substr(col, '[^-]+', 1, 2)
If you want to remove an optional space, then you can use trim()
:
select trim(leading ' ', regexp_substr(col, '[^-]+', 1, 2))
The non-ovious parameters mean
1
-- search from the first character of the source.1
is the default, but you have to set it anyway to be able to provide the second parameter.2
-- take the second match as the result substring. the default would be 1.
For a string operation as simple as this, I might just use the base INSTR()
and SUBSTR()
functions. In the query below, we take the substring of your column beginning at two positions after the hyphen.
SELECT
SUBSTR(col, INSTR(col, '-') + 2) AS subject
FROM yourTable
We could also use REGEXP_SUBSTR()
here (see Gordon's answer), but it would be a bit more complex and the performance might not be as good as the above query.