2

我有一个程序会出现错误“PL/SQL:语句被忽略”。此消息有点模糊,我无法弄清楚为什么我的程序无法编译。所有程序应该做的是检查客户的交货日期是否小于 SYSDATE,如果它被删除,如果没有打印'客户不能被删除'。

该过程的代码在这里:

    CREATE PROCEDURE remove_customer (customer_id VARCHAR2) IS
declare
   ordersCount pls_integer;
BEGIN
   select count(*) into ordersCount 
   from placed_orders 
   where fk1_customer_id = remove_customer.customer_id
   and delivery_date < sysdate;
if ordersCount = 0 then
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;
total_customers := total_customers - 1;
ELSE
DBMS_OUTPUT.PUT_LINE 'Customer currently has a order been delivered';
END IF;
END;

并且错误消息指定 PLS-00103:遇到符号“DECLARE”

感谢您的任何建议。

4

1 回答 1

0

这一行:

IF placed_order.delivery_date < SYSDATE

没有多大意义——你不能使用这样的列(想一想:placed_order 中的哪些行应该与 SYSDATE 进行比较?一个?全部?)。

如果你想检查这个客户是否有一个已经交付的交付,你需要一个额外的 SELECT:

 CREATE PROCEDURE remove_customer (customer_id VARCHAR2) IS       
  ordersCount pls_integer;
 begin
   select count(*) into ordersCount 
   from placed_orders 
   where fk1_customer_id = remove_customer.customer_id
   and delivery_date < sysdate;

   if ordersCount = 0 then
    -- your code for deleting the customer here
   else
    -- raise error, show message, ...
   end if;
于 2013-05-09T10:45:50.787 回答