我创建了一个包,其中包含一个程序,用于从country_ID
不存在的表中删除任何国家/地区。我写了这段代码:
CREATE PACKAGE cust_sa AS
PROCEDURE del_cn3(c_cntry_id COUNTRIES.COUNTRY_ID%TYPE)
IS
v_error_code NUMBER;
BEGIN
DELETE from countries WHERE country_id =c_cntry_id;
IF SQL%NOTFOUND THEN
DBMS_OUTPUT.PUT_LINE('No such record');
END IF;
EXCEPTION WHEN OTHERS THEN
v_error_code :=SQLCODE;
IF v_error_code =-2292 THEN
RAISE_APPLICATION_ERROR(-20004,'Organization ' ||
TO_CHAR(c_cntry_id) ||
' site details defined for it.');
END IF;
END del_cn3;
END cust_sa;
/
但是,在创建此程序包时出现以下两个错误:
(第4行)当期待其中一个时遇到符号V_ERROR_CODE 以下:语言
(最后一行)遇到符号CUST_SA 期待以下之一时:;
为什么会出现错误以及如何解决错误?
答案 0 :(得分:0)
你应该在规范和正文上拆分你的代码:
CREATE OR REPLACE PACKAGE cust_sa AS
PROCEDURE del_cn3(c_cntry_id COUNTRIES.COUNTRY_ID%TYPE);
END cust_sa;
/
CREATE OR REPLACE PACKAGE BODY cust_sa AS
PROCEDURE del_cn3(c_cntry_id COUNTRIES.COUNTRY_ID%TYPE) IS
v_error_code NUMBER;
BEGIN
DELETE FROM clients WHERE country_id = c_cntry_id;
IF SQL%NOTFOUND THEN
dbms_output.put_line('No such record');
END IF;
EXCEPTION WHEN OTHERS THEN
v_error_code := SQLCODE;
IF v_error_code = -2292 THEN
raise_application_error(-20004, 'Organization ' || to_char(c_cntry_id) || ' ...');
END IF;
END del_cn3;
END cust_sa;
/
答案 1 :(得分:0)
We should always foolow some old school defined steps before creating Packages
1) Create Package Specs
2) Create Package Body.
CREATE OR REPLACE PACKAGE cust_sa
AS
PROCEDURE del_cn3(
c_cntry_id IN EMP.EMPNO%TYPE);
END cust_sa;
CREATE OR REPLACE PACKAGE BODY cust_sa
AS
PROCEDURE del_cn3(
c_cntry_id IN EMP.EMPNO%TYPE)
IS
v_error_code NUMBER;
BEGIN
DELETE FROM EMP WHERE EMPNO =c_cntry_id;
IF SQL%NOTFOUND THEN
DBMS_OUTPUT.PUT_LINE('No such record');
END IF;
EXCEPTION
WHEN OTHERS THEN
v_error_code :=SQLCODE;
IF v_error_code = -2292 THEN
RAISE_APPLICATION_ERROR(-20004,'Organization ' || TO_CHAR(c_cntry_id) || ' site details defined for it.');
END IF;
END del_cn3;
END cust_sa;