我需要从字符串中提取日期部分“ 确认租客没有取车,金额为 400 美元。
采取的行动:需要与供应商进行后续通话
下一步行动日期时间:2023 年 5 月 4 日 09:00:00 本地”
我尝试使用 '\d{1,2}' 但对于一些它从 400$ 中提取 40,我还尝试使用 substr(comment,-28) 提取“04-May-2023 09: 00:00 Local”,但在少数情况下,它最后只提到 EST,因此在这种情况下这不起作用。
需要你的帮助
根据您发布的样本数据:
SQL> with test (col) as
2 (select 'Verify renter did not pick up vehicle amt 400$.
3 Action Taken:Need Followup Call with Supplier
4 Next Action DateTime: 04-May-2023 09:00:00 Local' from dual
5 ),
一个简单的选择是使用
substr + instr
组合;我一步一步地这样做是为了让它更清楚,但你可以(如果你愿意)将它们合并成一个。
此外,它取决于源数据。由于您只发布了一个示例,我们只能尝试想象您可能还会遇到什么。然而,由于没有证据表明实际上有有任何不同,所以你在这里。
6 temp as
7 -- extract everything after "DateTime"
8 (select substr(col, instr(col, 'DateTime')) val
9 from test
10 )
11 -- extract everything between the 1st and and the 3rd space
12 select substr(val, instr(val, ':') + 2,
13 instr(val, ' ', 1, 3) - instr(val, ':') - 1
14 ) result
15 from temp;
RESULT
---------------------
04-May-2023 09:00:00
SQL>