【问题标题】:How convert a SQL Server trigger into Oracle trigger?如何将 SQL Server 触发器转换为 Oracle 触发器?
【发布时间】:2019-04-08 10:14:49
【问题描述】:

我正在尝试将 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

【问题讨论】:

标签: sql-server oracle triggers


【解决方案1】:

这样的?

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;
/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-15
    • 1970-01-01
    • 2011-09-11
    • 2013-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多