Oracle向Sql Server转换触发器

时间:2017-10-25 06:37:48

标签: sql-server oracle

我是新的sql server我需要转换我在oracle中的sql server中的触发器,请帮助我尝试但是失败了。

Create or replace
Trigger AD_JOB_SCHEDULE BEFORE
    INSERT ON JOB_SCHEDULE FOR EACH row BEGIN
    if :new.ACCOUNT_SYSTEM_CODE is null
    Then
    :new.BATCH_TYPE:='POLICY_NIGHT';
    ELSEif :new.ACCOUNT_SYSTEM_CODE  is not null then
    :new.BATCH_TYPE:='ACCOUNT_NIGHT';
    END if;
END;    

以上是我的触发器。

以下是我的尝试

 CREATE TRIGGER AD_JOB_SCHEDULE 
   ON  JOB_SCHEDULE 
   AFTER INSERT,UPDATE
AS 
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for trigger here

    declare @value varchar(200)

    select @value=ACCOUNT_SYSTEM_CODE from inserted

    if @value is not null
    begin
        update JOB_SCHEDULE 
        set BATCH_TYPE='ACCOUNT_NIGHT'
        where ACCOUNT_SYSTEM_CODE is not null
    end
    else
    begin
        update JOB_SCHEDULE 
        set BATCH_TYPE='POLICY_NIGHT'
        where ACCOUNT_SYSTEM_CODE is  null
    end
END
GO

这是我的完整代码实际上我只是想知道它是否会起作用,因为我没有这个场景,我只需编写代码并交付。

0 个答案:

没有答案