查詢數據庫當前用戶連接信息(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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章