到目前为止,这似乎对这些特定示例有效,但就像我在上面的评论中所说的那样,您需要确定数据,所以在没有更广泛的测试的情况下不要太相信这一点。我有一个 NDC 表并进行了一些检查,似乎集中在描述中,但我没有检查每一个代码,所以非常仔细地测试!
正则表达式将括号放在要记住的组周围,从左到右读取,并返回第一个和第二个记住的组。它可以读作:从行首开始,查找一个或多个不是数字的字符,然后是一个或多个数字,然后是可选的小数点和零个或多个数字,然后是零个或多个空格,然后是可选度量之一(管道是逻辑 OR),然后是可选的“/ML”,然后是字符串的其余部分。
SQL> with tbl(drug_name) as (
select 'CYCLOSPORINE 100MG 30 CAPS' from dual union
select 'TERBUTALINE 2.5MG 100 TABS' from dual union
select 'TESTOSTERONE CYP 200MG/mL 10ML VIAL C3' from dual union
select 'GEMCITABINE 1 GM-26.3 ML VL' from dual union
select 'NOREPINEPHRINE 1MG/mL 4mL 10 AMP' from dual union
select 'AMOXI-DROP (50MG)' from dual union
select 'DARVOCET-N 100 TABLET' from dual union
select 'ALBON ORAL SUSP 5% 16OZ' from dual
)
select drug_name,
regexp_replace(upper(drug_name), '^\D+(\d+\.?\d*) *((GM|ML|MG|OZ|LB|%)?(/ML)?).*$', '\1\2') CONCENTRATION
from tbl;
DRUG_NAME CONCENTRATION
-------------------------------------- ------------------------------
ALBON ORAL SUSP 5% 16OZ 5%
AMOXI-DROP (50MG) 50MG
CYCLOSPORINE 100MG 30 CAPS 100MG
DARVOCET-N 100 TABLET 100
GEMCITABINE 1 GM-26.3 ML VL 1GM
NOREPINEPHRINE 1MG/mL 4mL 10 AMP 1MG/ML
TERBUTALINE 2.5MG 100 TABS 2.5MG
TESTOSTERONE CYP 200MG/mL 10ML VIAL C3 200MG/ML
8 rows selected.
SQL>
Notes:- If the regex does not find a match, the DRUG_NAME column will be returned.
- Since you upshift the drugname, the original 'mL' spelling becomes 'ML'.
Technically it's the same thing but you are altering data which may matter to the
consumers of the data.
- Some drug names like the DARVOCET example don't seem to have a measure in the
description. You need to decide if that's ok.
- The space between the number and measure is removed.
哦,我使用了 REGEXP_REPLACE,因为它允许使用 '\1' 简写来引用多个已保存的组,而 REGEXP_SUBSTR 不允许这样做(只有 1 个子组)。