3

我正在尝试从以下过程创建一个包

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;
/

到目前为止,这是我的包 sec,它创建得很好

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;
/
4

1 回答 1

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_locpl_loc请注意 extra 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.
于 2013-04-01T01:24:00.080 回答