常见Oracle日期处理问题

前端之家收集整理的这篇文章主要介绍了常见Oracle日期处理问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  • How to know what date it is today
SELECT TO_CHAR(SYSDATE,'D') INTO W_D FROM DUAL;
 or
 SELECT TO_CHAR(SYSDATE,'DAY') INTO W_D FROM DUAL;

1 means Sunday
7 means Saturday

  • How to get Weekends from a period of time.
DROP TABLE WEEKEND;
CREATE TABLE WEEKEND (WEEK_END DATE);

DECLARE
  W DATE := TO_DATE('2016-12-01','YYYY-MM-DD');
  W_D CHAR;
  BEGIN LOOP SELECT TO_CHAR(W,'D') INTO W_D FROM DUAL;
      IF W_D = 1 OR W_D = 7 THEN
        INSERT INTO WEEKEND VALUES (W);
      END IF;
      W := W + 1;
      IF TO_CHAR(W,'YYYY-MM-DD') = '2016-12-30' THEN
        EXIT;
      END IF;
    END LOOP;
  END;
/

猜你在找的Oracle相关文章