1

I am trying to run some PL/SQL code but it contains some errors about identifiers plese help me with it. The code is not running

DECLARE
   a := customer.purchase%TYPE;
   id := &employee.empno;
BEGIN
   UPDATE employee SET salary = salary + 5000;
   UPDATE employee SET bonus = bonus + 1000 WHERE empno = &id;
   SAVEPOINT sumeet;
   UPDATE customer SET purchase = purchase + 5000 WHERE custid = a;

   SELECT SUM(purchase) INTO a;

   IF (a < 11000) THEN
      ROLLBACK sumeet;
   END IF;
   COMMIT;

END;
/
4

4 回答 4

1

1:这是错误的:

DECLARE
  a := customer.purchase%TYPE;
  id := &employee.empno;

你没有:=在变量名后面放a,&是无效的,并且employee.empno不是有效的数据类型。IE:

DECLARE
  a customer.purchase%TYPE;
  id employee.empno%TYPE;

2:不需要&引用 id 变量:

UPDATE employee SET bonus = bonus + 1000 WHERE empno = &id;

IE:

UPDATE employee SET bonus = bonus + 1000 WHERE empno = id;
于 2013-01-24T06:50:05.177 回答
1

除了 Alen 的修复,而ROLLBACK不是你为什么不这样做:

   UPDATE customer SET purchase = purchase + 5000 
    WHERE custid = a
      AND (select sum(purchase) from customer) + 5000 < 11000;

  COMMIT;
于 2013-01-14T10:07:44.583 回答
0

Here's a tip: Combine your two updates on employee into one.

 UPDATE employee
 SET    salary = salary + 5000,
        bonus  = bonus  + case when empno = &id then 1000 else 0 end;

Also, start using meaningful variable names.

于 2013-01-24T10:22:12.550 回答
0

尝试使用此块,但首先更改声明块中的值 (1, 2)。

DECLARE
   a customer.purchase%TYPE := 1;
   id employee.empno%TYPE := 2;
BEGIN
   UPDATE employee SET salary = salary + 5000;
   UPDATE employee SET bonus = bonus + 1000 WHERE empno = id;
   SAVEPOINT sumeet;
   UPDATE customer SET purchase = purchase + 5000 WHERE custid = a;

   SELECT SUM(purchase) INTO a FROM customer;

   IF (a < 11000) THEN
      ROLLBACK sumeet;
   END IF;
   COMMIT;

END;
/
于 2013-01-14T09:22:23.377 回答