不包括一个月的时间段

时间:2018-04-24 19:35:32

标签: sql plsql

我必须在一个月内得到结果,不包括每天的时间段。到目前为止我有以下查询

  SET SERVEROUTPUT ON;
  DECLARE
  CURSOR login_hist
  IS
   SELECT
     login_id, insert_date
   FROM
      Login_history
      where to_char(insert_date,'DD-MM-YY:HH:MM:SS') > '12-Mar-10'

    ORDER BY
      insert_date DESC; 
  BEGIN
   FOR cur IN login_hist
   LOOP
    DBMS_OUTPUT.PUT_LINE( cur.login_id || ': $'      ||to_char(cur.insert_date,'DD-MM-YY:HH:MM:SS') );
    END LOOP;
  END;

-- Excludig hours 10:00am till 15:00 pm over a period of month

2 个答案:

答案 0 :(得分:0)

您只需从where子句中删除:HH:MM:SS即可。

SET SERVEROUTPUT ON;
DECLARE
CURSOR login_hist
IS
 SELECT
   login_id, insert_date
 FROM
  Login_history
  where to_char(insert_date,'DD-MM-YY') > '12-Mar-10'
 ORDER BY
  insert_date DESC; 

BEGIN
 FOR cur IN login_hist
 LOOP
  DBMS_OUTPUT.PUT_LINE( cur.login_id || ': $' ||to_char(cur.insert_date,'DD-MM-YY') );
END LOOP;
END;

答案 1 :(得分:0)

将where子句更新为:

where to_char(insert_date,'hh24:mi:ss') < '10:00:00'
AND to_char(insert_date,'hh24:mi:ss') > '15:00:00'

MM代表月份,mi代表分钟