sqloracleoracle-sqldevelopersubstrinstr

Oracle SQL, getting string value between 2 points


I need to select a string value between two dots. (dots include)

Given abc.musadeneme.dce I need .musadeneme.

I need your help, thanks.


Solution

  • You can use SUBSTR and INSTR (which is much faster than regular expressions):

    SELECT SUBSTR(
             value,
             INSTR(value, '.', 1, 1),
             INSTR(value, '.', 1, 2) + 1 - INSTR(value, '.', 1, 1)
           ) AS match
    FROM   table_name
    

    Which, for the sample data:

    CREATE TABLE table_name (value) AS
    SELECT 'abc.musadeneme.dce' FROM DUAL;
    

    Outputs:

    MATCH
    .musadeneme.

    fiddle