plan_table 是旧版本,修复结果导致 ORA-02304: 无效的对象标识符文字。

huangapple go评论54阅读模式
英文:

plan_table is old version fix results in ORA-02304: invalid object identifier literal

问题

我遇到与此处报道的相同问题:

> 问题:当使用"set autotrace on"来执行查询时,我收到以下消息:
>
> - 'PLAN_TABLE' 是旧版本
>
> 如何获取我的SQL解释计划的当前计划表?

那里的答案非常简单:

> 您必须暂时将sysdba授权给用户并按照以下步骤操作:
>
> cd $ORACLE_HOME/RDBMS/ADMIN
>
> sqlplus system manager as sysdba
>
> grant sysdba to myuser;
>
> connect myuser as sysdba
>
> @catplan
>
> revoke sysdba from myuser;
>
> exit;
>
> 这将防止使用旧版本的计划表。

但在执行catplan.sql时,我遇到了这个错误:

plan_table 是旧版本,修复结果导致 ORA-02304: 无效的对象标识符文字。

整个catplan.sql如下:

Rem
Rem $Header: catplan.sql 02-feb-2008.21:10:57 kyagoub Exp $
Rem
Rem catplan.sql
Rem
Rem Copyright (c) 2003, 2008, Oracle. All rights reserved.
Rem
Rem NAME
Rem catplan.sql - 创建公共计划表
Rem
Rem DESCRIPTION
Rem 此脚本创建一个作为全局临时表的公共计划表,可从任何模式访问。它还创建了plan_id序列号。
Rem
Rem
Rem MODIFIED (MM/DD/YY)
Rem kyagoub 02/02/08 - 删除plan_table$,因为它没有升级
Rem bdagevil 02/24/05 - 增加最大行大小
Rem pbelknap 07/23/04 - 为stat_row_type添加oid
Rem pbelknap 06/30/04 - 更改oid
Rem kyagoub 06/23/04 - 添加sql_plan_stat_row_type
Rem pbelknap 04/27/04 - 授予public执行sql_plan_xxx的权限,创建公共同义词并将删除语句移至catnplan.sql
Rem pbelknap 04/20/04 - 计划不同类型
Rem bdagevil 05/08/04 - 添加other_xml列
Rem bdagevil 11/01/03 - 所有运行dbms_xplan
Rem bdagevil 06/18/03 - 将提示别名更名为object_alias
Rem bdagevil 06/06/03 - 提示别名增加大小
Rem aime 04/25/03 - aime_going_to_main
Rem bdagevil 02/24/03 - bdagevil_sql_tune_5
Rem bdagevil 02/13/03 - 创建
Rem

create type dbms_xplan_type
as object (plan_table_output varchar2(300));
/

create type dbms_xplan_type_table
as table of dbms_xplan_type;
/

REM 较低特权用户所需
grant execute on dbms_xplan_type to public;
grant execute on dbms_xplan_type_table to public;

Rem
Rem 用于计划差异的计划对象类型
Rem - sql_plan_table_type是存储计划句柄的方便方法。dbms_xplan.compare_query_plans函数以两个计划作为参数,因此它需要一个汇总的类型。
Rem - ***请注意,这些类型仅由此函数使用,不应在用户脚本/表中使用,因为它们可能在将来更改

Rem
Rem SQL_PLAN_ROW_TYPE, SQL_PLAN_TABLE_TYPE
Rem
Rem 这些类型反映了计划表的结构,并用于将计划传递到此包中以进行计划比较。
Rem
Rem 您可以如下填充SQL_PLAN_TABLE_TYPE类型的嵌套表:
Rem
Rem select CAST(COLLECT
Rem (sql_plan_row_type(statement_id,plan_id,timestamp,remarks,
Rem operation,options,object_node,object_owner,object_name,
Rem object_alias,object_instance,object_type,optimizer,
Rem search_columns,id,parent_id,depth,position,cost,
Rem cardinality,bytes,other_tag,partition_start,
Rem partition_stop,partition_id,NULL,distribution,cpu_cost,
Rem io_cost,temp_space,access_predicates,filter_predicates,
Rem projection,time,qblock_name,other_xml))
Rem AS SQL_PLAN_TABLE_TYPE)
Rem from plan_table where plan_id = :plid order by id;

create type sql_plan_row_type
timestamp '1997-04-12:12:59:00' oid '00000000000000000000000000020210'
as object (
statement_id varchar2(30),
plan_id number,
timestamp date,
remarks varchar2(4000),
operation varchar2(30),
options varchar2(255),
object_node varchar2(128),
object_owner varchar2(30),
object_name varchar2(30),
object_alias varchar2(65),
object_instance numeric,
object_type varchar2(30),
optimizer varchar2(255),
search_columns number,
id numeric,
parent_id numeric,
depth numeric,
position numeric,
cost numeric,
cardinality numeric,
bytes numeric,
other_tag varchar2(255),
partition_start varchar2(255),
partition_stop varchar2(255),
partition_id numeric,
distribution varchar2(30),
cpu_cost numeric,
io_cost numeric,
temp_space numeric,
access_predicates varchar2(4000),
filter_predicates varchar2(4000),
projection varchar2(4000),
time numeric,
qblock_name varchar2(30),
other_xml clob
) NOT FINAL
/

create or replace public synonym sql_plan_row_type for sql_plan_row_type
/

grant execute on sql_plan_row_type to public
/

Rem
Rem sql_plan_table_type
Rem
create type sql_plan_table_type
timestamp '1997-04-12:12:59:00' oid '00000000000000000000000000020211'
as table of sql_plan_row_type
/

英文:

I had the same quersion as reported here:

> Question: I am getting this message when using "set autotrace on" for
> a query:
>
> - 'PLAN_TABLE' is old version
>
> How to I get the current plan table for my SQL explain plans?

The answer there is is very simple:

> You have to temporarily grant sysdba to the user and follow these
> steps:
>
> cd $ORACLE_HOME/RDBMS/ADMIN
>
> sqlplus system manager as sysdba
>
> grant sysdba to myuser;
>
> connect myuser as sysdba
>
> @catplan
>
> revoke sysdba from myuser;
>
> exit;
>
> This will prevent the old version of the plan table from being used.

But performing catplan.sql, at this command I got this error:

plan_table 是旧版本,修复结果导致 ORA-02304: 无效的对象标识符文字。

The whole catplan.sql is this:

Rem
Rem $Header: catplan.sql 02-feb-2008.21:10:57 kyagoub Exp $
Rem
Rem catplan.sql
Rem
Rem Copyright (c) 2003, 2008, Oracle. All rights reserved.  
Rem
Rem    NAME
Rem      catplan.sql - CATALOG create public plan table
Rem
Rem    DESCRIPTION
Rem      This script creates a public plan table as a global temporary
Rem      table accessible from any schema. It also creates the plan_id
Rem      sequence number.
Rem
Rem
Rem    MODIFIED   (MM/DD/YY)
Rem    kyagoub     02/02/08 - drop plan_table$ as it is not upgradedd
Rem    bdagevil    02/24/05 - increase maximum line size 
Rem    pbelknap    07/23/04 - type oid for stat_row_type 
Rem    pbelknap    06/30/04 - change oids 
Rem    kyagoub     06/23/04 - add sql_plan_stat_row_type 
Rem    pbelknap    06/25/04 - reserve toids 
Rem    kyagoub     04/27/04 - grant execute on sql_plan_xxx to public, create 
Rem                           public synonyms and move drop statements to 
Rem                           catnplan.sql 
Rem    pbelknap    04/20/04 - plan diff types 
Rem    bdagevil    05/08/04 - add other_xml column 
Rem    bdagevil    11/01/03 - all run dbms_xplan 
Rem    bdagevil    06/18/03 - rename hint alias to object_alias
Rem    bdagevil    06/06/03 - hint alias increased in size
Rem    aime        04/25/03 - aime_going_to_main
Rem    bdagevil    02/24/03 - bdagevil_sql_tune_5
Rem    bdagevil    02/13/03 - Created
Rem
create type dbms_xplan_type
as object (plan_table_output varchar2(300));
/
create type dbms_xplan_type_table
as table of dbms_xplan_type;
/
REM necessary for lower privileged users
grant execute on dbms_xplan_type to public;
grant execute on dbms_xplan_type_table to public;  
Rem
Rem Plan object type for plan diffs
Rem   - the sql_plan_table_type is a convenient way to store a handle on an
Rem     entire plan.  The dbms_xplan.compare_query_plans function takes in
Rem     two plans as arguments, so it needs a rolled-up type.  
Rem   - *** Note that these types are used by this function ONLY and should not
Rem         be used in user scripts/tables as they may be changed in the future
Rem
Rem SQL_PLAN_ROW_TYPE, SQL_PLAN_TABLE_TYPE
Rem
Rem  These types mirror the structure of the plan table and are used
Rem  to pass plans into this package for comparing plans.
Rem
Rem  You can populate a nested table of type SQL_PLAN_TABLE_TYPE as follows:
Rem
Rem  select CAST(COLLECT
Rem              (sql_plan_row_type(statement_id,plan_id,timestamp,remarks,
Rem               operation,options,object_node,object_owner,object_name,
Rem               object_alias,object_instance,object_type,optimizer,
Rem               search_columns,id,parent_id,depth,position,cost,
Rem               cardinality,bytes,other_tag,partition_start,
Rem               partition_stop,partition_id,NULL,distribution,cpu_cost,
Rem               io_cost,temp_space,access_predicates,filter_predicates,
Rem               projection,time,qblock_name,other_xml))
Rem         AS SQL_PLAN_TABLE_TYPE)
Rem  from plan_table where plan_id = :plid order by id;
create type sql_plan_row_type 
timestamp '1997-04-12:12:59:00' oid '00000000000000000000000000020210'
as object (
statement_id       varchar2(30),
plan_id            number,
timestamp          date,
remarks            varchar2(4000),
operation          varchar2(30),
options            varchar2(255),
object_node        varchar2(128),
object_owner       varchar2(30),
object_name        varchar2(30),
object_alias       varchar2(65),
object_instance    numeric,
object_type        varchar2(30),
optimizer          varchar2(255),
search_columns     number,
id                 numeric,
parent_id          numeric,
depth              numeric,
position           numeric,
cost               numeric,
cardinality        numeric,
bytes              numeric,
other_tag          varchar2(255),
partition_start    varchar2(255),
partition_stop     varchar2(255),
partition_id       numeric,
distribution       varchar2(30),
cpu_cost           numeric,
io_cost            numeric,
temp_space         numeric,
access_predicates  varchar2(4000),
filter_predicates  varchar2(4000),
projection         varchar2(4000),
time               numeric,
qblock_name        varchar2(30),
other_xml          clob
) NOT FINAL
/
create or replace public synonym sql_plan_row_type for sql_plan_row_type
/
grant execute on sql_plan_row_type to public
/
Rem 
Rem sql_plan_table_type
Rem
create type sql_plan_table_type 
timestamp '1997-04-12:12:59:00' oid '00000000000000000000000000020211'
as table of sql_plan_row_type
/
create or replace public synonym sql_plan_table_type for sql_plan_table_type
/
grant execute on sql_plan_table_type to public
/
Rem
Rem ora_plan_id$: sequence number to uniquely identify explain plans
Rem 
create sequence ora_plan_id_seq$
increment by 1
start with 1
minvalue 1
maxvalue 4294967295
cycle
cache 10
/
Rem
Rem explain plan table
Rem NOTE: the plan table was not upgraded when the other_xml has been added
Rem       in 10.2. This means that upgraded databases to 10.2 or post 10.2
Rem       will not have this column which will invalid all packages and 
Rem       funtionalities which use the column.   
Rem       This is the main reason it is recreated in here. 
drop table plan_table$;
create global temporary table plan_table$
(
statement_id       varchar2(30),
plan_id            number,
timestamp          date,
remarks            varchar2(4000),
operation          varchar2(30),
options            varchar2(255),
object_node        varchar2(128),
object_owner       varchar2(30),
object_name        varchar2(30),
object_alias       varchar2(65),
object_instance    numeric,
object_type        varchar2(30),
optimizer          varchar2(255),
search_columns     number,
id                 numeric,
parent_id          numeric,
depth              numeric,        
position           numeric,
cost               numeric,
cardinality        numeric,
bytes              numeric,
other_tag          varchar2(255),
partition_start    varchar2(255),
partition_stop     varchar2(255),
partition_id       numeric,
other              long,
other_xml          clob,
distribution       varchar2(30),
cpu_cost           numeric,
io_cost            numeric,
temp_space         numeric,
access_predicates  varchar2(4000),
filter_predicates  varchar2(4000),
projection         varchar2(4000),
time               numeric,
qblock_name        varchar2(30)
) on commit preserve rows
/
Rem
Rem Add necessary privileges and make plan_table$ the default for 
Rem everyone
Rem
grant select, insert, update, delete on plan_table$ to public
/
create or replace public synonym plan_table for plan_table$
/
Rem
Rem SQL_PLAN_STAT_ROW_TYPE
Rem
Rem  This type is a sub-type of SQL_PLAN_ROW_TYPE. It is defined 
Rem  to capture the row source statistics associated to a plan. 
Rem
create type sql_plan_stat_row_type 
timestamp '1997-04-12:12:59:00' oid '00000000000000000000000000020212'
under sql_plan_row_type(
executions     NUMBER,
starts         NUMBER,
output_rows    NUMBER,
cr_buffer_gets NUMBER,
cu_buffer_gets NUMBER,
disk_reads     NUMBER,
disk_writes    NUMBER,
elapsed_time   NUMBER
)
/
create or replace public synonym sql_plan_stat_row_type for sql_plan_stat_row_type
/
grant execute on sql_plan_stat_row_type to public
/
Rem
Rem Load explain plan package
Rem
@@dbmsxpln.sql
@@prvtxpln.plb

My Oracle version is this:

> Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
> PL/SQL Release 10.2.0.4.0 - Production CORE 10.2.0.4.0 Production TNS
> for 64-bit Windows: Version 10.2.0.4.0 - Production NLSRTL Version
> 10.2.0.4.0 - Production

How can I fix this issue?

答案1

得分: 1

如果您删除第2行:

timestamp '1997-04-12:12:59:00' oid '00000000000000000000000000020210'

类型将会被创建(在Oracle 10g上测试):

SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
PL/SQL Release 10.2.0.5.0 - Production
CORE    10.2.0.5.0      Production
TNS for Linux: Version 10.2.0.5.0 - Production
NLSRTL Version 10.2.0.5.0 - Production

创建类型:

SQL> create type sql_plan_row_type
2  --timestamp '1997-04-12:12:59:00' oid '00000000000000000000000000020210'
3  as object (
4          statement_id       varchar2(30),
5          plan_id            number,
6          timestamp          date,
7          remarks            varchar2(4000),
8          operation          varchar2(30),
9          options            varchar2(255),
10          object_node        varchar2(128),
11          object_owner       varchar2(30),
12          object_name        varchar2(30),
13          object_alias       varchar2(65),
14          object_instance    number,
15          object_type        varchar2(30),
16          optimizer          varchar2(255),
17          search_columns     number,
18          id                 number,
19          parent_id          number,
20          depth              number,
21          position           number,
22          cost               number,
23          cardinality        number,
24          bytes              number,
25          other_tag          varchar2(255),
26          partition_start    varchar2(255),
27          partition_stop     varchar2(255),
28          partition_id       number,
29          distribution       varchar2(30),
30          cpu_cost           number,
31          io_cost            number,
32          temp_space         number,
33          access_predicates  varchar2(4000),
34          filter_predicates  varchar2(4000),
35          projection         varchar2(4000),
36          time               number,
37          qblock_name        varchar2(30),
38          other_xml          clob
39  ) NOT FINAL
40  /
Type created.
SQL>;

尝试它,看看它的行为如何。

英文:

If you remove the 2nd line:

timestamp '1997-04-12:12:59:00' oid '00000000000000000000000000020210'

type gets created (tested on 10g):

SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
PL/SQL Release 10.2.0.5.0 - Production
CORE    10.2.0.5.0      Production
TNS for Linux: Version 10.2.0.5.0 - Production
NLSRTL Version 10.2.0.5.0 - Production

Create type:

SQL> create type sql_plan_row_type
2  --timestamp '1997-04-12:12:59:00' oid '00000000000000000000000000020210'
3  as object (
4          statement_id       varchar2(30),
5          plan_id            number,
6          timestamp          date,
7          remarks            varchar2(4000),
8          operation          varchar2(30),
9          options            varchar2(255),
10          object_node        varchar2(128),
11          object_owner       varchar2(30),
12          object_name        varchar2(30),
13          object_alias       varchar2(65),
14          object_instance    number,
15          object_type        varchar2(30),
16          optimizer          varchar2(255),
17          search_columns     number,
18          id                 number,
19          parent_id          number,
20          depth              number,
21          position           number,
22          cost               number,
23          cardinality        number,
24          bytes              number,
25          other_tag          varchar2(255),
26          partition_start    varchar2(255),
27          partition_stop     varchar2(255),
28          partition_id       number,
29          distribution       varchar2(30),
30          cpu_cost           number,
31          io_cost            number,
32          temp_space         number,
33          access_predicates  varchar2(4000),
34          filter_predicates  varchar2(4000),
35          projection         varchar2(4000),
36          time               number,
37          qblock_name        varchar2(30),
38          other_xml          clob
39  ) NOT FINAL
40  /
Type created.
SQL>

Try it, see how it behaves.

huangapple
  • 本文由 发表于 2023年2月8日 17:18:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/75383541.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定