oracle的to_dsinterval

Purpose:

TO_DSINTERVAL converts a character string of CHAR, VARCHAR2, NCHAR, or NVARCHAR2 datatype to an INTERVAL DAY TO SECOND value.

Examples:
The following example selects from the employees table the employees who had worked for the company for at least 100 days on January 1, 1990:

SELECT employee_id, last_name FROM employees
   WHERE hire_date + TO_DSINTERVAL('100 10:00:00')
   <= DATE '1990-01-01';

EMPLOYEE_ID LAST_NAME
----------- ---------------
        100 King
        101 Kochhar
        200 Whalen

上面是官方的简单解释
常用的功能就是把一个日期加上一定的小时数或着天数变成另外一个日期
如:
select sysdate + to_dsinterval('0 02:30:00') as newDate from dual;
就是把糸统时间加上2个半小时后变成的另一个日期。

select sysdate + to_dsinterval('800 08:30:00') as newDate from dual;
就是把糸统时间加上800天又8个小时30分钟

当然如果要把糸统时间减或着加一个小时或几个小时可以这样写:
select sysdate,(sysdate - 1/24) as newDate from dual;(+,-来决定是加或着减)
如果要把糸统时间减或加上一天或几天
select sysdate,(sysdate - 1) as newDate from dual;(+,-来决定是加或着减)

下面这个函数和TO_DSINTERVAL有点相似:
将糸统时间减去12分钟,'minute'是参数,只可以为DAY, HOUR, MINUTE, SECOND
分别用来操作天,小时,分钟,秒
select  sysdate,sysdate - numtodsinterval(12, 'minute') from dual

你可能感兴趣的:(oracle)