我正在尝试使用以下过程创建一个包
CREATE OR REPLACE PROCEDURE insert_rows
(pl_deptno dept.deptno%TYPE, pl_dname dept.dname%TYPE, pl_loc dept.loc%TYPE
) AS
BEGIN
INSERT INTO dept
(deptno,dname,loc)
values ( pl_deptno,pl_dname,pl_loc);
commit;
end insert_rows;
/
到目前为止,这是我的包装秒,创造了很好的
create or replace package fpf
is
procedure insert_rows
(p_deptno IN dept.deptno%TYPE,
p_dname IN dept.dname%TYPE,
p_loc IN dept.loc%TYPE);
end fpf;
/
但是,当我创建包体时,我会收到编译错误,有什么想法吗?
create or replace package body fpf
as
procedure insert_rows
(p_deptno IN dept.deptno%TYPE,
p_dname IN dept.dname%TYPE,
p_loc IN dept.loc%TYPE)
as
BEGIN
INSERT INTO dept
(deptno,dname,loc)
values ( pl_deptno,pl_dname,pl_loc);
end insert_rows;
end fpf;
/
答案 0 :(得分:5)
当您收到编译错误时,您会希望查看收到的错误。在SQL * Plus中,您可以使用命令show errors
SQL> create or replace package body fpf
2 as
3 procedure insert_rows
4 (p_deptno IN dept.deptno%TYPE,
5 p_dname IN dept.dname%TYPE,
6 p_loc IN dept.loc%TYPE)
7 as
8 BEGIN
9 INSERT INTO dept
10 (deptno,dname,loc)
11 values ( pl_deptno,pl_dname,pl_loc);
12 end insert_rows;
13 end fpf;
14 /
Warning: Package Body created with compilation errors.
SQL> sho err
Errors for PACKAGE BODY FPF:
LINE/COL ERROR
-------- -----------------------------------------------------------------
9/1 PL/SQL: SQL Statement ignored
11/29 PL/SQL: ORA-00984: column not allowed here
错误告诉您编译器认为第11行第29列的关键字是列名,并且代码中的该点不允许使用列名。第11行第29列是pl_loc
标识符。据推测,您并不打算将其作为列名的引用。据推测,您打算将其作为参数的名称。但Oracle不会将该标识符识别为参数。这是因为您的参数名为p_loc
而不是pl_loc
(请注意额外的l
)。
如果更正了所有三个参数的名称,则代码将编译
Wrote file afiedt.buf
1 create or replace package body fpf
2 as
3 procedure insert_rows
4 (p_deptno IN dept.deptno%TYPE,
5 p_dname IN dept.dname%TYPE,
6 p_loc IN dept.loc%TYPE)
7 as
8 BEGIN
9 INSERT INTO dept
10 (deptno,dname,loc)
11 values ( p_deptno,p_dname,p_loc);
12 end insert_rows;
13* end fpf;
SQL> /
Package body created.