您的位置:首页 > 其它

日期格式相关

2016-03-01 14:51 316 查看
字符替换
updatetzincident2015_yuan s
set s.发生时间=replace(s.发生时间,'年','/');
updatetzincident2015_yuan s
set s.发生时间=replace(s.发生时间,'月','/');
updatetzincident2015_yuan s
set s.发生时间=replace(s.发生时间,'日','
');
updatetzincident2015_yuan s
set s.发生时间=replace(s.发生时间,'时',':');
updatetzincident2015_yuan s
set s.发生时间=replace(s.发生时间,'分',':00');

字符提取
update tzincident2015_yuan
set发生时间_月=(substr(发生时间,instr(发生时间,'/',1,1)+1,
instr(发生时间,'/',1,2)-1-instr(发生时间,'/',1,1)));
update tzincident2015_yuan
set发生时间_日=(substr(发生时间,instr(发生时间,'/',1,2)+1,
instr(发生时间,' ',1,1)-1-instr(发生时间,'/',1,2)));
update tzincident2015_yuan
set发生时间_时=(substr(发生时间,instr(发生时间,'
',1,1)+1,
instr(发生时间,':',1,1)-1-instr(发生时间,'
',1,1)));

字符判断
Select to_char(sysdate,'ss')
from dual;取当前时间秒部分
Select to_char(sysdate,'mi')
from dual;取当前时间分钟部分
Select to_char(sysdate,'HH24')
from dual;取当前时间秒小时部分
Select to_char(sysdate,'DD')
from dual;取当前时间日期部分
Select to_char(sysdate,'MM')
from dual;取当前时间月部分
Select to_char(sysdate,'YYYY')
from dual;取当前时间年部分
Select to_char(sysdate,'w')
from dual;取当前时间是一个月中的第几周(从1日开始算)

Select to_char(sysdate,'ww')
from dual;取当前时间是一年中的第几周(从1.1开始算)
Select to_char(sysdate,'iw')
from dual;取当前时间是一年中的第几周(按实际日历的)
Select to_char(sysdate,'d')
from dual;取当前时间是一周的第几天,从星期天开始,周六结束
Select to_char(sysdate,'day')
from dual; 取当前日是星期几,和数据库设置的字符集有关,会输出'Tuesday'
Select to_char(sysdate,'ddd')
from dual ;当前日是一年中的第几天
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: