关于日期格式的问题

crazy_boom crazy_boom 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
CREATE TABLE MX
(BH CHAR(11) NULL DEFAULT '',
RIQI CHAR(10) NULL DEFAULT '',
SHL DECIMAL(14,2) DEFAULT 0
)

表MX 中RIQI存储的是日期格式的值 格式为 YYY-MM-DD (例:2009-10-21)
但是在操作过程中 会错误录入 2009-02-31、200-02-01、2008-0130
这样的错误的日期格式 。如何能够查出哪些数据的格式不符合日期格式?
我现在就用这样简单的办法 :
select * from mx where substring(riqi,5,1)<>'-'
select * from mx where substring(riqi,8,1)<>'-'
select * from mx where substring(riqi,6,2)='02' and substring(riqi,9,2)='30'
select * from mx where substring(riqi,6,2)='02' and cast(substring(riqi,9,2) as int)>28
这些方法来查 但是日期格式不正确的方式太多了 像这样来检查 很费劲 并且查出来的也不全。有什么更好的方法?
...全文
评论 3
收藏 已收藏
分享
返回顶部
crazy_boom
疑难问题 22,298 成员 121,727 内容