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

你可能感兴趣的:(oracle,数据库)