| |
| How to use Oracle Sequences |
 |
December 8, 1997
This section does not discuss the purpose of sequences as such. If you don't know what
it's for, read some Oracle documentation.
In many cases it's not necessary to bother with sequences in the client progam. Many
programmers prefer to use insert triggers on the tables themselves, and thus not have
to worry about primary key constraints. But there are certainly cases where it's much
more practical to pass the sequence number back to the client program: If you're inserting
rows in several tables with foreign key references you could get the primary keys from
sequences to use in the rows that need these references. But again: We're moving into the
area of religion now, so reason does not always apply:)
The way to get a sequence value is straightforward:
select myseq.nextval from dual
In my programs I usually keep a few dummy queries, so the code looks something like:
...
with DataModule1.Dummy do begin
sql.clear;
sql.add('select myseq.nextval from dual');
open;
PrimaryKey:=Fields[0].asInteger;
close;
end;
|
|
| Hits/month |
2,500,000+ |
Downloads (Since May 2000) |
7,393,709 |
| Total Files |
6,023 |
| Forum msgs |
7,670 |
| Articles/FAQs |
70+/900+ |
Top Selling Software at Amazon
|