Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trigger

Status
Not open for further replies.

Daft69

Programmer
Nov 28, 2001
9
BE
Hi,

I must do a auto number increse but I don't know how to do that !

I explain : I have a field : ID who is a number and when I make an insertion, I don't put any ID in the request but oracle take the max and add 1 !

I hope it's clear, I know that my english is not very good but I need help !!

Bye
 
If I've understood you correctly, you need to use a sequence there.
 
sequence ??

I don't know anything in trigger ! Can you explain more please ?
 
A sequence is a database object that generates numbers. Every time you do an insert, your code (be it a procedure or trigger) goes to the sequence for the next number:

CREATE SEQUENCE my_seq;

INSERT INTO my_table VALUES(my_seq.NEXTVAL, data_for_column_1,......);

Be advised that there may be breaks in your sequences; that is, there can be gaps in your numbers due to things like rollbacks, system failures, etc. If this is a problem (that is, if you have to account for every number), then your trigger/procedure will need to find the current high number and then increment it:

SELECT max(id_number) INTO max_num FROM my_table;
INSERT INTO my_table VALUES (max_num+1, data_for_column_1...);

This is relatively expensive in terms of resources and time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top