我无法使用Autotrace Traceonly Oracle打印统计数据

wgxvkvu9  于 2023-01-04  发布在  Oracle
关注(0)|答案(1)|浏览(161)

我想打印sql查询的执行统计信息。为此我想使用autotrace。当我在explain上使用autotrace时,我没有问题,它正确地打印了所有内容。但是,当我想使用autotrace traceonly时,程序说"不支持"。我的用户拥有所有权限......那是什么问题呢?

set autotrace traceonly;
set timing on;

-- Here i have my 4 Querys

set timing off;

结果:
当前不支持traceonly选项。
我还想打印这样的东西:

什么是命令打印的组成得到,像在我的形象?
有什么想法吗?
我使用的是SQL Developer和Oracle 11-G

roejwanj

roejwanj1#

更新:只需升级SQL Developer副本(22.2.1是最新版本)
下面是一个使用SQLDev(SQLcl)命令行版本的演示。相同的代码可以在SQL Developer的SQL工作表中使用F5。

SQL> set autotrace traceonly;
Autotrace TraceOnly
 Exhibits the performance statistics with silent query output
SQL> set timing on;
SQL> select 1 from dual;

1 row selected.

PLAN_TABLE_OUTPUT
_____________________________________________
SQL_ID  520mkxqpf15q8, child number 0
-------------------------------------
select 1 from dual

Plan hash value: 1388734953

------------------------------------------
| Id  | Operation        | Name | E-Rows |
------------------------------------------
|   0 | SELECT STATEMENT |      |        |
|   1 |  FAST DUAL       |      |      1 |
------------------------------------------

Note

PLAN_TABLE_OUTPUT
____________________________________________________________________________________
-----
   - Warning: basic plan statistics not available. These are only collected when:
       * hint 'gather_plan_statistics' is used for the statement or
       * parameter 'statistics_level' is set to 'ALL', at session or system level

Statistics
-----------------------------------------------------------
               1  CPU used by this session
               1  CPU used when call started
               1  DB time
              42  Requests to/from client
              42  SQL*Net roundtrips to/from client
             573  bytes received via SQL*Net from client
           82982  bytes sent via SQL*Net to client
               2  calls to get snapshot scn: kcmgss
               2  calls to kcmgcs
               2  execute count
              43  non-idle wait count
               2  opened cursors cumulative
               1  opened cursors current
               2  parse count (total)
               1  session cursor cache hits
               1  sorts (memory)
            2010  sorts (rows)
              43  user calls
Elapsed: 00:00:00.058
SQL>

如果你用的是旧版本,那么-
您将需要使用SQL * Plus。

[oracle@vbgeneric ~]$ sqlplus demo/oracle

SQL*Plus: Release 12.1.0.2.0 Production on Sat Apr 29 16:31:12 2017

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

Last Successful login time: Sat Apr 29 2017 09:03:35 -04:00

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> set autotrace traceonly;
set timing on;

select 1 from dual;
select 2 from dual;
select 3 from dual;
select 4 from dual;

set timing off;SQL> SQL> SQL> 
Elapsed: 00:00:00.02

Execution Plan
----------------------------------------------------------
Plan hash value: 1388734953

-----------------------------------------------------------------
| Id  | Operation    | Name | Rows  | Cost (%CPU)| Time|
-----------------------------------------------------------------
|   0 | SELECT STATEMENT |  |     1 |     2   (0)| 00:00:01 |
|   1 |  FAST DUAL   |  |     1 |     2   (0)| 00:00:01 |
-----------------------------------------------------------------

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

SQL> 
Elapsed: 00:00:00.01

Execution Plan
----------------------------------------------------------
Plan hash value: 1388734953

-----------------------------------------------------------------
| Id  | Operation    | Name | Rows  | Cost (%CPU)| Time|
-----------------------------------------------------------------
|   0 | SELECT STATEMENT |  |     1 |     2   (0)| 00:00:01 |
|   1 |  FAST DUAL   |  |     1 |     2   (0)| 00:00:01 |
-----------------------------------------------------------------

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

SQL> 
Elapsed: 00:00:00.01

Execution Plan
----------------------------------------------------------
Plan hash value: 1388734953

-----------------------------------------------------------------
| Id  | Operation    | Name | Rows  | Cost (%CPU)| Time|
-----------------------------------------------------------------
|   0 | SELECT STATEMENT |  |     1 |     2   (0)| 00:00:01 |
|   1 |  FAST DUAL   |  |     1 |     2   (0)| 00:00:01 |
-----------------------------------------------------------------

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

SQL> 
Elapsed: 00:00:00.00

Execution Plan
----------------------------------------------------------
Plan hash value: 1388734953

-----------------------------------------------------------------
| Id  | Operation    | Name | Rows  | Cost (%CPU)| Time|
-----------------------------------------------------------------
|   0 | SELECT STATEMENT |  |     1 |     2   (0)| 00:00:01 |
|   1 |  FAST DUAL   |  |     1 |     2   (0)| 00:00:01 |
-----------------------------------------------------------------

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

SQL> SQL>
  • 免责声明:我在Oracle工作,是SQL Developer的产品经理。*

相关问题