我的 Excel 文件在日期字段中包含一些垃圾数据。
日期格式为 1/2/2015 格式。我正在尝试将该文件加载到 varchar 字段中的阶段表中,并在加载到主表之前应用正则表达式替换函数来清理错误数据
有人可以为我提供合适的表达方式吗
create table A
(
bad_date varchar2(4000)
);
insert into A
( bad_date)
values ('1/2/2005');
insert into A
( bad_date)
values ('indep');
insert into A
( bad_date)
values ('/');
commit;
create table B
(
good_date date
);
我想使用正则表达式函数来清理不在日期模式中的数据。感谢您的帮助!
最佳答案
使用 ^[0-9]{1,2}/[0-9]{1,2}/[0-9]{4}
模式 regexp_like 符合你的日期格式。
使用以下insert 语句获取干净的日期数据:
insert into B
select * from
( select to_date(bad_date,
case when
regexp_like(bad_date,'^[0-9]{1,2}/[0-9]{1,2}/[0-9]{4}') then
'DD/MM/YYYY'
end) dateConverted
from A)
where dateConverted is not null;
关于sql - oracle regexp_replace 保留数字和反斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50614502/