Oracle 日期查詢

2021-06-28 13:36:48 字數 3299 閱讀 6757

例如:select * from c where  cdate>=to_date('2010-10-14 14:00:00','yyyy-mm-dd hh24:mi:ss')

select * from mytable where to_char(install_date,'yyyymmdd') > '20050101'

select   *   from   mytable   where   install_date     >   to_date('20050101','yyyymmdd');

取得當前日期是本月的第幾周

sql>   select   to_char(sysdate,'yyyymmdd   w   hh24:mi:ss')   from   dual;    to_char(sysdate,'yy ------------------- 20080327   4   18:16:09    sql>   select   to_char(sysdate,'w')   from   dual; 

t - 4

№2:取得當前日期是乙個星期中的第幾天,注意星期日是第一天

sql>   select   sysdate,to_char(sysdate,'d')   from   dual;    

sysdate       t ---------   - 27-mar-08   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 date0 from (select rownum rn from all_objects where 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;

no17:返回某個月的最後一天

select to_char(last_day(sysdate),'dd') from dual

引數傳遞,number型插入空值 昨天在程式中遇到乙個資料型別轉換的問題,在傳遞引數時,往number型別中插入空值出現的問題:

例如:string cskzcxcl ;

para[0] = new oracleparameter(":cskzcxcl", oracletype.number, 9);              

para[0].value = cskzcxcl;

總是報錯,說是資料型別的問題; 經過本人今天在朋友的幫助下,總算找到了解決辦法:

para[0].value =dbnull.value;

這樣再插入空字串時就不會出錯;

oracle中lpad和rpad的用法 lpad和rpad的用法 select lpad('b',10,'-') || 欄位名 from 表1;

在 b 的左邊插入10個 '-' 字元.

select rpad('b',10,'-') || 欄位名 from 表1;

在 b 的右邊插入10個 '-' 字元.

oracle 日期查詢

1.string hql select substr to char create time,yyyy mm dd hh24 mm ss 1,10 count createtime from sitebean where to char createtime,yyyy mm dd to char t...

oracle 查詢日期

查詢乙個季度的第一天 select trunc sysdate,q from dual 查詢乙個季度的最後一天 select add months trunc to date 2010 02 01 yyyy mm dd q 3 1 from dual 查詢當前日期以前3個小時的資料 select s...

Oracle日期區間查詢

有個需求 在表中查詢 2020年1月至今的所有的資料 但是提供的年份和月份是兩個字段 這裡使用 即可拼接 select distinct wa data.year wa data.month,wa data.month from wa data where wa data.year wa data....