1、當(dāng)時(shí)間條件字段為字符串類型的時(shí)候,通過以下方法查詢數(shù)據(jù):
目前創(chuàng)新互聯(lián)公司已為上1000+的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬主機(jī)、網(wǎng)站托管運(yùn)營(yíng)、企業(yè)網(wǎng)站設(shè)計(jì)、海晏網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。
1.1、SELECT * FROM 表名 t WHERE 1=1 AND to_date(t.tkdat,'yyyy/MM/dd')
between to_date('2017/8/1','yyyy/MM/dd') and to_date('2017/11/1','yyyy/MM/dd');
1.2、SELECT * FROM zsd018a t WHERE 1=1 AND to_date(t.tkdat,'yyyy/MM/dd hh24:mi:ss')
between to_date('2017/8/1','yyyy/MM/dd hh24:mi:ss') and to_date('2017/11/1','yyyy/MM/dd hh24:mi:ss');
2、當(dāng)時(shí)間條件為date類型的時(shí)候,通過以下方法查詢數(shù)據(jù):
select * from zmm028 where to_char(tkdat,'YYYY-MM-DD')='2017-10-01'
and to_char(tkdat,'YYYY-MM-DD')='2017-11-02' ;
range分區(qū)可以直接通過filter分區(qū)鍵查詢,oracle會(huì)根據(jù)執(zhí)行計(jì)劃自動(dòng)優(yōu)化sql
oracle 查詢?nèi)掌趨^(qū)間內(nèi)的數(shù)據(jù)一般最常用的就是between and 和=,=(或者不要等號(hào))了;
舉例:select * from tablename t where t.日期列 between to_date('2015-10-20 00:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('2015-10-20 23:59:59','yyyy-mm-dd hh24:mi:ss')
或者:
select * from tablename where t.日期列 = to_date('2015-10-20 00:00:00','yyyy-mm-dd hh24:mi:ss') and t.日期列 = to_date('2015-10-20 23:59:59','yyyy-mm-dd hh24:mi:ss')
如果要查詢開區(qū)間的數(shù)據(jù)只需將= 和=改為和就行。
where?1=1?and
IN_AVG_VALUE?BETWEEN?'30'?AND?'50'
or?
IN_MAX_VALUE?BETWEEN?'30'?AND?'50'
or?
IN_MIN_VALUE?BETWEEN?'30'?AND?'50'
你好,可以使用oracle的to_char( )函數(shù)將時(shí)間轉(zhuǎn)化為字符串,然后再進(jìn)行查詢,sql如下:
select * from table where to_char(time,'yyyy')='2016' and to_char(time,'hh:mm:ss')'16:00:00'