想要更新table1的时间字段time1 date,从table2中查出时间字段time2插入time1,现有问题,time2的部分数据为 "08月16日 10时"这种格式的,部分为标准格式"2015-08-16",想把所有time2格式变为标准 "2015-08-16",直接使用to_date和to_char不行,决定拼接字符串.所以需要分别判断原来是什么格式的,然后进行处理,用的是case when then,先把time2换为标准格式,select
(case
when length(time2)=10&&substr(time2,0,1)!='2'
then to_date((to_char(sysdate,'yyyy')||'-'||substr(time2,0,2)||'-'||substr(time2,3,2)),'yyyy-MM-dd')
else 'not time'
end)
from table2 d
现在报错,ora-00905:缺失关键字,各位大侠谁帮忙解决一下???小女子谢过啦
(case
when length(time2)=10&&substr(time2,0,1)!='2'
then to_date((to_char(sysdate,'yyyy')||'-'||substr(time2,0,2)||'-'||substr(time2,3,2)),'yyyy-MM-dd')
else 'not time'
end)
from table2 d
现在报错,ora-00905:缺失关键字,各位大侠谁帮忙解决一下???小女子谢过啦
(case
when substr(time2,0,1)!='2'
then to_date((to_char(sysdate,'yyyy')||'-'||substr(time2,0,2)||'-'||substr(time2,3,2)),'yyyy-MM-dd')
else to_date(time2,'yyyy-mm-dd')
end)
from table2 d
select
(case
when length(sysdate)=10 and substr(sysdate,0,1)!='2'
then to_date((to_char(sysdate,'yyyy')||'-'||substr(sysdate,0,2)||'-'||substr(sysdate,3,2)),'yyyy-MM-dd')
else sysdate
end)
from dual d应该这样才行,then和else的结果类型应该要一致。不能一个是date,一个是字符。
create table table2(b varchar2(100));insert into table2(b) values ('08月16日 10时');
insert into table2(b) values ('2015-08-16');
COMMIT;
INSERT INTO table1(a)
SELECT to_date(CASE SUBSTR(b,3,1) WHEN '月' THEN '2015-'||SUBSTR(b,1,2)||'-'||SUBSTR(b,4,2) ELSE b END,'yyyy-mm-dd') AS col1 FROM table2;
COMMIT;