我目前有一个删除客户的程序,这是一个位于包体内的相当简单的程序。以下是运行和删除客户的过程的代码:
PROCEDURE remove_customer (customer_id VARCHAR2) IS
BEGIN
DELETE FROM order_line
WHERE order_line.FK1_order_id in
(SELECT order_id FROM placed_order
WHERE placed_order.FK1_customer_id = remove_customer.customer_id
);
DELETE FROM placed_order
WHERE placed_order.FK1_customer_id = remove_customer.customer_id;
DELETE FROM customer
WHERE customer.customer_id = remove_customer.customer_id;
total_customers := total_customers - 1;
END;
我想要的是仅在交货日期已过时删除该客户?所以在上面的过程中会有一个 if 语句我只是不确定如何在哪里以及如何添加它。
这将是沿着
CREATE PROCEDURE remove_customertest (customer_id VARCHAR2) IS
BEGIN
IF placed_order.delivery_date < SYSDATE
THEN
DELETE FROM order_line
WHERE order_line.FK1_order_id in
(SELECT order_id FROM placed_order
WHERE placed_order.FK1_customer_id = remove_customer.customer_id
);
DELETE FROM placed_order
WHERE placed_order.FK1_customer_id = remove_customer.customer_id;
DELETE FROM customer
WHERE customer.customer_id = remove_customer.customer_id;
ELSE
DBMS_OUTPUT.PUT_LINE ('Customer currently has a order been delivered and cant be removed.');
END IF;
END;
有没有人对此有任何建议,或者我是否在正确的路线上?
感谢您的帮助,我对 PL/SQL 还很陌生