---
title: "SP2-0618: Cannot find the Session Identifier"
author: "andyniu"
date: "2013-07-15T10:28:50Z"
tags: []
categories: ["数据库"]
slug: "sp2-0618-cannot-find-the-session-identifier"
draft: false
lastmod: "2013-07-15T10:32:02Z"
id: 1906235
url: "https://andyniu.iteye.com/blog/1906235"
---

SQL&gt; set au[to](http://www.net527.cn/a/luyoujiaohuan/)trace [on](http://www.net527.cn/a/luyoujiaohuan/)  
SP2-0618: Cannot find the Session Identifier. Check PLUSTRACE role is enabled  
SP2-0611: Error enabling STATISTICS report

SQL&gt; select * from v$version;

BANNER  
\----------------------------------------------------------------  
Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Prod  
PL/SQL Release 10.1.0.2.0 - Production  
CORE 10.1.0.2.0 Production  
TNS for 32-bit Windows: Version 10.1.0.2.0 - Production  
NLSRTL Version 10.1.0.2.0 - Production

 

看提示是说PLUSTRACE role is not enabled

数据库在安装的时候没有创建plustrace 角色

该角色有那些权限？

我们可以从ora\_homesqlplusadminplustrce.sql中找到答案

-- Copyright (c) Oracle Corporation 1995, 2002. All Rights Reserved.  
\--  
\-- NAME  
\-- plustrce.sql  
\--  
\-- DESCRIPTION  
\-- Creates a role with access to Dynamic Performance Tables  
\-- for the SQL\*Plus SET AUTOTRACE ... STATISTICS command.  
\-- After this script has been run, each user requiring access to  
\-- the AUTOTRACE feature should be granted the PLUSTRACE role by  
\-- the DBA.  
\--  
\-- USAGE  
\-- sqlplus "/ as sysdba" @plustrce  
\--  
\-- Catalog.sql must have been run before this file is run.  
\-- This file must be run while connected to a DBA schema.

set echo on

drop role plustrace;  
create role plustrace;

grant select on v\_$sesstat to plustrace;  
grant select on v\_$statname to plustrace;  
grant select on v\_$mystat to plustrace;  
grant plustrace to dba with admin option;

set echo off  
至此我们可以利用该sql脚本创建plustrace role

SQL&gt; show user  
USER is "SYS"

SQL&gt; @?sqlplusadminplustrce  
SQL&gt;  
SQL&gt; drop role plustrace;

Role dropped.

SQL&gt; create role plustrace;

Role created.

SQL&gt;  
SQL&gt; grant select on v\_$sesstat to plustrace;

Grant succeeded.

SQL&gt; grant select on v\_$statname to plustrace;

Grant succeeded.

SQL&gt; grant select on v\_$mystat to plustrace;

Grant succeeded.

SQL&gt; grant plustrace to dba with admin option;

Grant succeeded.

SQL&gt;  
SQL&gt; set echo off  
SQL&gt; grant plustrace to scott;

Grant succeeded.

你可以将该role授予任何用户

然后我们再用scott用户连上看看

C:&gt;sqlplus scott/tiger

SQL\*Plus: Release 10.1.0.2.0 - Production on Wed May 24 11:36:43 2006

Copyright (c) 1982, 2004, Oracle. All rights reserved.

Connected to:  
Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production  
With the Partitioning, OLAP and Data Mining options

SQL&gt; select count(\*) from tt;

COUNT(\*)  
\----------  
1

SQL&gt; set autotrace traceonly  
SQL&gt; select count(\*) from tt;

Execution Plan  
\----------------------------------------------------------  
0 SELECT STATEMENT Optimizer=ALL\_ROWS (Cost=3 Card=1)  
1 0 SORT (AGGREGATE)  
2 1 TABLE ACCESS (FULL) OF 'TT' (TABLE) (Cost=3 Card=1)

Statistics  
\----------------------------------------------------------  
0 recursive calls  
0 db block gets  
7 consistent gets  
0 physical reads  
0 redo size  
393 bytes sent via SQL\*Net to client  
512 bytes received via SQL\*Net from client  
2 SQL\*Net roundtrips to/from client  
0 sorts (memory)  
0 sorts (disk)  
1 rows processed  
至此这一问题得到解决