gpt4 book ai didi

oracle11g - 创建包 sqlplus

转载 作者:行者123 更新时间:2023-12-02 23:36:39 24 4
gpt4 key购买 nike

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

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

最佳答案

当您遇到编译错误时,您需要查看收到的错误。在 SQL*Plus 中,您可以使用命令 showerrors

来做到这一点
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.

关于oracle11g - 创建包 sqlplus,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15732150/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com