oracle查询日期语句有:1、取得当前日期是本月的第几周,代码为【select to_char(sysdate,'w')】;2、取得当前日期是一个星期中的第几天,代码为【select sysdate,to_char(sysdate,d】。
oracle查询日期语句有:
1:取得当前日期是本月的第几周
sql> select to_char(sysdate,'yyyymmdd w hh24:mi:ss') from dual; to_char(sysdate,'yy20030327 4 18:16:09 sql> select to_char(sysdate,'w') from dual;结果:
4
2:取得当前日期是一个星期中的第几天,注意星期日是第一天
sql> select sysdate,to_char(sysdate,'d')from dual; sysdate t结果:
27-mar-03 5
类似:
select to_char(sysdate,'yyyy') from dual; --年select to_char(sysdate,'q' from dual; --季select to_char(sysdate,'mm') from dual; --月select to_char(sysdate,'dd') from dual; --日ddd 年中的第几天
ww 年中的第几个星期
w 该月中第几个星期
day 周中的星期几
d 今天对映的number
'1','星期日', '2','星期一', '3','星期二', '4','星期三', '5','星期四', '6','星期五', '7','星期六'
hh 小时(12)
hh24 小时(24)
mi 分
ss 秒
3:取当前日期是星期几中文显示:
sql> select to_char(sysdate,'day') from dual; to_char(sysdate,'day')结果:
星期四
4:如果一个表在一个date类型的字段上面建立了索引,如何使用
alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss'5: 得到当前的日期
select sysdate from dual;6: 得到当天凌晨0点0分0秒的日期
select trunc(sysdate) from dual;— 得到这天的最后一秒
select trunc(sysdate) 0.99999 from dual;— 得到小时的具体数值
select trunc(sysdate) 1/24 from dual;select trunc(sysdate) 7/24 from dual;7:得到明天凌晨0点0分0秒的日期
select trunc(sysdate 1) from dual;select trunc(sysdate) 1 from dual;8: 本月一日的日期
select trunc(sysdate,'mm') from dual;9:得到下月一日的日期
select trunc(add_months(sysdate,1),'mm') from dual;10:返回当前月的最后一天?
select last_day(sysdate) from dual; select last_day(trunc(sysdate)) from dual;select trunc(last_day(sysdate)) from dual;select trunc(add_months(sysdate,1),'mm') - 1 from dual;11: 得到一年的每一天
select trunc(sysdate,'yyyy') rn -1 date0from(select rownum rn from all_objectswhere rownum<366);12:今天是今年的第n天
select to_char(sysdate,'ddd') from dual;13:如何在给现有的日期加上2年
select add_months(sysdate,24) from dual;14:判断某一日子所在年分是否为润年
select decode(to_char(last_day(trunc(sysdate,'y') 31),'dd'),'29','闰年','平年') from dual;15:判断两年后是否为润年
select decode(to_char(last_day(trunc(add_months(sysdate,24),'y') 31),'dd'),'29','闰年','平年') from dual;16:得到日期的季度
select ceil(to_number(to_char(sysdate,'mm'))/3) from dual;select to_char(sysdate, 'q') from dual;相关学习推荐:oracle数据库学习教程
域名dns对访问速度有什么影响?如何降低?在云上购买服务器有什么免费音乐软件比较好用 强大的免费音乐软件推荐东港云服务器价格云服务器怎么搭宝塔云服务器摆放网站什么时候需要大带宽遇到百度恶意点击软件如何破解