ORA-01847 月份中日的值必须介于 1 和当月最后一日之间

一、问题描述:大数据与v5对接后查询表select * from base_customers where status=1
提示ORA-01847 月份中日的值必须介于 1 和当月最后一日之间
二、问题分析:
1、base_customers为视图,查视图结构
create or replace view base_customers as
select a.cardno as customerid,
b.stuempno as outid,
decode(a.status,‘1’,1,‘2’,6) as status,
a.cardtype cardsfid,
to_date(a.opendate,‘yyyymmdd’) as OPENDT,
to_date(a.expiredate,‘yyyymmdd’) as nousedate,
‘’ as pwd,
‘’ as querypwd,
decode(b.sex,‘1’,1,‘2’,0) as sex,
b.custname as name,
sysdate as curusedate,
b.deptcode as CUSTDEPT,
‘’ as EMPCODE,
b.nation as NATION,
d.balance as ODDFARE,
d.balance as ODDFAREACC,
0 as SUBODDFARE,
0 as SUBODDFAREACC,
to_number(b.idtype) as CERTIFICATEID,
b.idno as IDCARDNO,
to_number(b.areacode) as SERVERID,
b.country as COUNTRY,
to_number(substr(b.indate,0,4)) as REGSTARTYEAR,
decode(a.cardphytype,10,2,20,1) as CARDKIND,
to_date(a.opendate,‘yyyymmdd’) as CREATETIME,
to_number(a.LASTSAVED) as flag_ver,
to_date(a.LASTSAVED,‘yyyymmddhh24miss’) as flag_date,
0 as flag_del
from t_card a,t_customer b,e_user c,e_account d where a.custid=b.custid and b.custid=c.custid and c.id=d.userid;
2、定位t_card表中to_timestamp(a.expiredate,‘yyyymmdd’) as nousedate异常
select a.opendate,to_date(a.opendate,‘yyyymmdd’) as OPENDT from t_card a #无报错
select a.expiredate,to_timestamp(a.expiredate,‘yyyymmdd’) as nousedate from t_card a #报错ORA-01847 月份中日的值必须介于 1 和当月最后一日之间
3、结论:a.expiredate值中有非法日
三、问题处理:
1、排查是否存在0或者null
select a.expiredate
from t_card a order by a.expiredate where a.expiredate =’ ’
/
select a.expiredate
from t_card a order by a.expiredate where a.expiredate is null
/
select a.expiredate
from t_card a order by a.expiredate where a.expiredate =‘0’
/
select distinct(substr(a.expiredate,5,4))
from t_card a where substr(a.expiredate,5,2)=‘09’ order by substr(a.expiredate,5,4)–0900
/
select * from t_card a where substr(a.expiredate,5,4)=‘0900’
2、从01-12月排查非法日
select distinct(substr(a.expiredate,5,4))
from t_card a where substr(a.expiredate,5,2)=‘09’ order by substr(a.expiredate,5,4)–0900
说明:substr(a.expiredate,5,2)代表月,substr(a.expiredate,5,4)代表月日;substr(a.expiredate,5,2)='09’更改范围01、02、03、04、05、06、07、08、09、10、11、12
3、 select * from t_card a where substr(a.expiredate,5,4)=‘0900’ and custid=120007
update t_card a set a.expiredate=‘20230901’ wher substr(a.expiredate,5,4)=‘0900’ and custid=120007

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

福娃筱欢

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值