6 个解决方案
#1
select sysdate, sysdate+1/24, sysdate +1/1440, sysdate + 1/86400 from dual;
#2
date类型不能到毫秒的,要用timestamp类型.
用numtodsinterval这个函数进行加减(毫秒的还没找到)
select sysdate + numtodsinterval(150, 'DAY') from dual;
numtodsinterval(1500, 'HOUR')
numtodsinterval(15000, 'MINUTE')
numtodsinterval(150000, 'SECOND')
用numtodsinterval这个函数进行加减(毫秒的还没找到)
select sysdate + numtodsinterval(150, 'DAY') from dual;
numtodsinterval(1500, 'HOUR')
numtodsinterval(15000, 'MINUTE')
numtodsinterval(150000, 'SECOND')
#3
SQL> create table t(a timestamp);
表已创建。
SQL> insert into t(a) values(systimestamp);
已创建 1 行。
SQL> update t set a=a+numtodsinterval(1,'day') --加一天
2 ;
已更新 1 行。
SQL> update t set a=a+numtodsinterval(1,'hour') --加一小时
2 ;
已更新 1 行。
SQL> update t set a=a+numtodsinterval(1,'second') --加一秒
2 ;
已更新 1 行。
SQL> update t set a=a+numtodsinterval(500/1000,'second') --加500毫秒
2 ;
已更新 1 行。
SQL> select * from t;
A
---------------------------------------------------------------------------
2008-02-28 12:35:34.546000
表已创建。
SQL> insert into t(a) values(systimestamp);
已创建 1 行。
SQL> update t set a=a+numtodsinterval(1,'day') --加一天
2 ;
已更新 1 行。
SQL> update t set a=a+numtodsinterval(1,'hour') --加一小时
2 ;
已更新 1 行。
SQL> update t set a=a+numtodsinterval(1,'second') --加一秒
2 ;
已更新 1 行。
SQL> update t set a=a+numtodsinterval(500/1000,'second') --加500毫秒
2 ;
已更新 1 行。
SQL> select * from t;
A
---------------------------------------------------------------------------
2008-02-28 12:35:34.546000
#4
恩,不错!
学到了,可以到微秒:
SELECT systimestamp,systimestamp+numtodsinterval(1/1000000,'second')
FROM dual;
学到了,可以到微秒:
SELECT systimestamp,systimestamp+numtodsinterval(1/1000000,'second')
FROM dual;
#5
但是现在这个字段的值是varchar2类型的值,如何转换为timestamp类型的值呢?
#6
我用的AIX,这个问题已经解决了,直接构造像这样的语句
/* 12小时制 */
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtoyminterval(1,'year'),'YYYYMMDDHHMISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtoyminterval(1,'month'),'YYYYMMDDHHMISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtodsinterval(1,'day'),'YYYYMMDDHHMISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtodsinterval(1,'hour'),'YYYYMMDDHHMISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtodsinterval(1,'minute'),'YYYYMMDDHHMISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtodsinterval(1,'second'),'YYYYMMDDHHMISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtodsinterval(5/10,'second'),'YYYYMMDDHHMISSFF1');
/* 24小时制 */
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtoyminterval(1,'year'),'YYYYMMDDHH24MISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtoyminterval(1,'month'),'YYYYMMDDHH24MISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtodsinterval(1,'day'),'YYYYMMDDHH24MISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtodsinterval(1,'hour'),'YYYYMMDDHH24MISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtodsinterval(1,'minute'),'YYYYMMDDHH24MISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtodsinterval(1,'second'),'YYYYMMDDHH24MISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtodsinterval(5/10,'second'),'YYYYMMDDHH24MISSFF1');
然后再用EXECUTE语句执行,搞定,因为开始我就是想到先用select语句导出来用C来处理,但是觉得有点恐怖,所以一直在试直接用数据库语句来执行,多谢codearts兄提供的思路和方法,很有收获!
/* 12小时制 */
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtoyminterval(1,'year'),'YYYYMMDDHHMISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtoyminterval(1,'month'),'YYYYMMDDHHMISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtodsinterval(1,'day'),'YYYYMMDDHHMISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtodsinterval(1,'hour'),'YYYYMMDDHHMISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtodsinterval(1,'minute'),'YYYYMMDDHHMISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtodsinterval(1,'second'),'YYYYMMDDHHMISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtodsinterval(5/10,'second'),'YYYYMMDDHHMISSFF1');
/* 24小时制 */
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtoyminterval(1,'year'),'YYYYMMDDHH24MISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtoyminterval(1,'month'),'YYYYMMDDHH24MISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtodsinterval(1,'day'),'YYYYMMDDHH24MISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtodsinterval(1,'hour'),'YYYYMMDDHH24MISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtodsinterval(1,'minute'),'YYYYMMDDHH24MISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtodsinterval(1,'second'),'YYYYMMDDHH24MISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtodsinterval(5/10,'second'),'YYYYMMDDHH24MISSFF1');
然后再用EXECUTE语句执行,搞定,因为开始我就是想到先用select语句导出来用C来处理,但是觉得有点恐怖,所以一直在试直接用数据库语句来执行,多谢codearts兄提供的思路和方法,很有收获!
#1
select sysdate, sysdate+1/24, sysdate +1/1440, sysdate + 1/86400 from dual;
#2
date类型不能到毫秒的,要用timestamp类型.
用numtodsinterval这个函数进行加减(毫秒的还没找到)
select sysdate + numtodsinterval(150, 'DAY') from dual;
numtodsinterval(1500, 'HOUR')
numtodsinterval(15000, 'MINUTE')
numtodsinterval(150000, 'SECOND')
用numtodsinterval这个函数进行加减(毫秒的还没找到)
select sysdate + numtodsinterval(150, 'DAY') from dual;
numtodsinterval(1500, 'HOUR')
numtodsinterval(15000, 'MINUTE')
numtodsinterval(150000, 'SECOND')
#3
SQL> create table t(a timestamp);
表已创建。
SQL> insert into t(a) values(systimestamp);
已创建 1 行。
SQL> update t set a=a+numtodsinterval(1,'day') --加一天
2 ;
已更新 1 行。
SQL> update t set a=a+numtodsinterval(1,'hour') --加一小时
2 ;
已更新 1 行。
SQL> update t set a=a+numtodsinterval(1,'second') --加一秒
2 ;
已更新 1 行。
SQL> update t set a=a+numtodsinterval(500/1000,'second') --加500毫秒
2 ;
已更新 1 行。
SQL> select * from t;
A
---------------------------------------------------------------------------
2008-02-28 12:35:34.546000
表已创建。
SQL> insert into t(a) values(systimestamp);
已创建 1 行。
SQL> update t set a=a+numtodsinterval(1,'day') --加一天
2 ;
已更新 1 行。
SQL> update t set a=a+numtodsinterval(1,'hour') --加一小时
2 ;
已更新 1 行。
SQL> update t set a=a+numtodsinterval(1,'second') --加一秒
2 ;
已更新 1 行。
SQL> update t set a=a+numtodsinterval(500/1000,'second') --加500毫秒
2 ;
已更新 1 行。
SQL> select * from t;
A
---------------------------------------------------------------------------
2008-02-28 12:35:34.546000
#4
恩,不错!
学到了,可以到微秒:
SELECT systimestamp,systimestamp+numtodsinterval(1/1000000,'second')
FROM dual;
学到了,可以到微秒:
SELECT systimestamp,systimestamp+numtodsinterval(1/1000000,'second')
FROM dual;
#5
但是现在这个字段的值是varchar2类型的值,如何转换为timestamp类型的值呢?
#6
我用的AIX,这个问题已经解决了,直接构造像这样的语句
/* 12小时制 */
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtoyminterval(1,'year'),'YYYYMMDDHHMISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtoyminterval(1,'month'),'YYYYMMDDHHMISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtodsinterval(1,'day'),'YYYYMMDDHHMISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtodsinterval(1,'hour'),'YYYYMMDDHHMISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtodsinterval(1,'minute'),'YYYYMMDDHHMISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtodsinterval(1,'second'),'YYYYMMDDHHMISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtodsinterval(5/10,'second'),'YYYYMMDDHHMISSFF1');
/* 24小时制 */
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtoyminterval(1,'year'),'YYYYMMDDHH24MISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtoyminterval(1,'month'),'YYYYMMDDHH24MISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtodsinterval(1,'day'),'YYYYMMDDHH24MISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtodsinterval(1,'hour'),'YYYYMMDDHH24MISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtodsinterval(1,'minute'),'YYYYMMDDHH24MISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtodsinterval(1,'second'),'YYYYMMDDHH24MISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtodsinterval(5/10,'second'),'YYYYMMDDHH24MISSFF1');
然后再用EXECUTE语句执行,搞定,因为开始我就是想到先用select语句导出来用C来处理,但是觉得有点恐怖,所以一直在试直接用数据库语句来执行,多谢codearts兄提供的思路和方法,很有收获!
/* 12小时制 */
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtoyminterval(1,'year'),'YYYYMMDDHHMISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtoyminterval(1,'month'),'YYYYMMDDHHMISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtodsinterval(1,'day'),'YYYYMMDDHHMISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtodsinterval(1,'hour'),'YYYYMMDDHHMISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtodsinterval(1,'minute'),'YYYYMMDDHHMISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtodsinterval(1,'second'),'YYYYMMDDHHMISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHHMISSFF')+numtodsinterval(5/10,'second'),'YYYYMMDDHHMISSFF1');
/* 24小时制 */
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtoyminterval(1,'year'),'YYYYMMDDHH24MISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtoyminterval(1,'month'),'YYYYMMDDHH24MISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtodsinterval(1,'day'),'YYYYMMDDHH24MISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtodsinterval(1,'hour'),'YYYYMMDDHH24MISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtodsinterval(1,'minute'),'YYYYMMDDHH24MISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtodsinterval(1,'second'),'YYYYMMDDHH24MISSFF1');
update TESTTIME set time=to_char(TO_TIMESTAMP(time, 'YYYYMMDDHH24MISSFF')+numtodsinterval(5/10,'second'),'YYYYMMDDHH24MISSFF1');
然后再用EXECUTE语句执行,搞定,因为开始我就是想到先用select语句导出来用C来处理,但是觉得有点恐怖,所以一直在试直接用数据库语句来执行,多谢codearts兄提供的思路和方法,很有收获!