字段为date,value,现获取到一个字符串类型的日期strDate(格式“YYYYMMDD”),如何查找strDate标识日期所在月,自strDate当日到月末的所有记录。
如:strDate=20101120,如何查询11月20日到11月30日的记录

解决方案 »

  1.   


    select * from tablename 
    where date between to_date('20101120','yyyymmdd') and to_date('20101130','yyyymmdd')
      

  2.   

    月份信息是要通过strDate中获取的,所以不能写死的
      

  3.   

    select * from tablename 
    where date between to_date('20101120','yyyymmdd') and last_day(to_date('20101120','yyyymmdd'))+1-1/24/60/60
      

  4.   

    用last_day函数获取本月的最后一天啊
      

  5.   

    如果你只是存储了天的信息的话,直接
    select * from tablename 
    where date between to_date('20101120','yyyymmdd') and last_day(to_date('20101120','yyyymmdd'))
      

  6.   

    select * from tablename 
    where date between to_date(strdate,'yyyymmdd') 
               and last_day(to_date(strdate,'yyyymmdd'))
      

  7.   

    dt between to_date(strDate,'yyyymmdd') and last_day(to_date(strDate,'yyyymmdd'))
      

  8.   


    between trunc(to_date(strDate,'yyyymmdd'),'mm') and to_date(strDate,'yyyymmdd') 
      

  9.   

    dt between trunc(to_date(strDate,'yyyymmdd'),'mm') and to_date(strDate,'yyyymmdd')
      

  10.   


    select * from tablename 
    where date between to_date(strdate,'yyyymmdd') 
               and last_day(to_date(strdate,'yyyymmdd'))
    select * from tablename 
    where date between trunc(to_date(strDate,'yyyymmdd'),'mm') and to_date(strDate,'yyyymmdd') 
      

  11.   

    为什么会报ora00904的错
    SELECT Date,Value FROM TableName WHERE A=A AND Date between to_date(strDate,'YYYYMMDD') and last_day(to_date(strDate,'YYYYMMDD')) order by Date
      

  12.   

    有没有可能是因为我Date字段是字符串形式保存的,类型不匹配导致
      

  13.   

    strDate是字符串的形式不要紧 
    只有是20101011 这样的就可以 要有单引号的哦 '20101011'
      

  14.   

    strDate=‘20101030’,但还是报错904,我数据表中Date字段是以字符串形式保存的
      

  15.   


    --你的strdate是从另个一表里读出来的? 给你个例子
    已写入 file afiedt.buf  1  with tb as(
      2  select '19810211' strdate from dual)
      3  select emp.* from emp,tb
      4  where hiredate between to_date(strdate,'yyyymmdd')
      5*                and last_day(to_date(strdate,'yyyymmdd'))
    SQL> /     EMPNO ENAME      JOB              MGR HIREDATE              SAL       COMM     DEPTNO
    ---------- ---------- --------- ---------- -------------- ---------- ---------- ----------
          7499 ALLEN      SALESMAN        7698 20-2月 -81           1600        300         30
          7521 WARD       SALESMAN        7698 22-2月 -81           1250        500         30
      

  16.   

    怎么命名字段跟关键字一样 忌讳 你date字段是字符型的A=A AND ---没必要弄个开关放在这 除非是动态
    SELECT Date,Value FROM TableName WHERE  to_date(Date'YYYYMMDD') between to_date(strDate,'YYYYMMDD') and last_day(to_date(strDate,'YYYYMMDD')) order by Date