创建软件包sqlplus [英] Creating Package sqlplus

查看:145
本文介绍了创建软件包sqlplus的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过以下过程创建软件包

I am trying to create a package from the following procedure

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,

So far this is my package sec which, creates fine

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

但是,当我创建包主体时,出现编译错误,有什么想法吗?

But, when i create the package body, i get compilation errors, any ideas?

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

推荐答案

出现编译错误时,您将希望查看收到的错误.在SQL * Plus中,可以使用命令show errors

When you get compilation errors, you'll want to see what errors you received. In SQL*Plus, you can do that using the command 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).

The errors are telling you that the compiler thinks that the keyword at line 11, column 29 is a column name and that column names aren't allowed at that point in your code. Line 11 column 29 is the pl_loc identifier. Presumably, you didn't intend that to be a reference to a column name. Presumably, you intended that to be the name of a parameter. But Oracle doesn't recognize that identifier as the parameter. This is because your parameter is named p_loc not pl_loc (note the extra l).

如果您更正了所有三个参数的名称,则代码将编译

If you correct the name of all three parameters, the code compiles

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.

这篇关于创建软件包sqlplus的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆