Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Convert SQL Server trigger to Oracle

user6248369Jun 28 2018 — edited Jun 28 2018

Hello,

I'm new to SQL Server and need to convert SQL Server Triggers to Oracle. There is no SQL Server version, all I got is files and doing this manually. Need a little help please. Here are the examples of SQL Server triggers that need to be converted to Oracle:

    

Insert trigger - before insert or after in Oracle?

CREATE TRIGGER trigger_name ON dbo.table_name

FOR Insert AS

declare @InsertUser varchar(32)

BEGIN

SELECT @InsertUser = nt_username from master.dbo.sysprocesses where spid = @@spid

Update table_name

SET dCreateDate = GETDATE(), cCreateUser = @InsertUser

FROM table1 a ,table2 i WHERE a.tab_id = i.tab_id

END

GO

Update Trigger - before update or after in Oracle?

CREATE TRIGGER trigger_name ON dbo.table_name
FOR UPDATE AS
declare @UpdateUser varchar(32)
if not update(CreateUser) and not update(CreateDate)
BEGIN
SELECT @UpdateUser = nt_username from master.dbo.sysprocesses where spid = @@spid
Update table_name
SET UpdateDate = GETDATE(), UpdateUser = @UpdateUser
FROM table1 a ,table2 i WHERE a.tab_id = i.tab_id
END
GO

Thank you very much to all.

This post has been answered by L. Fernigrini on Jun 28 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 26 2018
Added on Jun 28 2018
5 comments
366 views