Oracle常用SQL汇总(持续更新)
查看表空间相关信息
为企业提供成都网站设计、网站制作、网站优化、全网营销推广、竞价托管、品牌运营等营销获客服务。创新互联公司拥有网络营销运营团队,以丰富的互联网营销经验助力企业精准获客,真正落地解决中小企业营销获客难题,做到“让获客更简单”。自创立至今,成功用技术实力解决了企业“网站建设、网络品牌塑造、网络营销”三大难题,同时降低了营销成本,提高了有效客户转化率,获得了众多企业客户的高度认可!
SELECT TABLESPACE_NAME, BLOCK_SIZE, --db_block_size大小 INITIAL_EXTENT FROM DBA_TABLESPACES
2. 表空间对应文件名称及大小
SELECT TABLESPACE_NAME, FILE_ID, FILE_NAME, ROUND(BYTES / (1024 * 1024), 0) TOTAL_SPACE FROM DBA_DATA_FILES ORDER BY TABLESPACE_NAME;
3. 查看表空间大小,使用情况
SELECT UPPER(F.TABLESPACE_NAME) AS TABLESPACE_NAME, --表空间名称 D.TOTAL_BYTES AS TOTAL_BYTES, --表空间大小M F.FREE_BYTES AS FREE_BYTES, --空闲大小M D.TOTAL_BYTES - F.FREE_BYTES AS USEAGE_BYTES, --使用大小M TO_CHAR(ROUND((D.TOTAL_BYTES - F.FREE_BYTES) / D.TOTAL_BYTES * 100, 2), '990.99') AS USEAGE_PERCENT, --使用占比 F.MAX_BYTES AS BLOCK_MAX_BYTES --最大BLOCK块 FROM (SELECT TABLESPACE_NAME, ROUND(SUM(BYTES) / (1024 * 1024), 2) FREE_BYTES, ROUND(MAX(BYTES) / (1024 * 1024), 2) MAX_BYTES FROM SYS.DBA_FREE_SPACE GROUP BY TABLESPACE_NAME) F, (SELECT DD.TABLESPACE_NAME, ROUND(SUM(DD.BYTES) / (1024 * 1024), 2) TOTAL_BYTES FROM SYS.DBA_DATA_FILES DD GROUP BY DD.TABLESPACE_NAME) D WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME ORDER BY 4 DESC;
4.查看数据库版本相关信息
SELECT PRODUCT,VERSION,STATUS FROM PRODUCT_COMPONENT_VERSION;
5.查看表大小
analyze table tablename compute statistics; SELECT NUM_ROWS * AVG_ROW_LEN FROM USER_TABLES WHERE TABLE_NAME = 'tablename';
6.查看正在执行的SQL
SELECT b.sid oracleID, b.username, b.machine, b.PROGRAM, b.serial#, spid , STATUS, paddr, sql_text, c.CPU_TIME FROM v$process a, v$session b, v$sqlarea c WHERE a.addr = b.paddr AND b.sql_hash_value = c.hash_value;
7.查看当前表被锁对象
SELECT SESS.SID, SESS.SERIAL#, LO.ORACLE_USERNAME, LO.OS_USER_NAME, AO.OBJECT_NAME, LO.LOCKED_MODE, SESS.MACHINE, SESS.TERMINAL, SESS.LOGON_TIME FROM V$LOCKED_OBJECT LO, DBA_OBJECTS AO, V$SESSION SESS WHERE AO.OBJECT_ID = LO.OBJECT_ID AND LO.SESSION_ID = SESS.SID; ALTER SYSTEM KILL SESSION 'SID,SERIAL#'; --杀掉锁表进程
网站名称:Oracle常用SQL汇总(持续更新)
本文URL:http://pwwzsj.com/article/pdphpj.html