在日常系统维护过程中,我们往往会经常要用到一些ORACLE常用参数,亦或是一些我们业务中的特殊场景,所以我们要养成复用的思想,我们在面向对象的世界,遨游在复用的大海中,其实思想是一样的,数据库中我们一样可以复用,所以我们进行就形成自己的知识库,记录我们常用的知识库。
1、查看表空间的名称及大小
sql > SELECT t.tablespace_name,round(SUM(bytes / (1024 * 1024)),0) ts_size FROM dba_tablespaces t,dba_data_files d WHERE t.tablespace_name = d.tablespace_name GROUP BY t.tablespace_name;
2、查看表空间物理文件的名称及大小
sql > SELECT tablespace_name,file_id,file_name,round(bytes / (1024 * 1024),0) total_space FROM dba_data_files ORDER BY tablespace_name;
3、查看回滚段名称及大小
sql > SELECT segment_name,tablespace_name,r.status,(initial_extent / 1024) initialextent,(next_extent / 1024) nextextent,max_extents,v.curext curextent FROM dba_rollback_segs r,v$rollstat v WHERE r.segment_id = v.usn(+) ORDER BY segment_name;
4、查看控制文件
sql > SELECT NAME FROM v$controlfile;
5、查看日志文件
SELECT MEMBER FROM v$logfile;
6、查看表空间的使用情况
sql > SELECT SUM(bytes) / (1024 * 1024) AS free_space,tablespace_name FROM dba_free_space GROUP BY tablespace_name;
sql > SELECT a.tablespace_name,a.bytes total,b.bytes used,c.bytes free,(b.bytes * 100) / a.bytes "% USED ",(c.bytes * 100) / a.bytes "% FREE " FROM sys.sm$ts_avail a,sys.sm$ts_used b,sys.sm$ts_free c WHERE a.tablespace_name = b.tablespace_name AND a.tablespace_name = c.tablespace_name;
7、查看数据库库对象
sql > SELECT owner,object_type,status,COUNT(*) count# FROM all_objects GROUP BY owner,status;
8、查看数据库的版本
sql > SELECT version FROM product_component_version WHERE substr(product,1,6) = 'Oracle';
9、查看数据库的创建日期和归档方式
sql > SELECT created,log_mode,log_mode FROM v$database;
10、结束进程
select sess.sid,
sess.serial#,
lo.oracle_username,
lo.os_user_name,
ao.object_name,
lo.locked_mode
from v$locked_object lo,
dba_objects ao,
v$session sess
where ao.object_id = lo.object_id and lo.session_id = sess.sid;
select saddr,sid,serial#,paddr,username,status from v$session where username =upper('sys');
alter system kill session '46,53';
select * from v$session t1,v$locked_object t2 where t1.sid = t2.SESSION_ID;
12、特殊字符处理(数值字段存在非数字)
select * from table_name p where p.line_num not in (select t.line_num from table_name t where REGEXP_LIKE(t.sale_num,'(^[+-]?\d{0,}\.?\d{0,}$)'))