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