• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

oracle 使用杂记1

发布: 2007-7-02 11:08 | 作者: admin | 来源: | 查看: 8次 | 进入软件测试论坛讨论

领测软件测试网
一直学习oracle 希望能和大家共同探讨问题 如有不对之处还请指出

index 种对null的使用
================================================================

有些情况可以用 " N/A " 代替 NULL

================================================================

8i 以上使用基于函数的index 可以用上 null

create table t (n number);
create index ind_n on t(n,1);   //  用 t(n,@#a@#) 更省空间

select v from t where n is null;

V
--------------------
lg

Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=3 Card=614 Bytes=6140)
   1    0   TABLE ACCESS (BY INDEX ROWID) OF @#T@# (Cost=3 Card=614 Bytes=6140)
   2    1     INDEX (RANGE SCAN) OF @#IND_N@# (NON-UNIQUE) (Cost=3 Card=614)

要记住用 CBO
I doesn@#t need query rewrite to make that leap, it is a "safe" operation.

==============================================================

null 可以在 bitmap index 中使用

==============================================================

或者象下面这样使用多列组合的index 方便使用index

create table t ( f_seq int, t_seq int, x char(1) );
create index t_idx on t(f_seq,t_seq);

select f_seq, t_seq from t where f_seq > 0 and t_seq is null;

Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=CHOOSE
   1    0   INDEX (RANGE SCAN) OF @#T_IDX@# (NON-UNIQUE)

select f_seq, t_seq, x from t  where f_seq > 0 and t_seq is null;

Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=CHOOSE
   1    0   TABLE ACCESS (BY INDEX ROWID) OF @#T@#
   2    1     INDEX (RANGE SCAN) OF @#T_IDX@# (NON-UNIQUE)

===============================================================

 

 

                                           表所占空间的大小   

select segment_name, round(blocks*8/1024, 0) table_size from user_segments where segment_type=@#TABLE@#;
---- 你可以知道你的表的实际size (单位: M)

-----------------------------------------------------------------------------------------

数据字典表DBA_TABLES、ALL_TABLES、USER_TABLES

select table_name,initial_extent,next_extent,min_extents,max_extents,pct_increase
from user_tables;

-----------------------------------------------------------------------------------------

分析一对象实际使用的块
     analyze table lg.t compute statistics;

分析完后就可以看一对象实际使用的块
    select blocks,num_rows,empty_blocks,avg_space,avg_row_len
                   from dba_tables where owner=@#LG@# and table_name=@#T@#;
select table_name, round(avg_row_len*num_rows/1024/1024, 0) data_size from user_tables;
---- 你可以知道表中大约的data size (单位: M)
-----------------------------------------------------------------------------------------

select count(distinct substr(rowid,1,15)) "how many use of block" from a;

这是看一个表真正使用了多少数据块 dba_tables 的 blocks 显示了 HWM 下不包含行的块的数目


-----------------------------------------------------------------------------------------

declare
   l_total_blocks        number;
   l_total_bytes         number;
   l_unused_blocks       number;
   l_unused_bytes        number;
   l_LastUsedExtFileId         number;
   l_LastUsedExtBlockId        number;
   l_last_used_block           number;
   l varchar2(128);
   t varchar2(128);
begin
   l:=upper(@#&name@#);
   select object_type into t from user_objects where object_name=l;
   dbms_space.unused_space(
      segment_owner     =>USER,
   segment_name      =>l,
   segment_type      =>t,
   partition_name    => null,
            total_blocks      => l_total_blocks,
            total_bytes       => l_total_bytes,
            unused_blocks     => l_unused_blocks,
            unused_bytes      => l_unused_bytes,
         last_used_extent_file_id => l_LastUsedExtFileId,
            last_used_extent_block_id => l_LastUsedExtBlockId,
            last_used_block => l_last_used_block  );
    dbms_output.put_line(RPAD((@#total_blocks: @#||l_total_blocks),40,@# @#)||@#total_bytes: @#||l_total_bytes);
    dbms_output.put_line(RPAD((@#unused_blocks: @#||l_unused_blocks),40,@# @#)||@#unused_bytes: @#||l_unused_bytes);
    dbms_output.put_line(RPAD((@#last_used_extent_file_id: @#||l_LastUsedExtFileId),40,@# @#)|| @#last_used_extent_block_id: @#||l_LastUsedExtBlockId);
    dbms_output.put_line(@#last_used_block: @#||l_last_used_block);
end;
/

 

                                           sequence

<<  Oracle9i Database Administrator@#s Guide  >>  20

if your application can never lose sequence numbers, then you cannot use Oracle sequences
and you may choose to store sequence numbers in database tables.

CREATE SEQUENCE  // 需要的系统权限

create sequence lg_sequence
      start with 1
      increment by 1
      order        //保证每个序列值都比先前的大, ********在并行服务中有用
      nocycle;     //防止循环又回到初始值
      NOCACHE NOORDER;
     
默认cache 为 20 直接 shutdown abort 后在内存中缓存的序列就会消失
        startup后从上次shutdown以前的 sys.seq$ 的HIGHWATER 的值开始

      最大值1.0E+27  1后面27个零
      lg_sequence.nextval
      lg_sequence.currval
     
     
alter sequence lg_sequence         //  alter sequence squ_1 increment by trunc(9999999/2);
     increment by 997;    //如果序列之前是2,这样一改就是999
          //是逐渐在原有的基础上涨的

oracle   不支持复制 sequence

-------------------------------    exp sequence    --------------------------------------

sequences are objects -- just like a table, procedure, view, package, etc.
       要exp sequence 那就 export a database or schema, that will get the sequences.

或者    select @#create sequence @# || sequence_name || @# start with @# || last_number+1 ||
        @#;@# from user_sequences where.....;


 

由于是杂记 想到什么就写的什么 可能有点乱 请大家多包涵

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网