想要更新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:缺失關鍵字,各位大俠誰幫忙解決一下???小女子謝過啦
uj5u.com熱心網友回復:
把 && 替換成 ANDuj5u.com熱心網友回復:
&&怎么在shell中 這么熟悉。。
uj5u.com熱心網友回復:
條件只需一個即可,同時else后應是 to_date(time2,'yyyy-mm-dd')
select
(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
uj5u.com熱心網友回復:
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,一個是字符。
uj5u.com熱心網友回復:
create table table1(a 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;
uj5u.com熱心網友回復:
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/34695.html
標籤:開發
