【问题标题】:regexp_substr- extract numbers in multiline textregexp_substr- 提取多行文本中的数字
【发布时间】:2017-09-22 22:11:54
【问题描述】:

我在 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"

【问题讨论】:

  • 您尝试了什么,结果如何?更新您的原始帖子。你想加入美元符号吗?

标签: plsql regexp-substr


【解决方案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,您只想获取第二组正则表达式。

【讨论】:

  • 太棒了!解决方案奏效了。感谢您的快速帮助以及对其工作原理的解释。
  • 你能帮我提取每个组件吗?在上面的文字中。我的意思是提取每个项目旁边的每个金额?
  • 您只需要更改正则表达式中的金额标题即可。如果它有括号,请确保在它们之前放一个 \。例如:(每月保险金额(危险保险):\$)([0-9\.]+),(试用期间的托管付款:\$)([0-9\.]+)等。 ..
  • 我能够进行微小的更改并提取所有项目的金额。再次感谢。
【解决方案2】:

我不使用很多正则表达式,但另一种解决方案如下所示。您可能需要根据您使用的行尾(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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-10
    • 2012-01-11
    • 2018-07-05
    • 1970-01-01
    • 2012-06-26
    • 1970-01-01
    • 2021-12-18
    相关资源
    最近更新 更多