今天遇到一个奇怪的问题,存储过程的调用序列编译是报错 Error: PLS-00302: component 'SEQUENCE_NAME' must be declared
序列是存在,拿出来可以执行成功,序列加前缀了,最后找到原因了是因为用户下有一个表和用户名同名导致的,这是oracle一个bug 已经修复了影响的版本为PL/SQL - Version: 10.2.0.4 to 11.2.0.3 - Release: 10.2 to 11.2
如下图报错:
解决方法:
Rename/ drop any conflicting object with the same name as the schema name
SELECT OBJECT_NAME, OBJECT_TYPE
FROM ALL_OBJECTS
WHERE OBJECT_NAME='USERNMAME'
原因:
An object exists with the same name as the schema owner causing a pl/sql compilation error.
Bug:1218383 PLS-327 WHEN COMPILE SCHEMA.SEQUENCE WITH EXISTING TABLE WITH SCHEMA NAME
以下在 11.2.0.1.0 的环境重现这个问题
C:\Users\Administrator>sqlplus u1/u1
SQL*Plus: Release 11.2.0.1.0 Production on 星期四 11月 6 16:31:25 2014
Copyright (c) 1982, 2010, Oracle. All rights reserved.
连接到:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
创建序列seq_u1
SQL> create sequence seq_u1
2 minvalue 1
3 maxvalue 9999999
4 start with 1
5 increment by 1
6 cache 5;
序列已创建。
创建和用户名同名的表u1
SQL> create table u1 (id number);
表已创建。
创建存储过程调用序列:
SQL> create or replace procedure next_val is
2 v_next number;
3 begin
4 select u1.seq_u1.Nextval into v_next from dual;
5
6 insert into test values (u1.seq_u1.NEXTVAL);
7 exception
8 when others then
9 null;
10 end next_val;
11 /
警告: 创建的过程带有编译错误。
编译有错误:(问题重现)
SQL> show error
PROCEDURE NEXT_VAL 出现错误:
LINE/COL ERROR
-------- -----------------------------------------------------------------
4/14 PLS-00302: 必须声明 'SEQ_U1' 组件
6/31 PLS-00302: 必须声明 'SEQ_U1' 组件
SQL>
查询与用户名同名的对象:
SQL> SELECT OBJECT_NAME, OBJECT_TYPE
2 FROM ALL_OBJECTS
3 WHERE OBJECT_NAME='U1';
OBJECT_NAME OBJECT_TYPE
------------------------------ -------------------
U1 TABLE
删除同名对象
SQL> drop table u1;
表已删除。
从新编译,编译通过问题解决
SQL> alter procedure next_val compile;
过程已更改。
SQL> show error
没有错误。
SQL>