oracle 常用语句

前端之家收集整理的这篇文章主要介绍了oracle 常用语句前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

编程之家小编现在分享给大家,也给大家做个参考。

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

以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

猜你在找的MySQL相关文章