| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> c.d.o.server -> Re: Oracle Primary key and Delphi: How to insert the primary key value automatically ?
Sorry i missed the original thread !
create a trigger as mentioned earlier or better yet write it like this (he will fill the primary key only when needed)
create trigger trg_yourtab
before insert
on yourtab
for each row
begin
if (:new.yourprimarykeycolumn is null) then
select yoursequence.nextval into
:new.yourprimarykeycolumn from dual;
end if;
exception
when others then
raise_application_error(errno, errmsg);
end;
This way it is possible to fill the key from the front-end app when needed (i.e. if this table is a master and you need to supply the new key as a foreign key to eventually inserted details in the same context).
to get the next sequence i use tqueries in delphi which i wrapped into
a delphi component.
In general i do it like this:
function GetSeq(const tablename : string) : double; begin
with myquery do
begin
SQL.Clear;
SQL.Add('select seq_' + tablename + '.nextval newseq
from dual');
Open;
result := FieldByName('newseq').AsFloat;
close;
end;
On Mon, 22 Sep 1997 16:11:18 +0100, Ken Nichols <knichols_at_mcsilo.ilo.dec.com> wrote:
>gmjotten_at_worldonline.nl
Christian Kaas
Client/Server development and consulting
Fax. 49-9129-5518
Phone 49-9129-5508
Received on Wed Sep 24 1997 - 00:00:00 CDT
![]() |
![]() |