1

我正在尝试从包含药品目录的 Oracle 数据库中的字符串中提取计量单位。我一直在使用 regexp_substr 从字符串中获取药物浓度

IE。

Name col in schema:
CYCLOSPORINE 100MG 30 CAPS
TERBUTALINE 2.5MG 100 TABS 

查询输出:

col 1: CYCLOSPORINE 100MG 30 CAPS, Col 2: 100MG
col 1: TERBUTALINE 2.5MG 100 TABS, Col 2: 2.5MG     



select name, 
regexp_substr(upper(name), 
'(\d*\.*\d+\s*ML|\d*\.*\d+\s*MG|\d*\.*\d+\s*OZ|\d*\.*\d+\s*LB)') 
CONCENTRATION 
from schema.table t 
where t.discontinuedflag=0
and t.restrictioncode <> 0
and t.distributor_id =19

任何人都知道我如何200MG/mL在 Oracle 中使用 regexp_substr() 从下面的字符串中提取出来?

'TESTOSTERONE CYP 200MG/mL 10ML VIAL C3' 
4

2 回答 2

0

看起来您想要字符串中以数字开头的第一个“令牌”。如果是这样的话:

select regexp_substr(name || ' ', ' [0-9.]+[^ ]+ ') as concentration

这将一个空格连接到 的末尾name,因此模式可以以空格结尾,即使它位于 的末尾name

于 2017-04-06T19:18:35.870 回答
0

到目前为止,这似乎对这些特定示例有效,但就像我在上面的评论中所说的那样,您需要确定数据,所以在没有更广泛的测试的情况下不要太相信这一点。我有一个 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 个子组)。

于 2017-04-07T14:18:57.737 回答