今天新建数据库使用hr用户练习的时候,set autotrace on时出现以下错误

是因为没有PLUSTRACE权限

涉及到@ORACLE_HOME/sqlplus/admin/plustrce.sql文件

内容如下

--DESCRIPTION--CreatesarolewithaccesstoDynamicPerformanceTables--fortheSQL*PlusSETAUTOTRACE...STATISTICScommand.--Afterthisscripthasbeenrun,eachuserrequiringaccessto--theAUTOTRACEfeatureshouldbegrantedthePLUSTRACEroleby--theDBA.----USAGE--sqlplus"sys/knl_test7assysdba"@plustrce----Catalog.sqlmusthavebeenrunbeforethisfileisrun.--ThisfilemustberunwhileconnectedtoaDBAschema.setechoondroproleplustrace;createroleplustrace;grantselectonv_$sesstattoplustrace;grantselectonv_$statnametoplustrace;grantselectonv_$mystattoplustrace;grantplustracetodbawithadminoption;setechooff

1. 查找数据库中是否有该角色

SQL>select*fromdba_roleswhererole='PLUSTRACE';norowsselected

2.建立角色 (使用sys用户)

SQL>@?/sqlplus/admin/plustrce.sqlSQL>SQL>droproleplustrace;droproleplustrace*ERRORatline1:ORA-01919:role'PLUSTRACE'doesnotexistSQL>createroleplustrace;Rolecreated.SQL>SQL>grantselectonv_$sesstattoplustrace;Grantsucceeded.SQL>grantselectonv_$statnametoplustrace;Grantsucceeded.SQL>grantselectonv_$mystattoplustrace;Grantsucceeded.SQL>grantplustracetodbawithadminoption;Grantsucceeded.SQL>SQL>setechooff

3.查询数据库

SQL>select*fromdba_roleswhererole='PLUSTRACE';ROLEPASSWORDAUTHENTICAT-------------------------------------------------PLUSTRACENONONE

4.授予操作用户改权限

SQL>grantplustracetohr;Grantsucceeded.

5.使用hr用户测试是否成功

SQL>connhr/hrConnected.SQL>SQL>setautotraceon