查看不同用戶的連接數量:
select username,count(username) from v$session where username is not null group by username
查看哪個過程被鎖:
SELECT * FROM V$DB_OBJECT_CACHE WHERE OWNER=''過程的所屬用戶'' AND LOCKS!=''0'';
查看鎖定數據庫的用戶:
select * from v$locked_object;
查看沒有提交的事務:
select * from v$transaction;--從這句也可以查看鎖定數據庫的用戶
獲得當前數據庫的session數及數據庫啟動以來最大的session數
select sum(sessions_current) cur_sessions,sum(sessions_highwater) high_sessions from V$LICENSE;
查看某個表所在的表空間名:
select tablespace_name from user_tables where table_name=''BILL_ORG''--說明:表名必須大寫
查看數據文件存放的路徑:
select tablespace_name,file_id,bytes/1024/1024,file_name
from dba_data_files order by file_id
查看當前用戶下的所有表:
select * from all_tables where owner=''YSPJ''
查看運行過的SQL語句:
SELECT SQL_TEXT FROM V$SQL
查看客戶端機器名、IP地址、登錄客戶端的用戶:
SELECT
SYS_CONTEXT(''USERENV'',''TERMINAL'') TERMINAL,
SYS_CONTEXT(''USERENV'',''HOST'') HOST,
SYS_CONTEXT(''USERENV'',''OS_USER'') OS_USER,
SYS_CONTEXT(''USERENV'',''IP_ADDRESS'') IP_ADDRESS
FROM DUAL
查看某個SID執行的SQL語句的運行情況:
select command_type,sql_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_processed,sysdate start_time,
sysdate finish_time,''>'' || address sql_address,''N'' status
from v$sqlarea
where address = (select sql_address from v$session where sid =11)
查看某個表所占用的空間的大小:
select sum(bytes)/(1024*1024) as "size(M)" from user_segments where segment_name=upper(''BILL_MAIN'');
查看某個存儲過程的源代碼:
select text from all_source where owner=user and name=upper(''month_BenYueJIEYu_2'');
查看當前數據徊的用戶的SID:
select username,sid,serial# from v$session;
將當前某個用戶的連接殺死:比如殺死YSPJ用戶的連接:
先執行alter system kill session ''sid,serial#'';
根據返回的SID和serial,執行下面的語句:
alter system kill session ''sid,serial#'';--其中SID和serial為上面的SQL語句返回的值。