Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: Sql question

RE: Sql question

From: Mercadante, Thomas F <NDATFM_at_labor.state.ny.us>
Date: Fri, 29 Jun 2001 11:29:37 -0700
Message-ID: <F001.0033DEB9.20010629113124@fatcity.com>

John,

just fooling around, I came up with this. run it thru sqlplus. obviously, change the table reference to your table.

set serveroutput on
spool results.xls
DECLARE
l_date DATE;
start_date DATE := to_date('&s_date','mm/dd/yyyy'); end_Date DATE := to_date('&e_Date','mm/dd/yyyy'); loc_sum number;
BEGIN
  l_date := start_date;
LOOP
  SELECT SUM(col1)
    INTO loc_sum
  FROM TOM3
  WHERE crdate = l_date;
  dbms_output.put_line(TO_CHAR(l_date,'mm/dd/yyyy') || CHR(9) || nvl(loc_sum,0));
  l_date := l_date + 1;
  EXIT WHEN l_date > end_date;
END LOOP;
END;
/

hope this helps

Tom Mercadante
Oracle Certified Professional

-----Original Message-----
Sent: Friday, June 29, 2001 2:37 PM
To: Multiple recipients of list ORACLE-L

I want to get every date between two user entered date's whether or not it exists in the table and then the quantity of data for the date if any exists.
My table t1 has date and quantity values (may be more than one quantity field per date)
and I want 0 for all dates in the range where no data exists. Is there a sql to get this without making some kind of date table? so if the user enters 03/02/01 and 03/06/01 they get.

03/02/01        10
03/03/01        1
03/04/01        0
03/05/01        0
03/06/01        8

They want to load into a spreadsheet.
tia.
--

Please see the official ORACLE-L FAQ: http://www.orafaq.com
--

Author: Shaw, John B
  INET: jbshaw_at_ingr.com
Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).
--

Please see the official ORACLE-L FAQ: http://www.orafaq.com
--

Author: Mercadante, Thomas F
  INET: NDATFM_at_labor.state.ny.us
Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing). Received on Fri Jun 29 2001 - 13:29:37 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US