Hi Tom,
Is it possible to invert the output below so a horizontal graph with vertical asterisks (corresponding to the growth_mb/begin_interval_time) is displayed? I was able to dynamically display the begin_interval_time horizontally with corresponding growth_mb but am not sure if it is possible to invert the asterisks. I'm basically trying to avoid the need to output to a graphical package so the data can be displayed horizontally.
Thanks in advance!
column growth_mb_graph format a100
column graph format a100
column begin_interval_time format a25
select
s.begin_interval_time,
round(sum(h.space_used_delta/1024/1024),0) growth_mb,
-- don't print the value, just the asterisk
replace
(
rpad
(
(round(sum(h.space_used_delta/1024/1024),0)),
(round(sum(h.space_used_delta/1024/1024),0)/1/1),
'*'
),
(round(sum(h.space_used_delta/1024/1024),0))
)graph
from
dba_hist_seg_stat h,
dba_hist_snapshot s
where
h.snap_id = s.snap_id
and s.begin_interval_time > sysdate - 1/8
group by
s.begin_interval_time
order by
1 desc
/
this is the output:'BEGIN_INTERVAL_TIME GROWTH_MB GRAPH
------------------------- ---------- ----------------------------------------------------------------------------------------------------
2011-08-03 18:30:30.032 24 **********************
2011-08-03 18:20:29.550 38 ************************************
2011-08-03 18:10:28.986 15 *************
2011-08-03 18:00:28.444 13 ***********
2011-08-03 17:50:27.959 35 *********************************
2011-08-03 17:40:27.356 17 ***************
2011-08-03 17:30:26.851 23 *********************
2011-08-03 17:20:26.362 38 ************************************
2011-08-03 17:10:25.859 20 ******************
2011-08-03 17:00:25.256 19 *****************
2011-08-03 16:50:24.758 40 **************************************
2011-08-03 16:40:24.230 18 ****************
2011-08-03 16:30:23.736 24 **********************
2011-08-03 16:20:23.248 36 **********************************
2011-08-03 16:10:22.689 16 **************
2011-08-03 16:00:22.139 15 *************
2011-08-03 15:50:21.628 36 *********************************
this is the code for the horizontal column pivot:
set feedback off
set time off
set pagesize 0
spool sample.seg.growth.graph.vertical.tmp
select
txt1,
(
-- don't place a comma after the last row
case
when txt3 = txt4 then txt2
else txt2||','
end)txt2
/*,
txt3,
txt4
*/
from
(
select
distinct
-- the .12345 case else is to place a dummy number so the max can collapse the output to 1 row
'max((case when s.begin_interval_time = ''' ||s.begin_interval_time||'''' as txt1,
'then round(sum(h.space_used_delta/1024/1024),0) else .12345 end)) as c'||replace(replace(to_char(cast (begin_interval_time as date),'yyyymmdd hh24:mi'),' ',''),':','') as txt2,
-- get begin_interval_time so it can be compared to txt4 so the last row doesn't contain a comma
'c'||replace(replace(to_char(cast (s.begin_interval_time as date),'yyyymmdd hh24:mi'),' ',''),':','') txt3,
(
select
-- get min begin_interval_time so the last row doesn't contain a comma
min
(
'c'||replace(replace(to_char(cast (s.begin_interval_time as date),'yyyymmdd hh24:mi'),' ',''),':','')
)
from
dba_hist_seg_stat h,
dba_hist_snapshot s
where
h.snap_id = s.snap_id
and s.begin_interval_time > sysdate - 1/8
) txt4
from
dba_hist_seg_stat h,
dba_hist_snapshot s
where
h.snap_id = s.snap_id
and s.begin_interval_time > sysdate - 1/8
group by
s.begin_interval_time
order by
txt2 desc
)
/
spool off
set feedback on
set time on
set echo on
set pagesize 500
select
min(round(sum(h.space_used_delta/1024/1024),0)) min,
max(round(sum(h.space_used_delta/1024/1024),0)) max,
@@sample.seg.growth.graph.vertical.tmp
from
dba_hist_seg_stat h,
dba_hist_snapshot s
where
h.snap_id = s.snap_id
and s.begin_interval_time > sysdate - 1/8
group by
s.begin_interval_time
and here's the output:
MIN MAX C201108031830 C201108031820 C201108031810 C201108031800 C201108031750 C201108031740 C201108031730 C201108031720 C201108031710 C201108031700 C201108031650 C201108031640 C201108031630 C201108031620 C201108031610 C201108031600 C201108031550
---------- ---------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- -------------
13 40 24 38 15 13 35 17 23 38 20 19 40 18 24 36 16 15 36
August 04, 2011 - 10:14 am UTC
this is the query I think you want ultimately:
ops$tkyte%ORA11GR2> with data
2 as
3 (
4 select min(round(sum(h.space_used_delta/1024/1024),0)) min,
5 max(round(sum(h.space_used_delta/1024/1024),0)) max,
6 max((case when s.begin_interval_time = '29-JUL-11 03.32.19.717 PM'
7 then round(sum(h.space_used_delta/1024/1024),0)
8 else .12345 end)) as c201107291532,
9 max((case when s.begin_interval_time = '29-JUL-11 12.00.44.722 PM'
10 then round(sum(h.space_used_delta/1024/1024),0)
11 else .12345 end)) as c201107291200,
12 max((case when s.begin_interval_time = '29-JUL-11 11.00.32.537 AM'
13 then round(sum(h.space_used_delta/1024/1024),0)
14 else .12345 end)) as c201107291100,
15 max((case when s.begin_interval_time = '29-JUL-11 10.10.52.713 AM'
16 then round(sum(h.space_used_delta/1024/1024),0)
17 else .12345 end)) as c201107291010,
18 max((case when s.begin_interval_time = '29-JUL-11 08.00.40.000 AM'
19 then round(sum(h.space_used_delta/1024/1024),0)
20 else .12345 end)) as c201107290800
21 from dba_hist_seg_stat h,
22 dba_hist_snapshot s
23 where h.snap_id = s.snap_id
24 and s.begin_interval_time between
25 to_date('29-jul-2011', 'dd-mon-yyyy')
26 and
27 to_date('30-jul-2011','dd-mon-yyyy')
28 group by s.begin_interval_time
29 ),
30 lines
31 as
32 (select level l
33 from dual
34 connect by level <= 41)
35 select min, max,
36 case when l = 41 then to_char(c201107291532,'999,999.9')
37 when (c201107291532-min)/((max-min)/40) >= l then ' *'
38 end c201107291532x,
39 case when l = 41 then to_char(c201107291200,'999,999.9')
40 when (c201107291200-min)/((max-min)/40) >= l then ' *'
41 end c201107291200x,
42 case when l = 41 then to_char(c201107291100,'999,999.9')
43 when (c201107291100-min)/((max-min)/40) >= l then ' *'
44 end c201107291100x,
45 case when l = 41 then to_char(c201107291010,'999,999.9')
46 when (c201107291010-min)/((max-min)/40) >= l then ' *'
47 end c201107291010x,
48 case when l = 41 then to_char(c201107290800,'999,999.9')
49 when (c201107290800-min)/((max-min)/40) >= l then ' *'
50 end c201107290800x
51 from data, lines
52 order by l desc
53 /
MIN MAX C201107291 C201107291 C201107291 C201107291 C201107290
---------- ---------- ---------- ---------- ---------- ---------- ----------
0 92 .1 56.0 61.0 1.0 92.0
0 92 *
0 92 *
0 92 *
0 92 *
0 92 *
0 92 *
0 92 *
0 92 *
0 92 *
0 92 *
0 92 *
0 92 *
0 92 *
0 92 *
0 92 * *
0 92 * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
41 rows selected.
Now, while I appreciate your sqlplus trick above - I found it too obscure and preferring more straightforward things - I'm going to use plsql to construct a query, you could use an anonymous block if you don't want a function:
ops$tkyte%ORA11GR2>
ops$tkyte%ORA11GR2>
ops$tkyte%ORA11GR2>
ops$tkyte%ORA11GR2> create or replace function show_hist( p_mindt in timestamp, p_maxdt in timestamp, p_lines in number default 40 )
2 return sys_refcursor
3 is
4 l_query long :=
5 'with data as (
6 select min(round(sum(h.space_used_delta/1024/1024),0)) min,
7 max(round(sum(h.space_used_delta/1024/1024),0)) max';
8
9 l_cursor sys_refcursor;
10 begin
11 for x in (select to_char(begin_interval_time,'yyyymmddhh24mi') bit
12 from dba_hist_snapshot
13 where begin_interval_time between p_mindt and p_maxdt)
14 loop
15 l_query := l_query || replace(
16 q'|,
17 max((case when to_char(s.begin_interval_time,'yyyymmddhh24mi') = '%s'
18 then round(sum(h.space_used_delta/1024/1024),0)
19 else .12345
20 end)) as c%s|'
21 , '%s', x.bit );
22 end loop;
23
24 l_query := l_query || q'|
25 from dba_hist_seg_stat h,
26 dba_hist_snapshot s
27 where h.snap_id = s.snap_id
28 and s.begin_interval_time between :p_mindt and :p_maxdt
29 group by s.begin_interval_time
30 ),
31 lines
32 as
33 (select level l
34 from dual
35 connect by level <= (:p_lines+1))
36 select min, max|';
37
38 for x in (select to_char(begin_interval_time,'yyyymmddhh24mi') bit
39 from dba_hist_snapshot
40 where begin_interval_time between p_mindt and p_maxdt)
41 loop
42 l_query := l_query ||
43 replace(
44 replace(
45 q'|,
46 case when l = (%d+1) then to_char(c%s,'999,999.9')
47 when (c%s-min)/((max-min)/%d) >= l then ' *'
48 end T%s|'
49 , '%s', x.bit )
50 , '%d', p_lines );
51 end loop;
52
53 l_query := l_query || ' from data, lines order by l desc';
54
55 open l_cursor for l_query using p_mindt, p_maxdt, p_lines;
56 return l_cursor;
57 end;
58 /
Function created.
ops$tkyte%ORA11GR2>
ops$tkyte%ORA11GR2> variable c refcursor
ops$tkyte%ORA11GR2> exec :c := show_hist( to_timestamp('29-jul-2011', 'dd-mon-yyyy'), to_timestamp('30-jul-2011','dd-mon-yyyy'), 20 )
PL/SQL procedure successfully completed.
ops$tkyte%ORA11GR2> print c
MIN MAX T201107291 T201107291 T201107291 T201107290 T201107291
---------- ---------- ---------- ---------- ---------- ---------- ----------
0 92 61.0 1.0 .1 92.0 56.0
0 92 *
0 92 *
0 92 *
0 92 *
0 92 *
0 92 *
0 92 *
0 92 * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
0 92 * * *
21 rows selected.