oracle中往varchar2格式的欄位中插入date時間格式的值會發生什嗎?,oraclevarchar2
 
--建立表test1
create table TEST1
(
  ID    VARCHAR2(40) default sys_guid(),
  TDATE VARCHAR2(200)
)
tablespace APP_TX_DATA
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
--插入date時間格式資料
insert into test1 values(sys_guid(),sysdate+10);、
--查詢資料
select * from test1  -- tdate值為 01-7月 -15
--Q:如何將現有資料01-7月 -15格式刷成正常的YYYYMMDD格式?
update test1 t set t.tdate = '20'||substr(t.tdate,instr(t.tdate, '-', 1, 2) + 1,2)
       || case instr(t.tdate, '月', 1, 1) - (instr(t.tdate, '-', 1, 1) + 1)
          when 1 then '0' || substr(t.tdate,
                             instr(t.tdate, '-', 1, 1) + 1,
                             (instr(t.tdate, '月', 1, 1)) - (instr(t.tdate, '-', 1, 1) + 1))
          when 2 then substr(t.tdate,
                             instr(t.tdate, '-', 1, 1) + 1,
                             (instr(t.tdate, '月', 1, 1)) - (instr(t.tdate, '-', 1, 1) + 1))
          else t.tdate end
        || substr(t.tdate,0,2)
  where t.tdate like '%月%' order by t.tdate
 
 
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。