一个时间日期转换格式的小功能
SQL> SELECT TO_CHAR(SYSDATE,'SSSSS'),sysdate FROM DUAL;
TO_CH SYSDATE
----- -------------------
62239 2007-11-21 17:17:19
SSSSS :格式显示的是自午夜0点以来,流逝的秒数,用它来算两个时间之差的秒数很简单,如下:
SQL> set serveroutput on
1 declare
2 t1 number ;
3 t2 number ;
4 t3 number ;
5 begin
6 select to_char(sysdate,'sssss') into t1 from dual;
7 dbms_lock.sleep(10);
8 select to_char(sysdate,'sssss') into t2 from dual;
9 t3 := t2-t1 ;
10 dbms_output.put_line('时间相差: '||t3||' 秒') ;
11* end;
SQL> /
时间相差: 10 秒
TO_CH SYSDATE
----- -------------------
62239 2007-11-21 17:17:19
SSSSS :格式显示的是自午夜0点以来,流逝的秒数,用它来算两个时间之差的秒数很简单,如下:
SQL> set serveroutput on
1 declare
2 t1 number ;
3 t2 number ;
4 t3 number ;
5 begin
6 select to_char(sysdate,'sssss') into t1 from dual;
7 dbms_lock.sleep(10);
8 select to_char(sysdate,'sssss') into t2 from dual;
9 t3 := t2-t1 ;
10 dbms_output.put_line('时间相差: '||t3||' 秒') ;
11* end;
SQL> /
时间相差: 10 秒