小弟今天學習了PL/SQL包的創建(包說明在之前已創建成功,包說明和包主體的名稱一樣),包主體的源代碼如下:
create or replace package body my_package
is
function add_stu (
f_id student.id%type,
f_name student.name%type,
f_add student.address%type,
f_sal student.sal%type)
return number
is
only_one exception;
pragma exception_init(only_one,-1);
begin
insert into student values (id,name,address,sal);
if sql%found then
return 1;
end if;
exception
when only_one then
return -1;
when others then
return 0;
end add_stu;
function del_stu (d_stu student.id%type)
return number
is
begin
delete from student where id = d_stu;
if sql%found then
return 1;
else
return 0;
end if;
exception
when others then
return -1;
end del_stu;
procedure query_stu (q_stu in student.id%type)
is
begin
select * into v_stu from student where id = q_stu;
exception
when no_data_found then
dbms_output.put_line('對不起,并沒有'||q_stu||'的部門');
when too_many_rows then
dbms_output.put_line('返回值過多,請使用游標');
when others then
dbms_output.put_line(sqlcode||'====='||sqlerrm);
end query_stu;
begin
null;
end my_package;
/程序執行后,系統提示錯誤,于是小弟使用:“show error”命令查看是什么錯誤,結果系統提示錯誤如下:
PACKAGE BODY MY_PACKAGE 出現錯誤:LINE/COL ERROR
--------  ----------------------------------
13/1      PL/SQL:SQL Statement ignored
13/45     PL/SQL:ORA-00984:列在此外不允許

解决方案 »

  1.   

    這個包中只使用到了一張表:student,它的結構如下:
    SQL> desc student;
     名称                                                                                                                                                                                                                                      是否为空? 类型
     ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------- ------------------------------------------------------------------------------------------------------------------------------------------------------------
     ID                                                                                                                                                                                                                                        NOT NULL NUMBER(38)
     NAME                                                                                                                                                                                                                                               VARCHAR2(10)
     ADDRESS                                                                                                                                                                                                                                            VARCHAR2(15)
     SAL                                                                                                                                                                                                                                                NUMBER