1. 字符串 → 时间 :to_date(varchar,format)
i.e :
select to_date('2016-08-08 16:56:32','yyyy-mm-dd hh24:mi:ss')as createdate from dual;--正确
select to_date('2016-08-08 16:56:32','yyyy-mm-dd')as createdate from dual; ---报错
select to_date('2016-08-08','yyyy-mm-dd hh24:mi:ss')as createdate from dual;---也可以正常返回
**不能使用双引号
2. 时间 → 字符串 : to_char(date,format)
i.e:
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss')as createdate from dual;
3. format 介绍
★ 年
yyyy : 四位
yyy : 三位
yy : 两位
★ 月
mm : 显示两位数字 如 05
★ 日
dd : 显示两位数字 如 05
★ 小时
hh : 12小时制
hh24 : 24小时制
★ 分钟
mi : 60 进制
★ 秒
ss : 60 进制 如 05
4. 注意 format 的格式最好和 date 的格式一致。
5. 建表时时间默认当前时间
create table test (
id number not null ,
createDate date default sysdate
)