oracle获取当前时间

  用法to_char(sysdate,'yyyy-MM-dd HH24:mi:ss)把时间变成字符串

  用法to_date('2015-08-12 15:53:37','yyyy-MM-dd HH24:mi:ss)把字符串变成时间  

  用法to_number把字符串变成数字

  用法trunc负责截取数字或者字符串

select sysdate from dual

获取当前的时间 2015/08/12 15:53:37

select to_char(sysdate,'yyyy-MM-dd HH24:mi:ss) from dual

把当前时间变成字符串 '2015-08-12 15:53:37'

select to_char(sysdate,'yyyy-MM-dd HH24:mm:ss) from dual

'2015-08-12 15:08:37'  mm是代表月份

select to_char(sysdate,'yyyy-MM-dd HH:mm:ss) from dual

'2015-08-12 03:08:37'  HH默认代表12

select to_date('2015-08-12 15:53:37','yyyy-MM-dd HH24:mi:ss) from dual

2015/08/12 15:53:37 把字符串变成时间

select to_char(10000,'$10,000') from dual

结果为$10,000

select to_char(10000,'L10,000') from dual

结果为¥10,000

select trunc(to_number('1000,123'),2) from dual

 

现在了解下时间转换中字符的意义 

   yyyy 表示时间的四个数

   yyy 表示时间的后三个数

   MM  mm 表示月份

   dd 表示多少号 

   day表示星期几

   ddd表示当年的第几天

   HH hh表示时间  HH24表示24小时的时间  HH或者HH12表示12小时的时间

   mi表示分钟

   ss表示秒

   w表示单月的第几周

   ww表示当年的第几周

  select sysdate - interval '7' minitue from dual

表示当前时间减去7分钟

select sysdate - interval '7' hour from dual

表示当前时间减去7小时

select sysdate - interval '7' year from dual 

表示当前时间减去7年

select sysdate,sysdate

dual伪表解释

dual是存在于oracle实实在在的表,常用于select中没有目标表的查询.

  

posted @ 2015-08-12 16:34  如果可以在重来  阅读(38650)  评论(0编辑  收藏  举报