简体   繁体   中英

DB2 equivalent of SQL Server's TRIGGER_NESTLEVEL()?

I'm trying to get control of a recursive trigger over DB2 (v9.7), unfortunately IBM documentation doesn't mention a way to know at which level of recursion the current trigger call is in.

I've found that there's this function on sql-server: trigger_nestlevel() , it basically does what I want (knowing the actual trigger recursive call level). so I would like to know if there is an equivalent function in DB2.

Unfortunately DB2 does NOT have any function or stored procedure for this. You can have maximum of 16 trigger cascade levels.

It is hard coded and can not be changed.

BTW in DB2, if a trigger causes another trigger to be fired, it is called trigger cascade. And you can avoid cascading by NO CASCADE keyword.

If you want to avoid the call to same trigger, there is a workaround:

  1. Create a view for your table => Create View vTable1 as Select * from Table1
  2. Create an INSTEAD OF TRIGGER for vTable1. => CREATE TRIGGER TRG_INSERT INSTEAD OF INSERT ON vTable1
  3. In TRG_INSERT, to insert into to table1.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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