0

我在 oracle 表中有一个字符串,如下所示。我需要在文本“每月税额(财产税):”之后提取金额。每个项目都在新行中,与项目对应的金额在描述旁边的同一行中提到。我尝试开发一些 regexp_substr 函数但没有取得多大成功。请帮助解决这个问题。

"New-Escrowed Payment Quote:
Effective Date(Projected - Good Through) = 07/07/2017
Current Escrow Balance : $-20000.25
Escrow Disbursements During Trial : $5691.06
Anticipated Balance(Projected Escrow Advance) : $-28481.31                    
Monthly Tax Amount(Property Taxes) : $548.51                                                       Monthly Insurance Amount (Hazard Insurance): $97.33
"Monthly PMI / MI Amount(Mortgage Insurance)    : $0"
4

2 回答 2

1

尝试这样的事情:

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

这使用具有 2 个组的正则表达式:

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

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

于 2017-09-22T06:25:09.043 回答
0

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

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 : $5691.06
        Anticipated Balance(Projected Escrow Advance) : $-28481.31
        Monthly Tax Amount(Property Taxes) : $548.51
        Monthly Insurance Amount (Hazard Insurance): $97.33
        Monthly PMI / MI Amount(Mortgage Insurance) : $0';

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;
于 2017-09-21T22:37:03.627 回答