oracle 常用语句

转自:http://www.oschina.net/code/snippet_121156_8968


  1. --查询表的大小  
  2. select t.owner,  
  3.        t.segment_name,  
  4.        (sum(t.blocks) * 8) / 1024 || 'M' as S,  
  5.        t.segment_type  
  6.   from dba_segments t  
  7.  where t.owner = 'USER_NAME'  
  8.  group by t.owner, t.segment_name, t.segment_type  
  9.  order by t.owner, S desc  
  10.    
  11. --修改表所在表空间  
  12.    
  13. select T.owner,  t.segment_name, t.tablespace_name --, sum(t.blocks)  
  14.   from dba_segments t  
  15.  where t.owner = 'USER_NAME'  
  16. ORDER BY T.owner  
  17.    
  18. select 'alter table ' || t.TABLE_NAME || ' move tablespace BIP_TS;' from user_all_tables t  
  19. select 'alter index '|| index_name ||' rebuild tablespace BIP_TS;' from user_indexes;  
  20.    
  21. --查看索引是否生效  
  22.    
  23.   select index_name, index_type, tablespace_name, table_type, status  
  24.   from user_indexes t  
  25.  where t.tablespace_name = 'TABLESPACENAME'  
  26.    and status = 'UNUSABLE'  
  27.    
  28. -- 清空回收站  
  29.    
  30. purge recyclebin;  
  31.    
  32. --查询建表语句  
  33.    
  34. select dbms_metadata.get_ddl('TABLE','UNIEAP_REPORT_CATEGORY'FROM DUAL  
  35.    
  36. select DBMS_METADATA.GET_DDL('TABLESPACE','BIP_TS'FROM DUAL  
  37.    
  38. --获取授权信息  
  39.    
  40. select dbms_metadata.get_granted_ddl('SYSTEM_GRANT'from dual;  
  41.    
  42. --查询表空间使用率的语句  
  43. select a.a1 表空间名称,  
  44.        c.c2 类型,  
  45.        c.c3 区管理,  
  46.        b.b2 / 1024 / 1024 表空间大小M,  
  47.        (b.b2 - a.a2) / 1024 / 1024 已使用M,  
  48.        substr((b.b2 - a.a2) / b.b2 * 100, 1, 5) 利用率  
  49.   from (select tablespace_name a1, sum(nvl(bytes, 0)) a2  
  50.           from dba_free_space  
  51.          group by tablespace_name) a,  
  52.        (select tablespace_name b1, sum(bytes) b2  
  53.           from dba_data_files  
  54.          group by tablespace_name) b,  
  55.        (select tablespace_name c1, contents c2, extent_management c3  
  56.           from dba_tablespaces) c  
  57.  where a.a1 = b.b1  
  58.    and c.c1 = b.b1;  
  59.    
  60. --修改分区名  
  61.    
  62. alter table TABLE_NAME rename partition OLD_PARTITION_NAME to NEW_PARTITION_NAME;  
  63.    
  64. --查询分区脚本  
  65. select TABLE_NAME ,PARTITION_NAME from user_tab_partitions where table_name like '%'  
  66. select TABLE_NAME ,PARTITION_NAME from user_tab_partitions where table_name like '%'  
  67. --查询索引脚本  
  68. SELECT INDEX_NAME,TABLE_NAME FROM USER_INDEXES WHERE INDEX_NAME LIKE '%'  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值