Thursday, June 05, 2008

How to Display HIGH_VALUE/LOW_VALUE Columns from USER_TAB_COL_STATISTICS

1. create a function as follows (copied from a website)


create or replace function display_raw (rawval raw, type varchar2)
return varchar2
is
cn number;
cv varchar2(32);
cd date;
cnv nvarchar2(32);
cr rowid;
cc char(32);
begin
if (type = 'NUMBER') then
dbms_stats.convert_raw_value(rawval, cn);
return to_char(cn);
elsif (type = 'VARCHAR2') then
dbms_stats.convert_raw_value(rawval, cv);
return to_char(cv);
elsif (type = 'DATE') then
dbms_stats.convert_raw_value(rawval, cd);
return to_char(cd);
elsif (type = 'NVARCHAR2') then
dbms_stats.convert_raw_value(rawval, cnv);
return to_char(cnv);
elsif (type = 'ROWID') then
dbms_stats.convert_raw_value(rawval, cr);
return to_char(cnv);
elsif (type = 'CHAR') then
dbms_stats.convert_raw_value(rawval, cc);
return to_char(cc);
else
return 'UNKNOWN DATATYPE';
end if;
end;
/









2. Issue the following statement with table name and column name


col column_name format a20
col low_val format a20
col high_val format a20

select
a.column_name,
display_raw(a.low_value,b.data_type) as low_val,
display_raw(a.high_value,b.data_type) as high_val,
a.num_distinct
from
dba_tab_col_statistics a, dba_tab_cols b
where
a.table_name='TABLE_NAME'
and a.table_name=b.table_name
and a.column_name=b.column_name
and a.owner='MYOWNER'
and b.owner='MYOWNER'
-- and a.column_name ='COL_NAME'
/








3. The output looks like:


COLUMN_NAME LOW_VAL HIGH_VAL NUM_DISTINCT
-------------------- -------------------- -------------------- ------------
SSP_VERSION_CHANGE_F Y Y 1
LAG

ONTTYPE E VDSL-1 5
ILEC_MON 0259843 UAIILGT075933613; 461775
ILEC_PON DICN059366494 UAIMICN087898169 503658
IS_IVAAP_PROV_COMPLE N Y 2
TE

EQPT_RETR_METHOD DROPOFF PICKUP 3
EQPT_RETR_DATE 2006-10-24 00:00:00 2008-09-07 00:00:00 597
SERVICE_PROPERTIES 0 32 11
RELATED_VZUSER_ID 01love zzzmyers 1693499
APPROVER_ID BAAIS15049 X2008591792643550 12475
GEOTAXCODE 0 null 6355
COUNTY ACCOMACK polk 1555
WINBACK_IND N Y 2
LIST_OF_FIOS_TNS 3016170150 985601305141046165 207
83

IS_NOS_ROUTE N Y 2
RESERVATION_ID 25050 baais28446 2327
IS_PREFAC N Y 2
VACATION_START_DATE 2005-05-01 00:00:00 2008-06-22 00:00:00 1038
VACATION_END_DATE 2005-06-01 00:00:00 2009-03-02 00:00:00 1267
UNEP_INDICATOR N Y 2
VLEC_ID 0127 ZTK 194
SUPP_ACTION_IND SUPP-CHANGE SUPP-UNCHANGED 3
IS_VZ1_MODEM N Y 2
DISP_CODE 0
DRY_LOOP_IND N Y 2

(......)

No comments: