欢迎投稿

今日深度:

oracle中往varchar2格式的字段中插入date时间格式的

oracle中往varchar2格式的字段中插入date时间格式的值会发生什么?


--建立表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

 

www.htsjk.Com true http://www.htsjk.com/oracle/23544.html NewsArticle oracle中往varchar2格式的字段中插入date时间格式的值会发生什么? --建立表test1create table TEST1(ID VARCHAR2(40) default sys_guid(),TDATE VARCHAR2(200))tablespace APP_TX_DATApctfree 10pctused 40initrans 1maxtrans 255s...
评论暂时关闭