oracle - Extract text between words -
i trying extract numbers between 2 words distincts, "substr
" don't work combined "instr
". @ least i'm not getting!
example:
codtax tax_description ----------------------- 1225 ncm 85444900 ipi 0% icms 18% cst 060 iva 41,00% iva ext 51,32%
the extract number between "ipi " , "% icms" 0 or between "iva " , "% iva" 41.00.
create table tax ( codtax number, tax_description varchar2(200 byte) ); insert tax (codtax, tax_description) values (1505, 'ncm 29051220 ipi 0% icms 18% cst 000 iva 0% iva ext 0%'); insert tax (codtax, tax_description) values (1258, 'ncm 85444900 ipi 0% icms 18% cst 060 iva 41,00% iva ext 51,32%'); insert tax (codtax, tax_description) values (2051, 'ncm 85362000 ipi 10% icms 18% cst 060 iva 43,00% iva ext 53,46%');
the result must be:
codtax tax_description ipi iva ---------------------------------------------------------------------------------- 1505 ncm 29051220 ipi 0% icms 18% cst 000 iva 0% iva ext 0% 0 0 1258 ncm 85444900 ipi 0% icms 18% cst 060 iva 41,00% iva ext 51,32% 0 41,00 2051 ncm 85362000 ipi 10% icms 18% cst 060 iva 43,00% iva ext 53,46% 10 43,00
you can try combination of instr , regexp_substr.
select a.*, regexp_substr (a.tax_description, '\d+,?\d*', instr (a.tax_description, 'ipi')) ipi, regexp_substr (a.tax_description, '\d+,?\d*', instr (a.tax_description, 'iva')) iva tax a;
instr used find first position of ipi , iva. used in regexp_substr function specify starting position.
the regex pattern,
- \d+ matches 1 or more digits.
- ,? matches 0 or 1 comma.
- \d* matches 0 or more digits.
Comments
Post a Comment