触发将值从一个表更新到另一个表

时间:2015-09-30 12:04:31

标签: oracle11g

我正在尝试创建一个触发器,以便从plan_id表中获取db的值,该值已发生超过3次,然后更新amount的值plan_idpreplanpostplan表中(plan_id所属的地方)。

我的表的模式是这样的:

db table:

 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 PLAN_ID                                   NOT NULL NUMBER
 CONNECTION_ID                             NOT NULL NUMBER

preplan:

 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 PLAN_ID                                   NOT NULL NUMBER
 AMOUNT                                             NUMBER

postplan:

     Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 PLAN_ID                                   NOT NULL NUMBER
 AMOUNT                                             NUMBER

我已经为此写了以下触发器:

CREATE OR REPLACE  TRIGGER plan_discount_trigger

AFTER INSERT
   ON db FOR EACH ROW
DECLARE

   l_planid  number(5);
   l_amount  number(5);

BEGIN

 SELECT plan_id from db into l_planid group by plan_id having count(:NEW.plan_id)>3;
    IF (l_planid>0 and l_planid<6) THEN
        select amount into l_amount from preplan;
        update preplan SET prepaid.amount = l_amount - (l_amount * 0.1);

    ELSIF (l_planid>9 and l_planid<16) THEN
        select amount into l_amount from postplan;
        update postplan SET postpaid.amount = l_amount - (l_amount * 0.1);
  ELSE
        dbms_output.put_line("invalid plan!");

    end IF;
end;

给出错误:

8/2      PL/SQL: SQL Statement ignored
8/25     PL/SQL: ORA-00933: SQL command not properly ended

请解释一下错误是什么以及如何解决它?

1 个答案:

答案 0 :(得分:0)

这需要改变

confirm("You wake up to your mother's voice, 'Wake up! I can't believe you slept in this late! You need to get dressed and hurry on down to Professor Oak's Lab! No time for breakfast! Get going!'");

var questionOne = prompt("1. Hurry out of bed, quickly get dressed, and run out the door! 2. Roll out of bed sleepily, manage to put on your clothes, and make a cup of coffee before leaving the house. 3. Grumble back at your mother and go back to sleep." , "Enter 1, 2, or 3.");

if (questionOne === '1')
{
  prompt("You arrive at Professor Oak's lab in a rush, but haven't quite missed the event! It's time to get your first Pokemon! When you meet the Professor he says with a wink, 'Ah yes, it's you! I remember your mother quite well. Wonder woman... Alright, follow me!' You follow Oak into his lab to find 3 Pokeballs on his desk. 'Choose one,' he says with a hand gesture. [1. Left Pokeball. 2. Middle Pokeball. 3. Right Pokeball.]");
}

 SELECT plan_id from db into l_planid group by plan_id having count(:NEW.plan_id)>3;