启用plustrace 角色
在新建的hr 用户中执行下面的语句开启执行计划输出。
SQL> set autotrace traceonly
SP2-0618: Cannot find the Session Identifier. Check PLUSTRACE role is enabled
SP2-0611: Error enabling STATISTICS report
在sys 的会话中尝试给 hr 用户授予plustrace 权限。不成功,好吧是时候查找资料解决了。
SQL> grant plustrace to hr;
grant plustrace to hr
*
ERROR at line 1:
ORA-01919: role 'PLUSTRACE' does not exist
在sqlplus 中为了使用set autotrace 。。。命令获得执行计划的输出,用户所在的模式下必须有plan_table 这张表存在用来提供统计信息,并且获得plustrace 权限。下面来进行这两项工作。
首先使用hr 用户连接到数据库,执行$ORACLE_HOME/rdbms/admin 下的utlxplan 脚本。
SQL> @utlxplan
Table created.
然后以sys 用户登录系统执行$ORACLE_HOME/sqlplus/admin 下的plustrce 脚本。
SQL> @plustrce
SQL> drop role plustrace;
drop role plustrace
*
ERROR at line 1:
ORA-01919: role 'PLUSTRACE' does not exist
SQL> create role plustrace;
Role created.
SQL> grant select on v_$sesstat to plustrace;
Grant succeeded.
SQL> grant select on v_$statname to plustrace;
Grant succeeded.
SQL> grant select on v_$mystat to plustrace;
Grant succeeded.
SQL> grant plustrace to dba with admin option;
Grant succeeded.
SQL> set echo off
最后把plustrace 授权给hr 用户。现在hr 用户就可以使用set autotrace。。。 命令了。
SQL> grant plustrace to hr;
Grant succeeded.
很有可能现在hr 的会话中执行set autotrace。。。 还是会报下面的错误,退出sqlplus 会话再次登录就OK 了。
SP2-0618: Cannot find the Session Identifier. Check PLUSTRACE role is enabled
SP2-0611: Error enabling STATISTICS report