如何解决此错误
create or replace package pg1
as
procedure p1(p_deptno in number);
type t is table of emp%rowtype
index by binary_integer;
end pg1;
create or replace package body pg1
as
procedure p1(p_deptno in number)
as
v_emp t;
v_dep exception;
begin
begin
select * bulk collect into v_emp from emp where deptno=p_deptno;
if p_deptno=10 then
raise v_dep;
end if;
for i in v_emp.first..v_emp.last
loop
insert into pg values(v_emp(i).empno, v_emp(i).ename, v_emp(i).job, v_emp(i).mgr, v_emp(i).hiredate, v_emp(i).sal, v_emp(i).comm, v_emp(i).deptno);
end loop;
exception
when v_dep then
raise_application_error(-20200,'my exception raised');
raise value_error;
end
when value_error then/*here getting error*/
dbms_output.put_line('value error');
end;
end p1;
end pg1;
end;
23/1 PLS-00103:在期待时遇到符号“WHEN” 的 下列: ;
答案 0 :(得分:0)
首先总是尝试评估oracle抛出的错误。在大多数情况下,Oracle错误都是非常具有描述性的。如果你仔细看,它总是指向确切的行号。希望你下次尝试调试:)
CREATE OR REPLACE PACKAGE pg1
AS
PROCEDURE p1(
p_deptno IN NUMBER);
type t
IS
TABLE OF emp%rowtype INDEX BY binary_integer;
END pg1;
CREATE OR REPLACE PACKAGE body pg1
AS
PROCEDURE p1(
p_deptno IN NUMBER)
AS
v_emp t;
v_dep EXCEPTION;
BEGIN
BEGIN
SELECT * bulk collect INTO v_emp FROM emp WHERE deptno=p_deptno;
IF p_deptno=10 THEN
raise v_dep;
END IF;
FOR i IN v_emp.first..v_emp.last
LOOP
INSERT
INTO pg VALUES
(
v_emp(i).empno,
v_emp(i).ename,
v_emp(i).job,
v_emp(i).mgr,
v_emp(i).hiredate,
v_emp(i).sal,
v_emp(i).comm,
v_emp(i).deptno
);
END LOOP;
EXCEPTION
WHEN v_dep THEN
raise_application_error(-20200,'my exception raised');
raise value_error;
END; -- Missed semi colon here
WHEN value_error THEN
dbms_output.put_line('value error');
END;
END p1;
END pg1;
END;