regexp_substr- 提取多行文本中的数字

regexp_substr- extract numbers in multiline text

我在 oracle table 中有一个字符串,如下所示。我需要提取文本 "Monthly Tax Amount(Property Taxes) : " 之后的金额。每个项目都在新行中,并且在说明旁边的同一行中提到了与该项目对应的金额。我尝试开发一些 regexp_substr 函数但没有成功。请帮助解决这个问题。

"New-Escrowed Payment Quote:
Effective Date(Projected - Good Through) = 07/07/2017
Current Escrow Balance : $-20000.25
Escrow Disbursements During Trial : 91.06
Anticipated Balance(Projected Escrow Advance) : $-28481.31                    
Monthly Tax Amount(Property Taxes) : 8.51                                                       Monthly Insurance Amount (Hazard Insurance): .33
"Monthly PMI / MI Amount(Mortgage Insurance)    : [=11=]"

我不经常使用正则表达式,但另一种解决方案如下所示。您可能需要根据您使用的行尾调整行尾 chr(10)、chr(13) (unix, windows)

declare

v_string varchar2(32000) default 'New-Escrowed Payment Quote: Effective Date(Projected - Good Through) = 07/07/2017
        Current Escrow Balance : $-20000.25
        Escrow Disbursements During Trial : 91.06
        Anticipated Balance(Projected Escrow Advance) : $-28481.31
        Monthly Tax Amount(Property Taxes) : 8.51
        Monthly Insurance Amount (Hazard Insurance): .33
        Monthly PMI / MI Amount(Mortgage Insurance) : [=10=]';

v_output varchar2(30) default null;

begin

select substr(v_string, instr(v_string, 'Taxes)')+ 9, (instr(v_string, chr(10), instr(v_string, 'Taxes)'))) - instr(v_string, 'Taxes)')) into v_output from dual;

dbms_output.put_line(v_output);

end;

尝试这样的事情:

SELECT REGEXP_SUBSTR('New-Escrowed Payment Quote: Effective Date(Projected - Good Through) = 07/07/2017 Current Escrow Balance : $-20000.25 Escrow Disbursements During Trial : 91.06 Anticipated Balance(Projected Escrow Advance) : $-28481.31
Monthly Tax Amount(Property Taxes) : 8.51 Monthly Insurance Amount (Hazard Insurance): .33 "Monthly PMI / MI Amount(Mortgage Insurance) : [=10=]',
'(Monthly Tax Amount\(Property Taxes\) : $)([0-9\.]+)',1,1,'i',2) s FROM dual

它使用一个包含 2 个组的正则表达式:

  • (Monthly Tax Amount(属性 Taxes) : \$) -- 第一个代表金额title
  • ([0-9.]+) -- 第二个代表你想要得到的数量

REGEXP_SUBSTR 的最后一个参数告诉 Oracle 您只想获取正则表达式的第二组。