[20131128]12c的dbms_utility.expand_sql_text.txt

简介: [20131128]12c的dbms_utility.expand_sql_text.txtSCOTT@ztest> @verBANNER                                                              ...
[20131128]12c的dbms_utility.expand_sql_text.txt

SCOTT@ztest> @ver
BANNER                                                                              CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production              0

12C的dbms_utility提供了新函数expand_sql_text可以看sql容易。

例子:
SCOTT@ztest> @ver
BANNER                                                                              CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production              0

variable x clob;

begin
  dbms_utility.expand_sql_text ( input_sql_text => 'select * from dba_tablespaces', output_sql_text => :x );
end;
/

SCOTT@ztest> column x format a200
SCOTT@ztest> print :x;
X
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SELECT "A1"."TABLESPACE_NAME" "TABLESPACE_NAME","A1"."BLOCK_SIZE" "BLOCK_SIZE","A1"."INITIAL_EXTENT" "INITIAL_EXTENT","A1"."NEXT_EXTENT" "NEXT_EXTENT","A1"."MIN_EXTENTS" "MIN_EXTENTS","A1"."MAX_EXTE
NTS" "MAX_EXTENTS","A1"."MAX_SIZE" "MAX_SIZE","A1"."PCT_INCREASE" "PCT_INCREASE","A1"."MIN_EXTLEN" "MIN_EXTLEN","A1"."STATUS" "STATUS","A1"."CONTENTS" "CONTENTS","A1"."LOGGING" "LOGGING","A1"."FORCE
_LOGGING" "FORCE_LOGGING","A1"."EXTENT_MANAGEMENT" "EXTENT_MANAGEMENT","A1"."ALLOCATION_TYPE" "ALLOCATION_TYPE","A1"."PLUGGED_IN" "PLUGGED_IN","A1"."SEGMENT_SPACE_MANAGEMENT" "SEGMENT_SPACE_MANAGEME
NT","A1"."DEF_TAB_COMPRESSION" "DEF_TAB_COMPRESSION","A1"."RETENTION" "RETENTION","A1"."BIGFILE" "BIGFILE","A1"."PREDICATE_EVALUATION" "PREDICATE_EVALUATION","A1"."ENCRYPTED" "ENCRYPTED","A1"."COMPR
ESS_FOR" "COMPRESS_FOR" FROM  (SELECT "A3"."NAME" "TABLESPACE_NAME","A3"."BLOCKSIZE" "BLOCK_SIZE","A3"."BLOCKSIZE"*"A3"."DFLINIT" "INITIAL_EXTENT",DECODE(BITAND("A3"."FLAGS",3),1,TO_NUMBER(NULL),"A3
"."BLOCKSIZE"*"A3"."DFLINCR") "NEXT_EXTENT","A3"."DFLMINEXT" "MIN_EXTENTS",DECODE("A3"."CONTENTS$",1,TO_NUMBER(NULL),"A3"."DFLMAXEXT") "MAX_EXTENTS",DECODE(BITAND("A3"."FLAGS",4096),4096,"A3"."AFFST
RENGTH",NULL) "MAX_SIZE",DECODE(BITAND("A3"."FLAGS",3),1,TO_NUMBER(NULL),"A3"."DFLEXTPCT") "PCT_INCREASE","A3"."BLOCKSIZE"*"A3"."DFLMINLEN" "MIN_EXTLEN",DECODE("A3"."ONLINE$",1,'ONLINE',2,'OFFLINE',
4,'READ ONLY','UNDEFINED') "STATUS",DECODE("A3"."CONTENTS$",0,DECODE(BITAND("A3"."FLAGS",16),16,'UNDO','PERMANENT'),1,'TEMPORARY') "CONTENTS",DECODE(BITAND("A3"."DFLOGGING",1),0,'NOLOGGING',1,'LOGGI
NG') "LOGGING",DECODE(BITAND("A3"."DFLOGGING",2),0,'NO',2,'YES') "FORCE_LOGGING",DECODE("A3"."BITMAPPED",0,'DICTIONARY','LOCAL') "EXTENT_MANAGEMENT",DECODE(BITAND("A3"."FLAGS",3),0,'USER',1,'SYSTEM'
,2,'UNIFORM','UNDEFINED') "ALLOCATION_TYPE",DECODE("A3"."PLUGGED",0,'NO','YES') "PLUGGED_IN",DECODE(BITAND("A3"."FLAGS",32),32,'AUTO','MANUAL') "SEGMENT_SPACE_MANAGEMENT",DECODE(BITAND("A3"."FLAGS",
64),64,'ENABLED','DISABLED') "DEF_TAB_COMPRESSION",DECODE(BITAND("A3"."FLAGS",16),16,DECODE(BITAND("A3"."FLAGS",512),512,'GUARANTEE','NOGUARANTEE'),'NOT APPLY') "RETENTION",DECODE(BITAND("A3"."FLAGS
",256),256,'YES','NO') "BIGFILE",DECODE("A2"."STORATTR",1,'STORAGE','HOST') "PREDICATE_EVALUATION",DECODE(BITAND("A3"."FLAGS",16384),16384,'YES','NO') "ENCRYPTED",DECODE(BITAND("A3"."FLAGS",64),0,NU
LL,CASE  WHEN BITAND("A3"."FLAGS",65536)=65536 THEN 'OLTP' WHEN BITAND("A3"."FLAGS",131072+262144)=131072 THEN 'QUERY LOW'||DECODE(BITAND("A3"."FLAGS",4194304),4194304,' ROW LEVEL LOCKING','') WHEN
BITAND("A3"."FLAGS",131072+262144)=262144 THEN 'QUERY HIGH'||DECODE(BITAND("A3"."FLAGS",4194304),4194304,' ROW LEVEL LOCKING','') WHEN BITAND("A3"."FLAGS",131072+262144)=131072+262144 THEN 'ARCHIVE
LOW'||DECODE(BITAND("A3"."FLAGS",4194304),4194304,' ROW LEVEL LOCKING','') WHEN BITAND("A3"."FLAGS",524288)=524288 THEN 'ARCHIVE HIGH'||DECODE(BITAND("A3"."FLAGS",4194304),4194304,' ROW LEVEL LOCKIN
G','') ELSE 'BASIC' END ) "COMPRESS_FOR" FROM "SYS"."TS$" "A3","SYS"."X$KCFISTSA" "A2" WHERE "A3"."ONLINE$"3 AND BITAND("A3"."FLAGS",2048)2048 AND "A3"."TS#"="A2"."TSID") "A1"

SCOTT@ztest> select text from dba_views where view_name='DBA_TABLESPACES';
TEXT
------------------------------------------------------------------------------
select ts.name, ts.blocksize, ts.blocksize * ts.dflinit,
          decode(bitand(ts.flags, 3), 1, to_number(NULL),
                 ts.blocksize * ts.dflincr),
          ts.dflminext,
          decode(ts.contents$, 1, to_number(NULL), ts.dflmaxext),
          decode(bitand(ts.flags, 4096), 4096, ts.affstrength, NULL),
          decode(bitand(ts.flags, 3), 1, to_number(NULL), ts.dflextpct),
          ts.blocksize * ts.dflminlen,
          decode(ts.online$, 1, 'ONLINE', 2, 'OFFLINE',
                 4, 'READ ONLY', 'UNDEFINED'),
          decode(ts.contents$, 0, (decode(bitand(ts.flags, 16), 16, 'UNDO',
                 'PERMANENT')), 1, 'TEMPORARY'),
          decode(bitand(ts.dflogging, 1), 0, 'NOLOGGING', 1, 'LOGGING'),
          decode(bitand(ts.dflogging, 2), 0, 'NO', 2, 'YES'),
          decode(ts.bitmapped, 0, 'DICTIONARY', 'LOCAL'),
          decode(bitand(ts.flags, 3), 0, 'USER', 1, 'SYSTEM', 2, 'UNIFORM',
                 'UNDEFINED'),
          decode(ts.plugged, 0, 'NO', 'YES'),
          decode(bitand(ts.flags,32), 32,'AUTO', 'MANUAL'),
          decode(bitand(ts.flags,64), 64,'ENABLED', 'DISABLED'),
          decode(bitand(ts.flags,16), 16, (decode(bitand(ts.flags, 512), 512,
                 'GUARANTEE', 'NOGUARANTEE')), 'NOT APPLY'),
          decode(bitand(ts.flags,256), 256, 'YES', 'NO'),
          decode(tsattr.storattr, 1, 'STORAGE', 'HOST'),
          decode(bitand(ts.flags,16384), 16384, 'YES', 'NO'),
          decode(bitand(ts.flags,64), 0, null,
            (case when bitand(ts.flags,  65536) = 65536
                    then 'OLTP'
                  when bitand(ts.flags, (131072+262144)) = 131072
                    then concat('QUERY LOW',
                                decode(bitand(ts.flags, 4194304), 4194304,
                                       ' ROW LEVEL LOCKING', ''))
                  when bitand(ts.flags, (131072+262144)) = 262144
                    then concat('QUERY HIGH',
                                decode(bitand(ts.flags, 4194304), 4194304,
                                       ' ROW LEVEL LOCKING', ''))
                  when bitand(ts.flags, (131072+262144)) = (131072+262144)
                    then concat('ARCHIVE LOW',
                                decode(bitand(ts.flags, 4194304), 4194304,
                                       ' ROW LEVEL LOCKING', ''))
                  when bitand(ts.flags, 524288) = 524288
                    then concat('ARCHIVE HIGH',
                                decode(bitand(ts.flags, 4194304), 4194304,
                                       ' ROW LEVEL LOCKING', ''))
                  else 'BASIC' end))
from sys.ts$ ts, sys.x$kcfistsa tsattr
where ts.online$ != 3
and bitand(flags,2048) != 2048
and ts.ts# = tsattr.tsid

目录
相关文章
|
测试技术 关系型数据库 Oracle
[20171106]DBMS_UTILITY.GET_TIME().txt
[20171106]DBMS_UTILITY.GET_TIME().txt --//有时候测试某个脚本运行时间,经常在这之前之后调用这个函数.今天奇怪的发现显示竟然是负数,感觉很奇怪做一个探究.
1032 0
|
SQL
[20170726]11G 12c expand sql text 2.txt
[20170726]11G 12c expand sql text 2.txt --//原来写的脚本只能分别在11g,12c单独使用.上午花一点点时间.把两者整合起来.
1065 0
|
SQL Oracle 关系型数据库
[20170724]关于sql_id那些事.txt
[20170724]关于sql_id那些事.txt --//昨天别人问的问题,我以前也写过许多blog,做一些总结: http://blog.itpub.net/267265/viewspace-1357292/ http://blog.
1117 0
|
SQL
[20170620]11G 12c expand sql text.txt
[20170620]11G 12c expand sql text.txt --//原来写的脚本只能分别在11g,12c单独使用.上午花一点点时间.把两者整合起来. --//讨论链接:http://www.
1045 0
|
SQL 测试技术 Perl
[20170619]11G expand sql text.txt
[20170619]11G expand sql text.txt --//12G下存在dbms_utility包.expand_sql_text扩展sql语句,查询到转换后执行的sql语句.
1042 0
|
SQL 关系型数据库
[20150616]关于sql_id.txt
[20150616]关于sql_id.txt --我曾经提到PLSQL中使用绑定变量,oracle会格式化处理,转化为特定的格式。可以参考我以前的例子: --[20121102]PLSQL中的绑定变量.txt --http://blog.itpub.net/267265/viewspace-748190/ --我也曾经写过一篇exact_matching_signature,force_matching。
837 0
|
算法 移动开发 SQL
[20141212]关于sql_id.txt
[20141212]关于sql_id.txt http://blog.itpub.net/267265/viewspace-1357292/ http://blog.itpub.net/267265/viewspace-1220996/ --昨天别人问一些sql_id计算的问题,实际上我也不懂具体的算法,我给他看了上面的链接。
871 0
[20141205]关于sql_id.txt
[20141205]关于sql_id.txt --昨天跟别人聊天,讲sql_id字串里面没有字符'o'.实际上他在学习sql_id与hash_value转换时copy 和 paste少粘贴1位,手工输入时以 --为是--字母'o',实际上是数字'0'.
719 0