Oracle
 SQL >> Database >  >> RDS >> Oracle

Come estrarre una sottostringa in Oracle

Userei REGEXP_SUBSTR (documentazione), con le espressioni regolari appropriate. Ad esempio:

select regexp_substr('Chapter 18 Unit 10 Sect 16', 'Chapter \d*') from dual; --Will return: Chapter 18
select regexp_substr('Chapter 18 Unit 10 Sect 16', 'Unit \d*') from dual;    --Will return: Unit 10
select regexp_substr('Chapter 18 Unit 10 Sect 16', 'Sect \d*') from dual;    --Will return: Sect 16

Se poi memorizzate stringhe del tipo Chapter xx Unit yy Sect zz in una tabella, potete usare questo tipo di query per ottenere più risultati:

select regexp_substr(info_column, 'Chapter \d*') from mytable;

Potete sostituire \d con [0-9] oppure [[:digit:]].

SQLfiddle