如题,pl/sql连的是oracle哦。
                 比如A表的phCC006字段为时间类型,通过phCC006字段来搜索A表中的数据。
                 比如搜索2011-10-09到2011-10-10的数据。
                 或者2011-10-09前的数据,2011-10-09后的数据。

解决方案 »

  1.   

    select * from A
    where phcc006 between to_date(20111009,'yyyymmdd') and to_date(20111010,'yyyymmdd')
    select * from A
    where phcc006 < to_date(20111009,'yyyymmdd') or phcc006 >to_date(20111009,'yyyymmdd')
      

  2.   


      PCC006 是DATE类型的,存进来的是2011-08-19 11:00:01这样的。按第一个语句那么查询查不出数据来。
      

  3.   

    1、如果传入进来的参数是时间类型的
    (假设参数是i_date1=2011-08-19 11:00:01,i_date2=2011-08-28 11:00:01),那么可以这样写:   select * from A t
       where t.phcc006 
     between to_date(to_char(i_date1,'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd') 
         and to_date(to_char(i_date2,'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd'); select * from A t
      where t.phcc006 < to_date(to_char(i_date1,'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd'); 
        
       select * from A t
        where t.phcc006 > to_date(to_char(i_date2,'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd');1、如果传入进来的参数是字符串类型的
      (假设参数是i_date1=2011-08-19 11:00:01,i_date2=2011-08-28 11:00:01),那么可以这样写:   select * from A t
       where t.phcc006 between to_date(substr(i_date1,1,10),'yyyy-mm-dd') 
                           and to_date(substr(i_date2,1,10),'yyyy-mm-dd');   select * from A t
        where t.phcc006 < to_date(substr(i_date1,1,10),'yyyy-mm-dd') ;
        
       select * from A t
        where t.phcc006 > to_date(substr(i_date2,1,10),'yyyy-mm-dd');
      
      

  4.   

    (假设参数是i_date1=2011-08-19 11:00:01,i_date2=2011-08-28 11:00:01),那么可以这样写:select * from lr_book where recommend_date between to_date('"+date1+"','yyyy-mm-dd hh24:mi:ss') and to_date('"+date2+"','yyyy-mm-dd hh24:mi:ss')
    select * from lr_book where recommend_date < to_date('"+date1+"','yyyy-mm-dd hh24:mi:ss') or  recommend_date>to_date('"+date2+"','yyyy-mm-dd hh24:mi:ss')
      

  5.   

    --搜索2011-10-09到2011-10-10的数据。
    select * from A
    where to_char(phcc006,'yyyy-mm-dd')>='2011-10-09' 
     and  to_char(phcc006,'yyyy-mm-dd')<='2011-10-10' 
    --2011-10-09前的数据
    select * from A
    where to_char(phcc006,'yyyy-mm-dd')<'2011-10-09' 
    --2011-10-09后的数据
    select * from A
    where to_char(phcc006,'yyyy-mm-dd')>'2011-10-09'