Regex oracle中的正则表达式
我有一个表,它的列值如下Regex oracle中的正则表达式,regex,oracle,Regex,Oracle,我有一个表,它的列值如下 ERROR - abc failed to load service request on {Date/Time} .The CIRCUIT is missing. ERROR - abc failed to load service request on {Date/Time}. The JOB_STREET_NAME is missing. ERROR - abc failed to load service request on {Date/Tim
ERROR - abc failed to load service request on {Date/Time} .The CIRCUIT is missing.
ERROR - abc failed to load service request on {Date/Time}. The JOB_STREET_NAME is missing.
ERROR - abc failed to load service request on {Date/Time}. The JOB_TOWN is missing.
我想在我的oracle包的特定列中找到{Date/Time}部分,并用当前的_时间戳替换它
找不到适合我的东西。我是新来的。寻找建议。我认为您可以使用
REGEXP\u SUBSTR
实现它,如下所示:
SELECT
REGEXP_SUBSTR(YOUR_COL,'failed to load service request on(.+) \.',1,1,NULL,1)
FROM YOUR_TABLE
一个简单的替换函数似乎工作得很好
SQL> -- create an populate table
SQL> create table errmsg (msg_id number,
2 msg_txt varchar2(100)
3 )
4 ;
Table created.
SQL> insert into errmsg values (1,'ERROR - abc failed to load service request on {Date/Time} .The CIRCUIT is missing.');
1 row created.
SQL> insert into errmsg values (2,'ERROR - abc failed to load service request on {Date/Time}. The JOB_STREET_NAME is missing.');
1 row created.
SQL> insert into errmsg values (3,'ERROR - abc failed to load service request on {Date/Time}. The JOB_TOWN is missing.');
1 row created.
SQL> commit;
Commit complete.
SQL> select * from errmsg;
MSG_ID
----------
MSG_TXT
--------------------------------------------------------------------------------
1
ERROR - abc failed to load service request on {Date/Time} .The CIRCUIT is missin
g.
ERROR - abc failed to load service request on {Date/Time} .The CIRCUIT is missin
g.
2
ERROR - abc failed to load service request on {Date/Time}. The JOB_STREET_NAME i
s missing.
3
ERROR - abc failed to load service request on {Date/Time}. The JOB_TOWN is missi
ng.
3 rows selected.
SQL> -- test the method
SQL> select replace(msg_txt,'{Date/Time}',to_char(sysdate,'dd-Mon-yyyy hh24:mi:ss')) logged_message
2 from errmsg
3 where msg_id=1;
LOGGED_MESSAGE
--------------------------------------------------------------------------------
ERROR - abc failed to load service request on 25-Mar-2020 16:16:39 .The CIRCUIT
is missing.
1 row selected.
SQL> --
SQL> select replace(msg_txt,'{Date/Time}',to_char(sysdate,'dd-Mon-yyyy hh24:mi:ss')) logged_message
2 from errmsg
3 where msg_id=2;
LOGGED_MESSAGE
--------------------------------------------------------------------------------
ERROR - abc failed to load service request on 25-Mar-2020 16:16:39. The JOB_STRE
ET_NAME is missing.
1 row selected.
SQL> --
SQL> select replace(msg_txt,'{Date/Time}',to_char(sysdate,'dd-Mon-yyyy hh24:mi:ss')) logged_message
2 from errmsg
3 where msg_id=3;
LOGGED_MESSAGE
--------------------------------------------------------------------------------
ERROR - abc failed to load service request on 25-Mar-2020 16:16:39. The JOB_TOWN
is missing.
1 row selected.
SQL> --
SQL> -- drop the table
SQL> drop table errmsg purge;
Table dropped.
SQL> spool off
你的问题很不清楚。请使用并编辑问题,以可读的格式显示数据,其中的示例数据不是“{Date/Time}”,也包括您尝试过的数据,以及预期的输出,而不是用正则表达式蒙混过关,一个简单的示例就足够了。除非您不是字面上的意思是
{Date/Time}
字符串需要替换。但这还不清楚。编辑了这个问题。我只是想知道正则表达式,它可以用来实现这个目标。我尝试了仅替换,但这对我不起作用。您肯定需要分享一些日期/时间字符串的实际外观示例,以构建一个正则表达式,该正则表达式可以匹配日期和时间格式的巨大差异。{date/time}需要在每次获取消息时替换为当前的_时间戳。此表达式仅适用于:“错误-abc未能在上加载服务请求。电路缺失。“对于其他人,它返回空值:警告-abc未在上提供作业号(建筑号)。错误-abc无法在上加载服务请求。找不到JOB_STREET_的名字。错误-abc无法在上加载服务请求。镇上的工作不见了。错误-abc无法在上加载服务请求。缺少作业状态。