Oracle關於一周內資料查詢 DATE

2021-07-29 19:01:39 字數 1107 閱讀 8437

trunc的用法:

1.select trunc(sysdate) from dual --2013-01-06 今天的日期為2013-01-06

2.select trunc(sysdate, 'mm') from dual --2013-01-01 返回當月第一天.

3.select trunc(sysdate,'yy') from dual --2013-01-01 返回當年第一天

4.select trunc(sysdate,'dd') from dual --2013-01-06 返回當前年月日

5.select trunc(sysdate,'yyyy') from dual --2013-01-01 返回當年第一天

6.select trunc(sysdate,'d') from dual --2013-01-06 (星期天)返回當前星期的第一天

7.select trunc(sysdate, 'hh') from dual --2013-01-06 17:00:00 當前時間為17:35

8.select trunc(sysdate, 'mi') from dual --2013-01-06 17:35:00 trunc()函式沒有秒的精確

中國的日期是由國外演變而來的。

因此0代表的是週日

當前系統時間的下一星期一的時間select   next_day(sysdate,1)   from   dual 

我想查詢上周二到這周一的資料:

select

trunc (next_day(sysdate - 8, 1) - 5),

trunc (sysdate, 'd') + 1

from

t_price_index;

此處主要是前面的next_day函式, -8為上個星期,1表示從上個星期-8天往後推的第一天,即星期日,-5表示為了適應中國的習慣,第二天為星期二,所以一般來說是+2,這裡要-5是要表示上個星期

三年內:

date_price > trunc (sysdate) - (interval '3' year)

三周內:

to_date (date_stock) > to_date (add_months(sysdate ,- 3))

使用sql語句查詢日期在一周內的資料

最近在作公司的乙個專案時用到了查詢同一周內的資料,感覺挺有用的。sql語句是 select from 表 where datediff week,時間字段,getdate 0 也可以稍作修改用來查詢與指定日期在同一周內的資料 select from 表 where datediff week,時間字...

oracle高階資料查詢技術

實驗目的 一 掌握日期型資料的操作技術 二 掌握層次查詢技術 三 理解情景查詢與翻譯查詢技術 四 了解統計查詢技術 實驗內容 一 日期型資料的操作 日期型資料的查詢顯示 不同語言環境下日期型資料查詢結果的差異 session 每建立乙個連線connection會建立乙個session會話 自由控制日...

8 11Oracle 資料查詢

重點 單張表的curd 多張表的curd 1 sql sql structed query language 結構化查詢語言 授權 scott把查詢emp的許可權給tom grant select on emp to tom 語句要傳輸到oracle伺服器,被執行 2 查詢 select 字段 fr...