繁体   English   中英

如何将 SQL Server 触发器转换为 Oracle 触发器?

[英]How convert a SQL Server trigger into Oracle trigger?

我正在尝试将 SQL Server 触发器转换为 Oracle 触发器,这个触发器是关于如果我销售产品并且产品数量为 0 则必须取消销售,但 oracle 的 sintaxis 有点不同。

这是 SQL Server 版本

create trigger IfQuantityIsZero on Products for update 
as 
IF (SELECT Quantity FROM INSERTED) < 0 BEGIN
    RAISERROR ('The sale can not be made, it exceeds the existing quantity of the product.',10,1)
ROLLBACK TRANSACTION
END

像这样的东西?

CREATE OR REPLACE TRIGGER ifquantityiszero BEFORE
     UPDATE  --OR INSERT 
   ON products FOR EACH ROW
BEGIN
     IF
          :NEW.quantity < 1 --refer to the modified columns in products using :NEW.column
     THEN
          RAISE_APPLICATION_ERROR(-20000,'The sale can not be made, it exceeds the existing quantity of the product.'
          );

     END IF;
END;
/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM