![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
|
Hallo, is there a solution to reset a sequence inside a trigger? I wanted to use this procedure: #################### CREATE OR REPLACE PROCEDURE reset_sequence (sequencename IN VARCHAR2) as curr_val INTEGER; BEGIN EXECUTE IMMEDIATE 'alter sequence ' ||sequencename||' MINVALUE 0'; EXECUTE IMMEDIATE 'SELECT ' ||sequencename ||'.nextval FROM dual' INTO curr_val; EXECUTE IMMEDIATE 'alter sequence ' ||sequencename||' increment by -'||curr_val; EXECUTE IMMEDIATE 'SELECT ' ||sequencename ||'.nextval FROM dual' INTO curr_val; EXECUTE IMMEDIATE 'alter sequence ' ||sequencename||' increment by 1'; END reset_sequence; / ##################### but the when I call the 'before insert' or 'after delete' trigger I get the message: --> Commit is not allowed inside a trigger. Thank you, Werner |
#4
| |||
| |||
|
|
1) Lookup usage for pragma autonomous_transaction at http://tahiti.oracle.com 2) What's the point of using a sequence when you are going to reset it everytime you insert/delete a row? Regards /Rauf |
#5
| |||
| |||
|
|
Hallo, is there a solution to reset a sequence inside a trigger? I wanted to use this procedure: #################### CREATE OR REPLACE PROCEDURE reset_sequence (sequencename IN VARCHAR2) as curr_val INTEGER; BEGIN EXECUTE IMMEDIATE 'alter sequence ' ||sequencename||' MINVALUE 0'; EXECUTE IMMEDIATE 'SELECT ' ||sequencename ||'.nextval FROM dual' INTO curr_val; EXECUTE IMMEDIATE 'alter sequence ' ||sequencename||' increment by -'||curr_val; EXECUTE IMMEDIATE 'SELECT ' ||sequencename ||'.nextval FROM dual' INTO curr_val; EXECUTE IMMEDIATE 'alter sequence ' ||sequencename||' increment by 1'; END reset_sequence; / ##################### but the when I call the 'before insert' or 'after delete' trigger I get the message: --> Commit is not allowed inside a trigger. Thank you, Werner |
#6
| |||
| |||
|
|
Stupid question maybe but why reset it? A sequence is a large number. Are you try to save numbers? You can set a max value and then cycle it. Resetting a sequence just seems like you're going about solving the wrong problem. Thanks, Lewis |
#7
| |||
| |||
|
|
Stupid question maybe but why reset it? A sequence is a large number. Are you try to save numbers? You can set a max value and then cycle it. Resetting a sequence just seems like you're going about solving the wrong problem. Thanks, Lewis In this table I have a lot of transactions, and it can be, that the ID which is the primary key can overrun after some time (some years). I can not use another primary key, because this would be with a VARCHAR2 column. And so I wantet to be save, that the oldest entry have the smallest ID for sorting. Werner Look at global temporary tables. This will probably do what you want very |
#8
| |||
| |||
|
#9
| |||
| |||
|
|
1) Lookup usage for pragma autonomous_transaction at http://tahiti.oracle.com 2) What's the point of using a sequence when you are going to reset it everytime you insert/delete a row? Regards /Rauf |
#10
| |||
| |||
|
|
1) Lookup usage for pragma autonomous_transaction at http://tahiti.oracle.com 2) What's the point of using a sequence when you are going to reset it everytime you insert/delete a row? Regards /Rauf Hallo Rauf, I don't reset the sequence every time the trigger is called, but I have some code, which is automatically cleaning the content of the table. And in the case the cleaner has deleted all rows, then I wanted to reset the trigger. In the firebird database I can reset the Generator(sequence) - no problem, but oracle won't like my idea. So, if 1) is not my solution, in last consequence I habe to reset the sequence outside the trigger anywhere in the code. Thank you, Werner You don't reset the trigger, you reset the sequence. |
![]() |
| Thread Tools | |
| Display Modes | |
| |