我的触发器不打印我想要的东西

时间:2013-12-12 00:55:33

标签: sql oracle debugging

所以我是一名在Oracle SQL工作的学生,我写了一个触发器,通知我项目数量是否低于某个值。我的触发器是在没有编译错误的情况下创建的,但是当我测试它时,我看不到我想要的输出...我相信可能有更好的方法来做这个部分,但我主要关心的是如何让它打印到命令行。如果可能的话,我希望第一个if语句包含一个break语句,以便数量不能小于0.这是由addint'BREAK;'完成的。在'END IF;'之前?

SQL> @345lowqtytrigger
SQL> CREATE OR REPLACE TRIGGER low_qty_trigger
  2  BEFORE INSERT OR UPDATE OF vnd_itm_qty ON Vending_Machine_Item
  3  FOR EACH ROW
  4  DECLARE
  5  tempstr varchar2(1000);
  6  name varchar2(1000);
  7  vndadd varchar2(1000);
  8  tempint int;
 9  cursor itm_des_cursor is
 10  SELECT itm_des FROM item WHERE itm_id = item.itm_id;
 11  cursor vnd_addr_cursor is
 12  SELECT vnd_addr FROM Vending_Machine WHERE vnd_id = Vending_Machine.vnd_id;
 13  BEGIN
 14          open itm_des_cursor;
 15          fetch itm_des_cursor into name;
 16          open vnd_addr_cursor;
 17          fetch vnd_addr_cursor into vndadd;
 18          IF :NEW.vnd_itm_qty < 0 THEN
 19          tempstr := concat(:new.vnd_id,concat(' can not have less than 0 quantity for ',name));
 20          dbms_output.put_line(tempstr);
 21  end if;
 22  tempint := :new.vnd_itm_qty_max*.15;
 23          IF
 24          :NEW.vnd_itm_qty <= tempint
 25          and
 26          :NEW.vnd_itm_qty >= 0
 27          THEN
 28          tempstr := concat('There will be less than ',
 29  concat(to_char(tempint),
 30  concat(' of ',
 31  concat(name,
 32  concat(' in Vending Machine ',
 33  concat(to_char(:new.vnd_id),
 34  concat(' located at ',vndadd)))))));
 35  dbms_output.put_line(tempstr);
 36  END IF;
 37  close itm_des_cursor;
 38  close vnd_addr_cursor;
 39  END;
 40  /

Trigger created.

SQL> SET ECHO OFF;
No errors.
SQL> spool off;

TEST CASE

SQL> update vending_machine_item set vnd_itm_qty = 1 where vnd_id = 956 and itm_id = 193;


1 row updated.

1 个答案:

答案 0 :(得分:2)

你是如何测试的?它必须在交互式会话中才能查看dbms_output生成的任何输出。尝试使用set serveroutput on.

从sql * plus会话更新vending_machine_item