example
A reader, January 02, 2006 - 8:04 am UTC
CREATE TABLE "JEFF$DATA_FILES"
( "ID" NUMBER,
"LOAD_DATE" DATE,
"FILE_NAME" VARCHAR2(513),
"FILE_ID" NUMBER,
"TABLESPACE_NAME" VARCHAR2(30),
"BYTES" NUMBER,
"BLOCKS" NUMBER,
"STATUS" VARCHAR2(9),
"RELATIVE_FNO" NUMBER,
"AUTOEXTENSIBLE" VARCHAR2(3),
"MAXBYTES" NUMBER,
"MAXBLOCKS" NUMBER,
"INCREMENT_BY" NUMBER,
"USER_BYTES" NUMBER,
"USER_BLOCKS" NUMBER,
"ONLINE_STATUS" VARCHAR2(7)
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS"
test data:
INSERT INTO JEFF$DATA_FILES ( LOAD_DATE, FILE_NAME, FILE_ID, TABLESPACE_NAME, BYTES, BLOCKS, STATUS,
RELATIVE_FNO, AUTOEXTENSIBLE, MAXBYTES, MAXBLOCKS, INCREMENT_BY, USER_BYTES, USER_BLOCKS,
ONLINE_STATUS ) VALUES (
TO_Date( '12/29/2005 10:18:06 AM', 'MM/DD/YYYY HH:MI:SS AM'), '/u02/oradata/lnx102/users01.dbf'
, 8, 'USERS', 110100480, 26880, 'AVAILABLE', 8, 'YES', 17179860992, 4194302, 320, 110034944
, 26864, 'ONLINE');
INSERT INTO JEFF$DATA_FILES ( LOAD_DATE, FILE_NAME, FILE_ID, TABLESPACE_NAME, BYTES, BLOCKS, STATUS,
RELATIVE_FNO, AUTOEXTENSIBLE, MAXBYTES, MAXBLOCKS, INCREMENT_BY, USER_BYTES, USER_BLOCKS,
ONLINE_STATUS ) VALUES (
TO_Date( '12/29/2005 10:18:06 AM', 'MM/DD/YYYY HH:MI:SS AM'), '/u02/oradata/lnx102/system01.dbf'
, 1, 'SYSTEM', 576716800, 140800, 'AVAILABLE', 1, 'YES', 17179860992, 4194302, 2560
, 576651264, 140784, 'SYSTEM');
INSERT INTO JEFF$DATA_FILES ( LOAD_DATE, FILE_NAME, FILE_ID, TABLESPACE_NAME, BYTES, BLOCKS, STATUS,
RELATIVE_FNO, AUTOEXTENSIBLE, MAXBYTES, MAXBLOCKS, INCREMENT_BY, USER_BYTES, USER_BLOCKS,
ONLINE_STATUS ) VALUES (
TO_Date( '12/29/2005 10:25:12 AM', 'MM/DD/YYYY HH:MI:SS AM'), '/u02/oradata/lnx102/users01.dbf'
, 8, 'USERS', 125829120, 30720, 'AVAILABLE', 8, 'YES', 17179860992, 4194302, 320, 125763584
, 30704, 'ONLINE');
INSERT INTO JEFF$DATA_FILES ( LOAD_DATE, FILE_NAME, FILE_ID, TABLESPACE_NAME, BYTES, BLOCKS, STATUS,
RELATIVE_FNO, AUTOEXTENSIBLE, MAXBYTES, MAXBLOCKS, INCREMENT_BY, USER_BYTES, USER_BLOCKS,
ONLINE_STATUS ) VALUES (
TO_Date( '12/29/2005 10:25:12 AM', 'MM/DD/YYYY HH:MI:SS AM'), '/u02/oradata/lnx102/system01.dbf'
, 1, 'SYSTEM', 576716800, 140800, 'AVAILABLE', 1, 'YES', 17179860992, 4194302, 2560
, 576651264, 140784, 'SYSTEM');
INSERT INTO JEFF$DATA_FILES ( LOAD_DATE, FILE_NAME, FILE_ID, TABLESPACE_NAME, BYTES, BLOCKS, STATUS,
RELATIVE_FNO, AUTOEXTENSIBLE, MAXBYTES, MAXBLOCKS, INCREMENT_BY, USER_BYTES, USER_BLOCKS,
ONLINE_STATUS ) VALUES (
TO_Date( '12/29/2005 10:38:05 AM', 'MM/DD/YYYY HH:MI:SS AM'), '/u02/oradata/lnx102/users01.dbf'
, 8, 'USERS', 104857600, 25600, 'AVAILABLE', 8, 'YES', 17179860992, 4194302, 320, 104792064
, 25584, 'ONLINE');
INSERT INTO JEFF$DATA_FILES ( LOAD_DATE, FILE_NAME, FILE_ID, TABLESPACE_NAME, BYTES, BLOCKS, STATUS,
RELATIVE_FNO, AUTOEXTENSIBLE, MAXBYTES, MAXBLOCKS, INCREMENT_BY, USER_BYTES, USER_BLOCKS,
ONLINE_STATUS ) VALUES (
TO_Date( '12/29/2005 10:38:05 AM', 'MM/DD/YYYY HH:MI:SS AM'), '/u02/oradata/lnx102/system01.dbf'
, 1, 'SYSTEM', 576716800, 140800, 'AVAILABLE', 1, 'YES', 17179860992, 4194302, 2560
, 576651264, 140784, 'SYSTEM');
INSERT INTO JEFF$DATA_FILES ( LOAD_DATE, FILE_NAME, FILE_ID, TABLESPACE_NAME, BYTES, BLOCKS, STATUS,
RELATIVE_FNO, AUTOEXTENSIBLE, MAXBYTES, MAXBLOCKS, INCREMENT_BY, USER_BYTES, USER_BLOCKS,
ONLINE_STATUS ) VALUES (
TO_Date( '01/01/2006 12:59:31 AM', 'MM/DD/YYYY HH:MI:SS AM'), '/u02/oradata/lnx102/users01.dbf'
, 8, 'USERS', 83886080, 20480, 'AVAILABLE', 8, 'YES', 17179860992, 4194302, 320, 83820544
, 20464, 'ONLINE');
INSERT INTO JEFF$DATA_FILES ( LOAD_DATE, FILE_NAME, FILE_ID, TABLESPACE_NAME, BYTES, BLOCKS, STATUS,
RELATIVE_FNO, AUTOEXTENSIBLE, MAXBYTES, MAXBLOCKS, INCREMENT_BY, USER_BYTES, USER_BLOCKS,
ONLINE_STATUS ) VALUES (
TO_Date( '01/01/2006 12:59:31 AM', 'MM/DD/YYYY HH:MI:SS AM'), '/u02/oradata/lnx102/system01.dbf'
, 1, 'SYSTEM', 576716800, 140800, 'AVAILABLE', 1, 'YES', 17179860992, 4194302, 2560
, 576651264, 140784, 'SYSTEM');
commit;
January 02, 2006 - 10:24 am UTC
Your data was "un-interesting", so I tweaked it for SYSTEM.
ops$tkyte@ORA10GR2> select tablespace_name, bytes, load_date from jeff$data_files order by 1, 3;
TABLESPACE BYTES LOAD_DATE
---------- ---------- --------------------
SYSTEM 576716801 29-dec-2005 10:18:06
<<<===== start time
SYSTEM 576716802 29-dec-2005 10:25:12
SYSTEM 576716803 29-dec-2005 10:38:05
<<<===== end time
SYSTEM 576716804 01-jan-2006 00:59:31
USERS 110100480 29-dec-2005 10:18:06
<<<===== start time
USERS 125829120 29-dec-2005 10:25:12
USERS 104857600 29-dec-2005 10:38:05
<<<====== end time
USERS 83886080 01-jan-2006 00:59:31
8 rows selected.
<b>What we want is for each tablespace - the bytes associated with the MAX(load_date) that is LESS THAN or EQUAL TO the input start time (see below for what I used). In other words - the row right above the start time pointer above.
We want the bytes associated with the MAX(LOAD_DATE) that is LESS THAN or EQUAL TO the input end time. In other words the row right above the end time pointer above.
These are the two "byte values" we want - here are the input dates:</b>
ops$tkyte@ORA10GR2>
ops$tkyte@ORA10GR2> variable d1 varchar2(21)
ops$tkyte@ORA10GR2> variable d2 varchar2(21)
ops$tkyte@ORA10GR2>
ops$tkyte@ORA10GR2> exec :d1 := '29-dec-2005 10:20:00'
PL/SQL procedure successfully completed.
ops$tkyte@ORA10GR2> exec :d2 := '01-jan-2006 00:50:00'
PL/SQL procedure successfully completed.
<b>here is one approach - take the set of tablespaces (you could obviously add a predicate to the query to get just SOME of them) and for each tablespace - get the row that satisfies the above need:</b>
ops$tkyte@ORA10GR2>
ops$tkyte@ORA10GR2> select :d1 start_time, :d2 end_time, tablespace_name,
2 (select to_number( substr( max( to_char(load_date,'yyyymmddhh24miss') || bytes), 15 ) )
3 from jeff$data_files
4 where tablespace_name = x.tablespace_name
5 and load_date <= to_date( :d1, 'dd-mon-yyyy hh24:mi:ss' )) start_bytes,
6 (select to_number( substr( max( to_char(load_date,'yyyymmddhh24miss') || bytes), 15 ) )
7 from jeff$data_files
8 where tablespace_name = x.tablespace_name
9 and load_date <= to_date( :d2, 'dd-mon-yyyy hh24:mi:ss' )) end_bytes
10 from (select distinct tablespace_name from jeff$data_files) x
11 /
START_TIME END_TIME TABLESPACE START_BYTES END_BYTES
--------------------- --------------------- ---------- ----------- ----------
29-dec-2005 10:20:00 01-jan-2006 00:50:00 USERS 110100480 104857600
29-dec-2005 10:20:00 01-jan-2006 00:50:00 SYSTEM 576716801 576716803
There are other ways to do this via analytics and what not, but this works.