title: ORA-01841: (full) year must be between -4713 and +9999, and not be 0
body: <p>I get </p>
  
  <blockquote>
    <p>"ORA-01841: (full) year must be between -4713 and +9999, and not be
    0." </p>
  </blockquote>
  
  <p>on random calendaristic data.</p>
  
  <p>I run the following query:</p>
  
  <pre><code>insert into TEMP_TBL
  SELECT COUNT(ea.employee_rk) AS no_logins,
    ea.country_cd,
    ea.nsb_department,
    ea.employee_id,
    NULL,
    NULL
  FROM EMPLOYEE_ACTIVITY ea
    JOIN employee_activity_ded ead
      ON ead.employee_act_ver_sk=ea.employee_act_ver_sk
    JOIN employee_start_end ese
      ON ese.employee_id    = ea.employee_sk
     AND ea.ACTIVITY_DT&gt;=ese.START_REV
     AND ea.ACTIVITY_DT &lt;ese.end_rev
  WHERE TRUNC(ea.ACTIVITY_DT) BETWEEN to_date('01-AUG-2017','DD-MON-YYYY HH24:MI:SS') AND to_date('31-AUG-2017','DD-MON-YYYY HH24:MI:SS');
  
  
  DESC TEMP_TBL;
  
  VALUE_SEC        NUMBER
  COUNTRY_CD    VARCHAR2(50 BYTE)
  NSB_DEPARTMENT         VARCHAR2(50 BYTE)
  EMPLOYEE_RK  VARCHAR2(32 BYTE)
  ACCESS_DAY      DATE
  ACCESS_TIME    DATE
  
  
  DESC employee_start_end;
  
  EMPLOYEE_VERSION_SK              NUMBER(20,0)
  EMPLOYEE_SK   NUMBER(20,0)
  START_REV         DATE
  END_REV             DATE
  EMPLOYEE_ID   VARCHAR2(32 BYTE)
  </code></pre>
  
  <p><code>EMPLOYEE_ACTIVITY</code> has a big number of columns, but what it's important: </p>
  
  <pre><code>ea.ACTIVITY_DT       DATE
  </code></pre>
  
  <p>This error occurs on random data within the tables. What is strange is that when I add <code>TO_DATE</code> to <code>ese.START_REV</code> and to <code>ese.END_REV</code> the error doesn't appear anymore.</p>
  
  <p>Both <code>ese.START_REV</code> and to <code>ese.END_REV</code> have <code>DATE</code> as datatype.</p>
  
  <p>After I add <code>TO_DATE</code> the same query runs without errors:</p>
  
  <pre><code>insert into TEMP_TBL
  SELECT COUNT(ea.employee_rk) AS no_logins,
    ea.country_cd,
    ea.nsb_department,
    ea.employee_id,
    NULL,
    NULL
  FROM EMPLOYEE_ACTIVITY ea
    JOIN employee_activity_ded ead
      ON ead.employee_act_ver_sk=ea.employee_act_ver_sk
    JOIN employee_start_end ese
      ON ese.employee_id    = ea.employee_sk
     AND ea.ACTIVITY_DT&gt;=to_date(ese.START_REV)
     AND ea.ACTIVITY_DT &lt;to_date(ese.end_rev)
  WHERE TRUNC(ea.ACTIVITY_DT) BETWEEN to_date('01-AUG-2017','DD-MON-YYYY HH24:MI:SS') AND to_date('31-AUG-2017','DD-MON-YYYY HH24:MI:SS');
  </code></pre>