--Establish table test1
CREATE TABLE TEST1
(
ID VARCHAR2 (+) 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
);
--Insert Date time Format data
INSERT into test1 values (Sys_guid (), sysdate+10);
--Querying data
SELECT * FROM Test1--tdate value is January-July-15
--q: How do I brush an existing data January-July-15 format into a normal YYYYMMDD format?
Update Test1 t Set t.tdate = ' 20 ' | | substr (T.tdate,instr (t.tdate, '-', 1, 2) + +)
|| Case InStr (T.tdate, ' Month ', 1, 1)-(InStr (T.tdate, '-', 1, 1) + 1)
When 1 Then ' 0 ' | | SUBSTR (T.tdate,
InStr (T.tdate, '-', 1, 1) + 1,
(InStr (T.tdate, ' Month ', 1, 1))-(InStr (T.tdate, '-', 1, 1) + 1))
When 2 then substr (T.tdate,
InStr (T.tdate, '-', 1, 1) + 1,
(InStr (T.tdate, ' Month ', 1, 1))-(InStr (T.tdate, '-', 1, 1) + 1))
else T.tdate End
|| SUBSTR (t.tdate,0,2)
Where t.tdate like '% month% ' ORDER by t.tdate
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
What happens to a value in Oracle that inserts a date time format into a field in the VARCHAR2 format?