手机版
你好,游客 登录 注册
背景:
阅读新闻

使用触发器记录Oracle用户登陆信息

[日期:2013-10-30] 来源:Linux社区  作者:leshami [字体:大 中 小]

2、结果样例

--查看用户的登入登出信息
SQL> select * from sys.stats$user_log where rownum<3;

USER_ID    SESSION_ID HOST            LAST_PROGRAM    LAST_MODULE    LOGON_DAY LOGON_TIME LOGOFF_DA LOGOFF_TIM  ELP_MINS
---------- ---------- --------------- ---------------- ---------------- --------- ---------- --------- ---------- --------
GX_ADMIN    5409517  v2012DB01u      JDBC Thin Client JDBC Thin Client 24-OCT-13 12:20:30  24-OCT-13 16:20:30  240
GX_ADMIN    5409518  v2013DB01u      JDBC Thin Client JDBC Thin Client 24-OCT-13 12:22:23  24-OCT-13 16:22:30  240

--汇总用户登陆时间   
SQL> SELECT user_id, TRUNC (logon_day) logon_day, SUM (elapsed_minutes) total_time
  2  FROM sys.stats$user_log
  3  GROUP BY user_id, TRUNC (logon_day) ORDER BY 2;

USER_ID                        LOGON_DAY TOTAL_TIME
------------------------------ --------- ----------
GX_ADMIN                      24-OCT-13        960
SYS                            24-OCT-13
GX_ADMIN                      25-OCT-13      2891
GX_WEBUSER                    25-OCT-13
SYS                            25-OCT-13
GX_WEBUSER                    26-OCT-13
GX_ADMIN                      26-OCT-13      2880
SYS                            26-OCT-13
GX_WEBUSER                    27-OCT-13
GX_ADMIN                      27-OCT-13      2640
GX_WEBUSER                    28-OCT-13

--Author : Leshami
--Blog  : http://www.linuxidc.com

--基于日期时间段的用户登陆数
SQL> select trunc (logon_day) logon_day,substr(logon_time,1,2) hour,count(user_id) as number_of_logins
  2  from sys.stats$user_log
  3  group by trunc (logon_day) ,substr(logon_time,1,2)  order by 1,2;

LOGON_DAY HOUR  NUMBER_OF_LOGINS
--------- ------ ----------------
24-OCT-13 12                    2
24-OCT-13 16                    3
24-OCT-13 20                    2
24-OCT-13 22                    2
24-OCT-13 23                    1
25-OCT-13 00                    2
25-OCT-13 03                  104
25-OCT-13 04                    2
25-OCT-13 06                    2
25-OCT-13 10                    2
25-OCT-13 14                    2
  .............

 

推荐阅读:

Oracle中的角色和权限授予 http://www.linuxidc.com/Linux/2013-09/90596.htm

Oracle收集用户的权限 http://www.linuxidc.com/Linux/2013-04/82173.htm

Oracle权限总结 http://www.linuxidc.com/Linux/2013-01/78475.htm

Oracle查询指定用户有权限的所有表 http://www.linuxidc.com/Linux/2013-01/78403.htm

修改文件目录权限导致数据库连接报错ORA-12547 http://www.linuxidc.com/Linux/2013-01/77432.htm

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux
相关资讯       Oracle触发器 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款