oracle SQL 語句取本週 本月 本年的資料

2021-06-18 07:28:26 字數 594 閱讀 1093

--國內從周一到週日 國外是週日到週六

select to_char(sysdate-1,'d') from dual;--取國內的星期幾 去掉減一取國外的星期--

--取本週時間內的資料

select * from table where dtime >=trunc(next_day(sysdate-8,1)+1) and dtime<=trunc(next_day(sysdate-8,1)+7)+1 ;

select * from table where dtime >=trunc(next_day(sysdate-8,1)) and dtime<=trunc(next_day(sysdate-8,1)+7);--國外的

select * from table where dtime >=trunc(sysdate, 'mm') and dtime<=last_day(sysdate);

--本月的

select * from table where to_char(dtiem,'yyyy')=to_char(sysdate,'yyyy');

--本年的

常用oracle sql語句

建立表空間 alter tablespace nm offline drop tablespace nm including contents and datafiles drop user nmcascade create tablespace nm datafile 1 size 500m au...

Oracle SQL語句優化

1,建表時 1 建立主鍵 2 建立索引 3 如果表資料量很大考慮建立分割槽 4 可以使用number型別的就不適用varchar2,這是因為引擎在處理查詢和連線時會逐個比較字串中每乙個字元,而對於數字型而言只需要比較一次就夠了。2,建立索引注意事項 1 首先應考慮在 where 及 order by...

oracle sql 複雜語句

1.oracle行轉列,pivot函式和unpivot函式 2.start with connect by prior 遞迴查詢用法 樹形結構的資料 例如組織機構樹 3.資料誤刪恢復 select from 表名稱 as of timestamp to timestamp 2020 05 07 08...