Oracle数据库经典SQL查询常用SQL查询:1、查看表空间的名称及大小selectt.tablespace_name,round(sum(bytes/(1024*1024)),0)ts_sizefromdba_tablespacest,dba_data_filesdwheret.tablespace_name=d.tablespace_namegroupbyt.tablespace_name;2、查看表空间物理文件的名称及大小selecttablespace_name,file_id,file_name,round(bytes/(1024*1024),0)total_spacefromdba_data_filesorderbytablespace_name;3、查看回滚段名称及大小selectsegment_name,tablespace_name,r.status,(initial_extent/1024)InitialExtent,(next_extent/1024)NextExtent,max_extents,v.curextCurExtentFromdba_rollback_segsr,v$rollstatvWherer.segment_id=v.usn(+)orderbysegment_name;4、查看控制文件selectnamefromv$controlfile;5、查看日志文件selectmemberfromv$logfile;6、查看表空间的使用情况selectsum(bytes)/(1024*1024)asfree_space,tablespace_namefromdba_free_spacegroupbytablespace_name;SELECTA.TABLESPACE_NAME,A.BYTESTOTAL,B.BYTESUSED,C.BYTESFREE,(B.BYTES*100)/A.BYTES%USED,(C.BYTES*100)/A.BYTES%FREEFROMSYS.SM$TS_AVAILA,SYS.SM$TS_USEDB,SYS.SM$TS_FREECWHEREA.TABLESPACE_NAME=B.TABLESPACE_NAMEANDA.TABLESPACE_NAME=C.TABLESPACE_NAME;7、查看数据库库对象selectowner,object_type,status,count(*)count#fromall_objectsgroupbyowner,object_type,status;8、查看数据库的版本SelectversionFROMProduct_component_versionWhereSUBSTR(PRODUCT,1,6)='Oracle';9、查看数据库的创建日期和归档方式SelectCreated,Log_Mode,Log_ModeFromV$Database;10、捕捉运行很久的SQLcolumnusernameformata12columnopnameformata16columnprogressformata8selectusername,sid,opname,round(sofar*100/totalwork,0)||'%'asprogress,time_remaining,sql_textfromv$session_longops,v$sqlwheretime_remaining0andsql_address=addressandsql_hash_value=hash_value/11。查看数据表的参数信息SELECTpartition_name,high_value,high_value_length,tablespace_name,pct_free,pct_used,ini_trans,max_trans,initial_extent,next_extent,min_extent,max_extent,pct_increase,FREELISTS,freelist_groups,LOGGING,BUFFER_POOL,num_rows,blocks,empty_blocks,avg_space,chain_cnt,avg_row_len,sample_size,last_analyzedFROMdba_tab_partitions--WHEREtable_name=:tnameANDtable_owner=:townerORDERBYpartition_position12.查看还没提交的事务select*fromv$locked_object;select*fromv$transaction;13。查找object为哪些进程所用selectp.spid,s.sid,s.serial#serial_num,s.usernameuser_name,a.typeobject_type,s.osuseros_user_name,a.owner,a.objectobject_name,decode(sign(48-command),1,to_char(command),'ActionCode#'||to_char(command))action,p.programoracle_process,s.terminalterminal,s.programprogram,s.statussession_statusfromv$sessions,v$accessa,v$processpwheres.paddr=p.addrands.type='USER'anda.sid=s.sidanda.object='SUBSCRIBER_ATTR'orderbys.username,s.osuser14。回滚段查看selectrownum,sys.dba_rollback_segs.segment_nameName,v$rollstat.extentsExtents,v$rollstat.rssizeSize_in_Bytes,v$rollstat.xactsXActs,v$rollstat.getsGets,v$rollstat.waitsWaits,v$rollstat.writesWrites,sys.dba_rollback_segs.statusstatusfromv$rollstat,sys.dba_rollback_segs,v$rollnamewherev$rollname.name(+)=sys.dba_rollback_segs.segment_nameandv$rollstat.usn(+)=v$rollname.usnorderbyrownum15。耗资源的进程(topsession)selects.schemanameschema_name,decode(sign(48-command),1,to_char(command),'ActionCode#'||to_char(command))action,statussession_status,s.osuseros_user_name,s.sid,p.spid,s.serial#serial_num,nvl(s.username,'[Oracleprocess]')user_name,s.terminalterminal,s.programprogram,st.valuecriteria_valuefromv$sesstatst,v$sessions,v$processpwherest.sid=s.sidandst.statistic#=to_number('38')and('ALL'='ALL'ors.status='ALL')andp.addr=s.paddrorderbyst.valuedesc,p.spidasc,s.usernameasc,s.osuserasc16。查看锁(lock)情况select/*+RULE*/ls.osuseros_user_name,ls.usernameuser_name,decode(ls.type,'RW','Rowwaitenqueuelock','TM','DMLenqueuelock','TX','Transactionenqueuelock','UL','Usersuppliedlock')lock_type,o.object_nameobject,decode(ls.lmode,1,null,2,'RowShare',3,'RowExclusive',4,'Share',5,'ShareRowExclusive',6,'Exclusive',null)lock_mode,o.owner,ls.sid,ls.serial#serial_num,ls.id1,ls.id2fromsys.dba_objectso,(selects.osuser,s.username,l.type,l.lmode,s.sid,s.serial#,l.id1,l.id2fromv$sessions,v$locklwheres.sid=l.sid)lswhereo.object_id=ls.id1ando.owner'SYS'orderbyo.owner,o.object_name17。查看等待(wait)情况SELECTv$waitstat.class,v$waitstat.countcount,SUM(v$sysstat.value)sum_valueFROMv$waitstat,v$sysstatWHEREv$sysstat.nameIN('dbblockgets','consistentgets')groupbyv$waitstat.class,v$waitstat.count18。查看sga情况SELECTNAME,BYTESFROMSYS.V_$SGASTATORDERBYNAMEASC19。查看catchedobjectSELECTowner,name,db_link,namespace,type,sharable_mem,loads,executions,locks,pins,keptFROMv$db_object_cache20。查看V$SQLAREASELECTSQL_TEXT,SHARABLE_MEM,PERSISTENT_MEM,RUNTIME_MEM,SORTS,VERSION_COUNT,LOADED_VERSIONS,OPEN_VERSIONS,USERS_OPENING,EXECUTIONS,USERS_EXECUTING,LOADS,FIRST_LOAD_TIME,INVALIDATIONS,PARSE_CALLS,DISK_READS,BUFFER_GETS,ROWS_PROCESSEDFROMV$SQLAREA21。查看object分类数量selectdecode(o.type#,1,'INDEX',2,'TABLE',3,'CLUSTER',4,'VIEW',5,'SYNONYM',6,'SEQUENCE','OTHER')object_type,count(*)quantityfromsys.obj$owhereo.type#1groupbydecode(o.type#,1,'INDEX',2,'TABLE',3,'CLUSTER',4,'VIEW',5,'SYNONYM',6,'SEQUENCE','OTHER')unionselect'COLUMN',count(*)fromsys.col$unionselect'DBLINK',count(*)from22。按用户查看object种类selectu.nameschema,sum(decode(o.type#,1,1,NULL))indexes,sum(decode(o.type#,2,1,NULL))tables,sum(decode(o.ty