Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
327 views
in Technique[技术] by (71.8m points)

oracle - 删除客户的步骤(Procedure to delete a customer)

I have the following procedure, which is supposed to delete a specific customer.

(我有以下步骤,应该删除特定的客户。)

I keep getting errors, and I am not sure why.

(我不断收到错误,我不确定为什么。)

I am new to this and this is a class homework.

(我是新来的,这是课堂作业。)

Thanks in advance for your help:

(在此先感谢您的帮助:)

CREATE or REPLACE PROCEDURE DISP_CUST_DELETE (I_CUSTOMER_NUM IN CUSTOMER_NUM&TYPE)

BEGIN 
    DELETE
    FROM  CUSTOMER
    WHERE CUSTOMER_NUM = I_CUSTOMER_NUM;

    dbms_output.put_line('Customer has been deleted');

EXCEPTION
    WHEN NO_DATA_FOUND THEN
        dbms_output.put_line('NO CUSTOMER WITH this number has been deleted');
END;
/

Here is a little update.

(这是一个小更新。)
Yes, sorry that is what I meant.

(是的,对不起,这就是我的意思。)

Here is the updated procedure.

(这是更新的过程。)

CREATE or REPLACE PROCEDURE DISP_CUST_DELETE (I_CUSTOMER_NUM IN CUSTOMER.CUSTOMER_NUM) AS

BEGIN 
    DELETE
    FROM CUSTOMER
    WHERE CUSTOMER_NUM = I_CUSTOMER_NUM;

    dbms_output.put_line('Customer' || I_CUSTOMER_NUM ||'has been deleted');

EXCEPTION
    WHEN NO_DATA_FOUND THEN
        dbms_output.put_line('NO CUSTOMER WITH'||I_CUSTOMER_NUM||'has been deleted');
END;
/

And here is the error I am getting:

(这是我得到的错误:)

0/0 PL/SQL: Compilation unit analysis terminated 1/47

(0/0 PL / SQL:编译单元分析已终止1/47)
PLS-00488: 'CUSTOMER.CUSTOMER_NUM' must be a type

(PLS-00488:“ CUSTOMER.CUSTOMER_NUM”必须为类型)

  ask by Alan translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Like @sticky bit suggested in the comments, you have a syntax error on your code.

(就像@sticky bit建议的@sticky bit一样,您的代码也存在语法错误。)

In order for you to declare a variable to be the same type as a previously declared variable or a column of a table you should use table.table_column%TYPE .

(为了使您声明的变量与先前声明的变量或表的列具有相同的类型,应使用table.table_column%TYPE 。)

CREATE or REPLACE PROCEDURE DISP_CUST_DELETE (
    I_CUSTOMER_NUM IN CUSTOMER.CUSTOMER_NUM%TYPE   --> This line here
) AS

BEGIN 
    DELETE
    FROM CUSTOMER
    WHERE CUSTOMER_NUM = I_CUSTOMER_NUM;

    dbms_output.put_line('Customer' || I_CUSTOMER_NUM ||'has been deleted');

    EXCEPTION
        WHEN NO_DATA_FOUND THEN
            dbms_output.put_line('NO CUSTOMER WITH'||I_CUSTOMER_NUM||'has been deleted');
END;
/

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...