begin
    if sysdate between '7:00'and '17:00' then
      dbms_output.put_line('在');
    else
      dbms_output.put_line('不在');
    end if;
    end;
如何判断当点时间在7:00到17:00之间?

解决方案 »

  1.   

    if to_number(to_char(sysdate,'hh24')) between 7 and 17 then 试试吧,好久没写sp了.
      

  2.   

    谢谢,minitoy!我可是想了好久的。还以为时间不能用数值去判断
      

  3.   

    不包括17吧
    if to_number(to_char(sysdate,'hh24')) between 7 and 16 then  
      

  4.   

    begin
      if sysdate between to_date('7:00','mi:ss') and to_date('17:00','mi:ss') then
        dbms_output.put_line('在');
      else
        dbms_output.put_line('不在');
      end if;
    end;
      

  5.   

    不行啊!时间格式改成“hh24:mi”后,仍不能判断的。在时间段里面,也输出‘不在’
      

  6.   

      select to_date('9:00','hh24:mi') from dual;
    返回的是当月的1号的9:00,也就是2011-8-1 上午 09:00:00(现在是8月30日) 所以当然会输出“不在”
    这是症结所在。用当天的时间比较才行,可是如何表达呢?
      

  7.   

    begin
      if to_date(to_char(sysdate,'hh24:mi:ss'),'hh24:mi:ss') between to_date('7:00','hh24:mi:ss') and to_date('17:00','hh24:mi:ss') then
        dbms_output.put_line('在');
      else
        dbms_output.put_line('不在');
      end if;
    end;
      

  8.   

    如果要用当天的
    begin
      if sysdate between to_date(to_char(sysdate,'yyyy-mm-dd')||' 7:00','yyyy-mm-dd hh24:mi:ss') and to_date(to_char(sysdate,'yyyy-mm-dd')||' 15:00','yyyy-mm-dd hh24:mi:ss') then
        dbms_output.put_line('在');
      else
        dbms_output.put_line('不在');
      end if;
    end;
      

  9.   

    不行啊。
    to_date(to_char(sysdate,'hh24:mi:ss'),'hh24:mi:ss')
    返回的是这个月1号的时间,怎么可能对。我要判断当前时间是否在这个时间段内