set autotrace on SP2-0618: 無法找到會話標識符。啓用檢查 PLUSTRACE 角色 SP2-0611: 啓用 STATISTICS 報告時出錯

scott用戶執行set autotrace on報錯:

SQL> set autotrace on
SP2-0618: 無法找到會話標識符。啓用檢查 PLUSTRACE 角色
SP2-0611: 啓用 STATISTICS 報告時出錯

原因:

用戶沒有PLUSTRACE角色權限

解決辦法:

  1. 以sys用戶,執行下面二個sql文件
    1)執行$ORACLE_HOME/sqlplus/admin/plustrce.sql ,創建角色
    2)執行$ORACLE_HOME/rdbms/admin/utlxplan.sql,創建plan_table表
    文件內容:
    在這裏插入圖片描述
    執行文件:
    SQL> @D:\app\Administrator\product\11.2.0\dbhome_1\sqlplus\admin\plustrce.sql
    #以下爲plustrce.sql的執行代碼:
    SQL>
    SQL> drop role plustrace;
    drop role plustrace
              *1 行出現錯誤:
    ORA-01919: 角色 'PLUSTRACE' 不存在
    
    
    SQL> create role plustrace;
    
    角色已創建。
    
    SQL>
    SQL> grant select on v_$sesstat to plustrace;
    
    授權成功。
    
    SQL> grant select on v_$statname to plustrace;
    
    授權成功。
    
    SQL> grant select on v_$mystat to plustrace;
    
    授權成功。
    
    SQL> grant plustrace to dba with admin option;
    
    授權成功。
    
    SQL>
    SQL> set echo off
    SQL> @D:\app\Administrator\product\11.2.0\dbhome_1\RDBMS\ADMIN\utlxplan.sql
    
    表已創建。
    
  2. 給用戶賦予plustrace角色權限。
    SQL> grant plustrace to scott;
    SQL> grant select any dictionary toscott;
    
  3. 測試
    退出後再次測試成功
    在這裏插入圖片描述

後續

報錯ORA-01039: 視圖基本對象的權限不足


執行計劃
----------------------------------------------------------
ERROR:
ORA-01039: 視圖基本對象的權限不足


SP2-0612: 生成 AUTOTRACE EXPLAIN 報告時出錯

統計信息
----------------------------------------------------------
          0  recursive calls
          0  db block gets
       1520  consistent gets
          0  physical reads
          0  redo size
        793  bytes sent via SQL*Net to client
        427  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
         16  rows processed

需要給scott再授權grant select any dictionary to scott;

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