表子段:
id number primary key(值不能重,不能是空) name varchar2(30) money number odate date

1 ,‘jd0001’,123.45 ,sysdate

2 ,‘jd0002’,345.85 ,sysdate



把id等于2的订单钱数改为2345.68。

‘dd - MON - yy’
to_char ( par1 , par2 ) par1 要处理的日期数据或者日期字段 par2 是日期格式
日期格式:

select id, salary, start_date from s_emp order by start_date;

。。。。。。

用to_char改过的格式可以避免一些误会:
select id, salary, to_char(start_date, ‘yyyy-mm-dd hh24:mi:ss‘) start_date from s_emp order by start_date;

。。。。。。

查看s_emp的脚本可得只有id=1的时间是to_date放入了年月日时分秒,其他的都是默认放入日期(08-MAR-90),时分秒默认0。
to_date(par1,par2) /*把日期字符串变成日期*/
insert into myorder values(2008, ‘bj00001‘, 200000,to_date(‘2008-08-08 20:08:08‘, ‘yyyy-mm-dd hh24:mi:ss‘)); select id, to_char(odate, ‘yyyy-mm-dd hh24:mi:ss‘) odate from myorder where id=2008;

insert into myorder values(2012, ‘chuan_piao‘, 888888,to_date(‘2012-12-22 23:59:59‘, ‘yyyy-mm-dd hh24:mi:ss‘)); select id, to_char(odate, ‘yyy-mm=dd hh24:mo:ss‘);

表现当前系统日期:
select to_char(sysdate, ‘yyyy-mm-dd hh24:mi:ss‘) from dual;

调整一天:加1
select to_char(sysdate+1, ‘yyyy-mm-dd hh24:mi:ss‘) from dual;

调整一个小时:加1/24
select to_char(sysdate, ‘yyyy-mm-dd hh24:mi:ss‘), to_char(sysdate+1/24, ‘yyyy-mm-dd hh24:mi:ss‘) from dual;

按照分钟按照秒为单位调整以此类推:
select to_char(sysdate, ‘yyyy-mm-dd hh24:mi:ss‘), to_char(sysdate+1/24(24*60*60), ‘yyyy-mm-dd hh24:mi:ss‘) from dual;

add_months(par1,par2) 按月为单位进行调整
select to_char(sysdate, ‘yyyy-mm-dd hh24:mi:ss‘), to_char(add_mouths(sysdate, 1), ‘yyyy-mm-dd hh24:mi:ss‘) from dual;

round(par1,par2)(用的少)
‘hh’是小时为单位(半个小时以上就入,半个小时以下舍)
‘mm’月,‘yy’年
以天为单位:
select to_char(sysdate,‘yyyy-mm-dd hh24:mi:ss‘), to_char(round(sysdate), ‘yyyy-mm-dd hh24:mi:ss‘) from dual;

以小时为单位:
select to_char(sysdate,‘yyyy-mm-dd hh24:mi:ss‘), to_char(round(sysdate), ‘hh‘, ‘yyyy-mm-dd hh24:mi:ss‘) from dual;

trunc(par1,par2)(用的少)
用法和round一样,只是不入,不管后面是多少都直接截掉
select to_char(sysdate, ‘yyyy-mm-dd hh24:mi:ss‘), to_char(trunc(sysdate, ‘mm‘), ‘yyyy-mm-dd hh24:mi:ss‘) from dual;

sysdate 得到这个日期对应的月的最后一天的最后一秒
8月应该得到:2014-08-31 23:59:59
‘2008-01-20 08:30:25’应该得到:2014-01-31 23:59:59
select to_char(sysdate, ‘yyyy-mm-dd hh24:mi:ss‘), to_char(add)months(trunc(sysdate, ‘mm ‘),1)-1/(24*60*60),
‘yyyy-mm-dd hh24:mi:ss‘) from dual;

last_day(par1)得到日期对应的月的最后一天对应的时间点
select to_char(sysdate, ‘yyyy-mm-dd hh24:mi:ss‘), to_char(trunc(last_day(sysdate))+1-1/(24*60*60), ‘yyyy-mm-dd hh24:mi:ss‘) from dual;

next_day(par1,par2)下个星期几的时间点
08-25是星期一,下一个星期一是09-01
select to_char(sysdate, ‘yyyy-mm-dd hh24:mi:ss‘), to_char(mext_day(sysdate, ‘moneday‘), ‘yyyy-mm-dd hh24:mi:ss‘) from dual;

08-25是星期一,下一个星期五是08-29(离08-25最近的周五)
select to_char(sysdate, ‘yyyy-mm-dd hh24:mi:ss‘), to_char(mext_day(sysdate,‘friday‘), ‘yyyy-mm-dd hh24:mi:ss‘) from dual;

原文:https://www.cnblogs.com/cjaaron/p/9215146.html