使用regexp replace编写oracle查询,以修复空间并返回hh:mm格式。
with
test_data (srt_tm) as (
select '1:00' from dual union all
select '01:00' from dual union all
select ' 01:00' from dual union all
select '4:00' from dual union all
select '04:00' from dual union all
select ' 04:00' from dual
)预期输出:

已尝试查询:
select (strt_tm,regexp_replace(strt_tm,'^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$','hh:mm') as "REPLACE"
from test_data发布于 2021-09-08 16:49:56
只需在小时数中添加额外的0,并删除除最后两位以外的所有数字:
select
strt_tm,
regexp_replace(
regexp_replace(
strt_tm
,'(\d+):'
,'0\1:'
)
,'.*(\d{2}:)'
,'\1'
) as "REPLACE"
from test_data;完整的test_data示例:
with
test_data (strt_tm) as (
select '1:00' from dual union all
select '01:00' from dual union all
select ' 01:00' from dual union all
select '4:00' from dual union all
select '04:00' from dual union all
select ' 04:00' from dual
)
select
strt_tm,
regexp_replace(
regexp_replace(
strt_tm
,'(\d+):'
,'0\1:'
)
,'.*(\d{2}:)'
,'\1'
) as "REPLACE"
from test_datahttps://stackoverflow.com/questions/69106385
复制相似问题