Oracle中日期时间的操作比较和加减

来源:互联网 发布:通达信引用60分钟数据 编辑:程序博客网 时间:2024/05/17 06:03
1.日期时间间隔操作当前时间减去7分钟的时间select sysdate,sysdate - interval '7' MINUTE from dual当前时间减去7小时的时间select sysdate - interval '7' hour from dual当前时间减去7天的时间select sysdate - interval '7' day from dual当前时间减去7月的时间select sysdate,sysdate - interval '7' month from dual当前时间减去7年的时间select sysdate,sysdate - interval '7' year from dual时间间隔乘以一个数字select sysdate,sysdate - 8 *interval '2' hour from dual2.日期到字符操作select sysdate,to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dualselect sysdate,to_char(sysdate,'yyyy-mm-dd hh:mi:ss') from dualselect sysdate,to_char(sysdate,'yyyy-ddd hh:mi:ss') from dualselect sysdate,to_char(sysdate,'yyyy-mm iw-d hh:mi:ss') from dual参考oracle的相关关文档(ORACLE901DOC/SERVER.901/A90125/SQL_ELEMENTS4.HTM#48515)3. 字符到日期操作select to_date('2003-10-17 21:15:37','yyyy-mm-dd hh24:mi:ss') from dual具体用法和上面的to_char差不多。4. trunk/ ROUND函数的使用select trunc(sysdate ,'YEAR') from dualselect trunc(sysdate ) from dualselect to_char(trunc(sysdate ,'YYYY'),'YYYY') from dual5.oracle有毫秒级的数据类型--返回当前时间 年月日小时分秒毫秒select to_char(current_timestamp(5),'DD-MON-YYYY HH24:MI:SSxFF') from dual;--返回当前 时间的秒毫秒,可以指定秒后面的精度(最大=9)select to_char(current_timestamp(9),'MI:SSxFF') from dual;6.计算程序运行的时间(ms)declaretype rc is ref cursor;l_rc rc;l_dummy all_objects.object_name%type;l_start number default dbms_utility.get_time;beginfor I in 1 .. 1000loopopen l_rc for'select object_name from all_objects '||'where object_id = ' || i;fetch l_rc into l_dummy;

http://www.cnblogs.com/pboy2925/archive/2008/07/02/1247997.html
原创粉丝点击