select ryrq, extract (year from ryrq), extract (month from ryrq), extract (day from ryrq) from zy_brry where zyh=6830
上面的方法获取的都是把0省略后的值,目标是获取2016、04、02
===========================================================
select csny,substr(to_char(csny,'yyyy'),1,4) csyear,substr(to_char(csny,'mm'),1,2) csmonth,
substr(to_char(csny,'dd'),1,2) csday from zy_brry where zyh=6830
===========================================================================================
上面这种方法截取一下也可以,
===================================================================================
这个substr截取日期好像规则与截取字符窜有点区别
=============================================================
现在问题是hour变成12小时制的了,然后用下面的方法改一下就好了
=============================================================
select substr(to_char(ryrq,'yyyy'),1,4) ryyear,substr(to_char(ryrq,'mm'),1,2) rymonth,
substr(to_char(ryrq,'dd'),1,2) ryday,substr(to_char(ryrq,'hh'),1,2) ryhour ,
substr(to_char(cyrq,'yyyy'),1,4) cyyear,substr(to_char(cyrq,'mm'),1,2) cymonth,
substr(to_char(cyrq,'dd'),1,2) cyday,substr(to_char(cyrq,'hh'),1,2) cyhour ,
substr(to_char(csny,'yyyy'),1,4) csyear,substr(to_char(csny,'mm'),1,2) csmonth,
substr(to_char(csny,'dd'),1,2) csday
from zy_brry where zyh=43439
===============================================================