1. 程式人生 > >查詢資料庫當前使用者連線資訊(MySQL,Oracle)

查詢資料庫當前使用者連線資訊(MySQL,Oracle)

MYSQL有個命令可以列出所有當前連線( show processlist; ),但由於其結果集不是普通的查詢結果集,程式處理時可能有問題,建議使用以下SQL語句:
 
select id,user as user_,host,db,command,time,state from information_schema.PROCESSLIST
 
Oracle的SQL語句:
select * from v$session where username is not null order by logon_time, sid

為保持和上面MySQL的欄位對應關係,還可以這樣改下:

select sid as id,username as user_, machine as host,schemaname as db,action as command,'' as time,status as state from v$session where username is not null order by logon_time, sid