问题
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.
回答1:
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:
- Create a view for your table => Create View vTable1 as Select * from Table1
- Create an INSTEAD OF TRIGGER for vTable1. => CREATE TRIGGER TRG_INSERT INSTEAD OF INSERT ON vTable1
- In TRG_INSERT, to insert into to table1.
来源:https://stackoverflow.com/questions/13845776/db2-equivalent-of-sql-servers-trigger-nestlevel