Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Something like this (assuming your table is named <code>your_table</code> and the date column is named <code>the_date</code>):</p> <pre><code>with date_range as ( select min(the_date) as oldest, max(the_date) as recent, max(the_date) - min(the_date) as total_days from your_table ), all_dates as ( select oldest + level - 1 as a_date from date_range connect by level &lt;= (select total_days from date_range) ) select ad.a_date from all_dates ad left join your_table yt on ad.a_date = yt.the_date where yt.the_date is null order by ad.a_date; </code></pre> <p><strong>Edit:</strong> <br/> the <code>WITH</code> clause is called a "common table expression" and is equivalent to a derived table ("inline view"). </p> <p>It's similar to </p> <pre><code>select * from ( ..... ) all_dates join your_table ... </code></pre> <p>The second CTE simply creates a list of dates "on-the-fly" using a undocumented feature of Oracle's <code>connect by</code> implementation. </p> <p>Re-using a select (like I did with calculating the first and last date) is a bit easier (and IMHO more readable) than using derived tables.</p> <p><strong>Edit 2:</strong><br/></p> <p>This can be done with a recursive CTE as well:</p> <pre><code>with date_range as ( select min(the_date) as oldest, max(the_date) as recent, max(the_date) - min(the_date) as total_days from your_table ), all_dates (a_date, lvl) as ( select oldest as a_date, 1 as lvl from date_range union all select (select oldest from date_range) + lvl, lvl + 1 from all_dates where lvl &lt; (select total_days from date_range) ) select ad.a_date, lvl from all_dates ad left join your_table yt on ad.a_date = yt.the_date where yt.the_date is null order by ad.a_date; </code></pre> <p>Which should work in all DBMS supporting recursive CTEs (PostgreSQL and Firebird - being more standard compliant - do need the <code>recursive</code> keyword though).</p> <p>Note the hack <code>select (select oldest from date_range) + lvl, lvl + 1</code> in the recursive part. This should not be necessary, but Oracle still has some bugs with regards to DATEs in a recursive CTE. In PostgreSQL the following works without problems:</p> <pre><code>.... all_dates (a_date, lvl) as ( select oldest as a_date, 0 as lvl from date_range union all select a_date + 1, lvl + 1 from all_dates where lvl &lt; (select total_days from date_range) ) .... </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload