[20151214]显示统计分析的最大与最小值

[20151214]显示统计分析的最大与最小值.txt

--昨天看了一个链接:
http://www.pythian.com/blog/oracle-internal-datatype-storage/

col low_value format a20
col high_value format a20
col table_name format a10 head 'TABLE'
col data_type format a20
col column_name format a6 head 'COLUMN'
 
set linesize 200 trimspool on
set pagesize 60
 
select
   us.table_name,
   uc.data_type,
   us.column_name,
   case
      when uc.data_type in ('VARCHAR2','VARCHAR','CHAR')  then
         utl_raw.cast_to_varchar2(us.low_value)
      when uc.data_type = 'NUMBER' then
         to_char(utl_raw.cast_to_number(us.low_value) )
      when uc.data_type = 'DATE' then
         -- extract the century and year information from the
         -- internal date format
         -- century = (century byte -100) * 100
         to_char((
            to_number(
                  -- parse out integer appearing before first comma
                  substr( substr(dump(us.low_value),15), 1, instr(substr(dump(us.low_value),15),',')-1) - 100
            ) * 100
         )
         +
         -- year = year byte - 100
         (
            to_number(
                  substr(
                     substr(dump(us.low_value),15),
                     -- get position of 2nd comma
                     instr(substr(dump(us.low_value),15),',',2)+1,
                     -- get position of 2nd comma - position of 1st comma
                     instr(substr(dump(us.low_value),15),',',1,2) - instr(substr(dump(us.low_value),15),',',1,1) -1
                  )
            )
            - 100
         )) --current_year
                  || '-' ||
                  lpad(
                     substr(
                        substr(dump(us.low_value),15),
                        instr(substr(dump(us.low_value),15),',',1,2)+1,
                        instr(substr(dump(us.low_value),15),',',1,3) - instr(substr(dump(us.low_value),15),',',1,2) -1
                     ) -- month
                     ,2,'0'
                  )
                  ||  '-' ||
                  lpad(
                     substr(
                        substr(dump(us.low_value),15),
                        instr(substr(dump(us.low_value),15),',',1,3)+1,
                        instr(substr(dump(us.low_value),15),',',1,4) - instr(substr(dump(us.low_value),15),',',1,3) -1
                     ) -- day
                     ,2,'0'
                  )
                  || ' ' ||
                  lpad(
                     to_char(to_number(
                        substr(
                              substr(dump(us.low_value),15),
                              instr(substr(dump(us.low_value),15),',',1,4)+1,
                              instr(substr(dump(us.low_value),15),',',1,5) - instr(substr(dump(us.low_value),15),',',1,4) -1
                        )
                     )-1)
                     ,2,'0'
                  ) -- hour
                  || ':' ||
                  lpad(
                     to_char(
                        to_number(
                              substr(
                              substr(dump(us.low_value),15),
                              instr(substr(dump(us.low_value),15),',',1,5)+1,
                              instr(substr(dump(us.low_value),15),',',1,6) - instr(substr(dump(us.low_value),15),',',1,5) -1
                              )
                        )-1
                     )
                     ,2,'0'
                  ) -- minute
                  || ':' ||
                  lpad(
                     to_char(
                        to_number(
                              substr(
                              substr(dump(us.low_value),15),
                              instr(substr(dump(us.low_value),15),',',1,6)+1
                              )
                        )-1
                     )
                     ,2,'0'
                  ) --second
         else 'NOT SUPPORTED'
         end low_value,
         -- get the high value
   case
      when uc.data_type in ('VARCHAR2','VARCHAR','CHAR')  then
         utl_raw.cast_to_varchar2(us.high_value)
      when uc.data_type = 'NUMBER' then
         to_char(utl_raw.cast_to_number(us.high_value) )
      when uc.data_type = 'DATE' then
         -- extract the century and year information from the
         -- internal date format
         -- century = (century byte -100) * 100
         to_char((
            to_number(
                  -- parse out integer appearing before first comma
                  substr( substr(dump(us.high_value),15), 1, instr(substr(dump(us.high_value),15),',')-1) - 100
            ) * 100
         )
         +
         -- year = year byte - 100
         (
            to_number(
                  substr(
                     substr(dump(us.high_value),15),
                     -- get position of 2nd comma
                     instr(substr(dump(us.high_value),15),',',2)+1,
                     -- get position of 2nd comma - position of 1st comma
                     instr(substr(dump(us.high_value),15),',',1,2) - instr(substr(dump(us.high_value),15),',',1,1) -1
                  )
            )
            - 100
         )) --current_year
                  || '-' ||
                  lpad(
                     substr(
                        substr(dump(us.high_value),15),
                        instr(substr(dump(us.high_value),15),',',1,2)+1,
                        instr(substr(dump(us.high_value),15),',',1,3) - instr(substr(dump(us.high_value),15),',',1,2) -1
                     ) -- month
                     ,2,'0'
                  )
                  ||  '-' ||
                  lpad(
                     substr(
                        substr(dump(us.high_value),15),
                        instr(substr(dump(us.high_value),15),',',1,3)+1,
                        instr(substr(dump(us.high_value),15),',',1,4) - instr(substr(dump(us.high_value),15),',',1,3) -1
                     ) -- day
                     ,2,'0'
                  )
                  || ' ' ||
                  lpad(
                     to_char(to_number(
                        substr(
                              substr(dump(us.high_value),15),
                              instr(substr(dump(us.high_value),15),',',1,4)+1,
                              instr(substr(dump(us.high_value),15),',',1,5) - instr(substr(dump(us.high_value),15),',',1,4) -1
                        )
                     )-1)
                     ,2,'0'
                  ) -- hour
                  || ':' ||
                  lpad(
                     to_char(
                        to_number(
                              substr(
                              substr(dump(us.high_value),15),
                              instr(substr(dump(us.high_value),15),',',1,5)+1,
                              instr(substr(dump(us.high_value),15),',',1,6) - instr(substr(dump(us.high_value),15),',',1,5) -1
                              )
                        )-1
                     )
                     ,2,'0'
                  ) -- minute
                  || ':' ||
                  lpad(
                     to_char(
                        to_number(
                              substr(
                              substr(dump(us.high_value),15),
                              instr(substr(dump(us.high_value),15),',',1,6)+1
                              )
                        )-1
                     )
                     ,2,'0'
                  ) --second
         else 'NOT SUPPORTED'
         end high_value
from all_tab_col_statistics us
join all_tab_columns uc on uc.owner = us.owner
   and uc.table_name = us.table_name
   and uc.column_name = us.column_name
   and us.owner = USER
   and us.table_name = 'EMP'
order by uc.column_id;

--我记得以前有一个链接,定义函数display_raw可以显示最大最小值,链接:
http://structureddata.org/2007/10/16/how-to-display-high_valuelow_value-columns-from-user_tab_col_statistics/
https://github.com/gregrahn/oracle_scripts/blob/master/display_raw.sql

--
--  display_raw.sql
--
--  DESCRIPTION
--    helper function to print raw representation of column stats minimum or maximum
-- 
--  Created by Greg Rahn on 2011-08-19.
--

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);
    cbf    binary_float;
    cbd    binary_double;
begin
    if (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 = 'NUMBER') then
        dbms_stats.convert_raw_value(rawval, cn);
        return to_char(cn);
    elsif (type = 'BINARY_FLOAT') then
        dbms_stats.convert_raw_value(rawval, cbf);
        return to_char(cbf);
    elsif (type = 'BINARY_DOUBLE') then
        dbms_stats.convert_raw_value(rawval, cbd);
        return to_char(cbd);
    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(cr);
    elsif (type = 'CHAR') then
        dbms_stats.convert_raw_value(rawval, cc);
        return to_char(cc);
    else
        return 'UNKNOWN DATATYPE';
    end if;
end;
/

--但是那个方法的缺点是要安装这个函数,有1点点不方便,而且不能在上面的例子使用dbms_stats.convert_raw_value过程,因为返回值记录在第2个参数。
--我自己也有一个脚本,也是抄别人的,当然我也做了小量修改:脚本如下:(当然你的显示器显示要足够的宽,至少设置set linesize 250)

$ cat tab_lh.sql

PROMPT
PROMPT DISPLAY TABLE_NAME OF COLUMN_NAME INFORMATION.
PROMPT INPUT   OWNER TABLE_NAME COLUMN
PROMPT SAMPLE  : @ TAB_LH TABLE_NAME [COLUMN_NAME]
PROMPT IF NOT INPUT COLUMN_NAME ,USE "" .
PROMPT

column trans_low format a32
column trans_high format a32
column data_default format a20
column column_name format a24
SELECT
--owner,
--         table_name,
         column_name,
         data_type,
         data_length,
         nullable,
         num_distinct,
         density,
         sample_size,
         CASE
            WHEN data_type IN ('CHAR', 'VARCHAR2')
            THEN
               UTL_RAW.cast_to_varchar2 (low_value)
            WHEN data_type = 'NUMBER'
            THEN
               TO_CHAR (UTL_RAW.cast_to_number (low_value))
            WHEN data_type = 'DATE'
            THEN
               RTRIM (
                     LTRIM (
                        TO_CHAR (
                               100
                             * (  TO_NUMBER (SUBSTR (low_value, 1, 2), 'XX')
                                - 100)
                           + (TO_NUMBER (SUBSTR (low_value, 3, 2), 'XX') - 100),
                           '0000'))
                  || '-'
                  || LTRIM (
                        TO_CHAR (TO_NUMBER (SUBSTR (low_value, 5, 2), 'XX'),
                                 '00'))
                  || '-'
                  || LTRIM (
                        TO_CHAR (TO_NUMBER (SUBSTR (low_value, 7, 2), 'XX'),
                                 '00'))
                  || ' '
                  || LTRIM (
                        TO_CHAR (
                           TO_NUMBER (SUBSTR (low_value, 9, 2), 'XX') - 1,
                           '00'))
                  || ':'
                  || LTRIM (
                        TO_CHAR (
                           TO_NUMBER (SUBSTR (low_value, 11, 2), 'XX') - 1,
                           '00'))
                  || ':'
                  || LTRIM (
                        TO_CHAR (
                           TO_NUMBER (SUBSTR (low_value, 13, 2), 'XX') - 1,
                           '00')))
         END
            trans_low,
         CASE
            WHEN data_type IN ('CHAR', 'VARCHAR2')
            THEN
               UTL_RAW.cast_to_varchar2 (high_value)
            WHEN data_type = 'NUMBER'
            THEN
               TO_CHAR (UTL_RAW.cast_to_number (high_value))
            WHEN data_type = 'DATE'
            THEN
               RTRIM (
                     LTRIM (
                        TO_CHAR (
                               100
                             * (  TO_NUMBER (SUBSTR (high_value, 1, 2), 'XX')
                                - 100)
                           + (TO_NUMBER (SUBSTR (high_value, 3, 2), 'XX') - 100),
                           '0000'))
                  || '-'
                  || LTRIM (
                        TO_CHAR (TO_NUMBER (SUBSTR (high_value, 5, 2), 'XX'),
                                 '00'))
                  || '-'
                  || LTRIM (
                        TO_CHAR (TO_NUMBER (SUBSTR (high_value, 7, 2), 'XX'),
                                 '00'))
                  || ' '
                  || LTRIM (
                        TO_CHAR (
                           TO_NUMBER (SUBSTR (high_value, 9, 2), 'XX') - 1,
                           '00'))
                  || ':'
                  || LTRIM (
                        TO_CHAR (
                           TO_NUMBER (SUBSTR (high_value, 11, 2), 'XX') - 1,
                           '00'))
                  || ':'
                  || LTRIM (
                        TO_CHAR (
                           TO_NUMBER (SUBSTR (high_value, 13, 2), 'XX') - 1,
                           '00')))
         END
            trans_high,
         num_nulls,
         num_buckets,
         last_analyzed,
         histogram,
        data_default
    FROM dba_tab_cols
   WHERE  owner = decode('&1','',user,upper('&1'))
AND table_name = upper('&2')
AND column_name = decode('&&3','',column_name,upper('&&3'))
ORDER BY column_id
/

时间: 2024-10-14 12:30:10

[20151214]显示统计分析的最大与最小值的相关文章

[20120215]显示统计信息的最大最小值.txt

昨晚,看了一些统计信息的内容,由于里面的信息是RAW datatypes.看了别人写的代码,转换对应的数值: http://structureddata.org/2007/10/16/how-to-display-high_valuelow_value-columns-from-user_tab_col_statistics/ create or replace function display_raw (rawval raw, type varchar2)return varchar2is  

ASP.NET分页组件学与用——教学篇

asp.net|分页 ASP.NET分页组件学与用--教学篇 没有人会怀疑分页组件在WEB应用程序中的作用.数据库中的记录数成千上万甚至过亿,如果一股脑儿显示在一页显然毫不现实,这样的程序员也太小儿科了.所以,最好的办法就是分页显示,每页只显示数据库中的一部分记录,可以翻页,也可以输入一个页码翻到指定的页面,这种方式也是当前比较常见的用法. 本文的不同之处在于,我把分页的功能封装在组件中,一方面体现了面向对象的特点,另一方面也方便发布.共享和使用.事先声明,本文不再讲述组件创建的详细过程,如果有

怎么提高WPS文字排版速度

  怎么提高WPS文字排版速度 1.熟练使用几种常用快捷键 初级: Ctrl+N 新建文件 Ctrl+O 打开文件 Ctrl+W 关闭文件 [F12]键: 另存文件 Ctrl+B 字体加粗 Ctrl+U 加下划线 Ctrl+I 字体倾斜 中级: [ctrl+Enter]: 插入分页符 [ctrl+ shift+C]: 复制格式 [ctrl+ shift+V]: 粘贴格式 Ctrl+D 调出"字体"窗口 [ctrl+L]: 左对齐 [ctri+R]: 右对齐 [ctri+C]: 居中 A

关于ORACLE位图索引内部浅论

我们都知道ORACLE位图索引适用于字段不同值很少的情况,同时修改DML会导致整个同样的值 全部被锁定,这严重影响了并发性,所以不建议OLTP系统大量使用位图索引. 但是具体位图索引的内部是如何排列和组织的呢?如下将进行探讨,由于水平有限可能有一定错误. 首先认识BITMAP索引的组织方式,首先看一下ORACLE给出的这张图 可以看到本图中实际上有4种颜色蓝色.绿色.红色.黄色,BITMAP 索引也是B-TREE的格式,但是其页节点存储 的是键值+ROWID范围+位图键的方式,这样一来可以很明显

《SPSS 统计分析从入门到精通(第2版)》一6.2 卡方检验

6.2 卡方检验 SPSS 统计分析从入门到精通(第2版)在某些统计方法中,往往事先假定总体服从正态分布,然后对其均值或方差做检验,但某个随机变量是否服从某种特定的分布是需要进行检验的.卡方检验(Chi-square test)就是一种用来检验给定 的样本数据是否来自特定分布的方法. 检验的过程,通常是先根据以往的经验或实际观测数据的分布情况,推测总体服从某种分布,分布函数为F(x),然后利用样本数据检验该总体的分布函数是否就是F(x). 6.2.1 原理与方法 卡方检验的零假设H0为:样本所属

显示眼图

使用WX scope可以观察眼图,具体步骤如下: 1.点击autorange,采用手动调整: 2.调整secs/div和counts/div到合适的位置: 3.将T offset调整到最小值: 4.点击persistence: 5.调整analogy alpha到最小值: 即可显示眼图. 下面是BPSK调制,发送端宏成型滤波器输出端观察到的眼图: 在接收端定时恢复之前的眼图如下: 接收端经过定时恢复后的眼图: 由于在信道中并没有引入时钟偏移,所以定时恢复之前也能观察到比较好的眼图 另外,如果安装

Python中用于求最小值的min()方法

 这篇文章主要介绍了简单介绍Python中用于求最小值的min()方法,是Python入门中的基础知识,需要的朋友可以参考下     min()方法返回它的参数最小值:最接近负无穷大的值. 语法 以下是min()方法的语法: ? 1 min( x, y, z, .... ) 参数 x -- 这是一个数值表达式. y -- 这也是一个数值表达式. z -- 这也是一个数值表达式. 返回值 此方法返回最小的它的参数. 例子 下面的例子显示了min()方法的使用. ? 1 2 3 4 5 6 #!/u

xcel2013怎样隐藏与显示状态栏

  excel 2013隐藏与显示状态栏的教程: 隐藏与显示状态栏步骤1:打开EXCEL2010工作表,工作表标签名"电脑统计表",可以看到,底部状态栏没有显示出来! 隐藏与显示状态栏步骤2:右键"电脑统计表"标签,弹出快捷菜单,点击"查看代码"命令项 隐藏与显示状态栏步骤3:进入VBA模式,并按组合键,显示出"立即窗口" 隐藏与显示状态栏步骤4:在"立即窗口"中输入: Application.Displa

可用来显示空值的时间选择控件3

控件|显示 public DateInput() { // 该调用是 Windows.Forms 窗体设计器所必需的. InitializeComponent(); tbMonth.ContextMenu = mnu ; tbYear.ContextMenu = mnu ; tbDay.ContextMenu = mnu ; this.Height = 21 ; this.Value = DateTime.Now ; this.DateFormat = "yyyy-MM-dd" ; i