Oracle - SQL 优化 -------- > 创建PLUSTRACE角色

SQL> conn / as sysdba
Connected.
SQL> @$ORACLE_HOME/sqlplus/admin/plustrce

运行结果:

SQL> 
SQL> drop role plustrace;
drop role plustrace
          *
ERROR at line 1:
ORA-01919: role 'PLUSTRACE' does not exist


Elapsed: 00:00:01.71
SQL> create role plustrace;

Role created.

Elapsed: 00:00:00.26
SQL> 
SQL> grant select on v_$sesstat to plustrace;

Grant succeeded.

Elapsed: 00:00:00.27
SQL> grant select on v_$statname to plustrace;

Grant succeeded.

Elapsed: 00:00:00.02
SQL> grant select on v_$mystat to plustrace;

Grant succeeded.

Elapsed: 00:00:00.02
SQL> grant plustrace to dba with admin option;

Grant succeeded.

Elapsed: 00:00:00.02
SQL> 
SQL> set echo off
执行完该脚本,就可以在数据库中看到一个名为PLUSTRACE的角色,而且可以将该角色授权给需要使用SET AUTOTRACE的用户。

##  给用户scott授权

SQL> grant plustrace to scott;

Grant succeeded.

Elapsed: 00:00:00.03
##  看下,是否可以使用了?

SQL> set autotrace on
SQL> select 1 from dual;

         1
----------
         1

Elapsed: 00:00:00.06

Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=CHOOSE
   1    0   TABLE ACCESS (FULL) OF 'DUAL'




Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
          0  consistent gets
          0  physical reads
          0  redo size
          0  bytes sent via SQL*Net to client
          0  bytes received via SQL*Net from client
          0  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed
OK !

你可能感兴趣的:(Oracle,-,SQL,优化)