Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Oracle Primary key and Delphi: How to insert the primary key value automatically ?

Re: Oracle Primary key and Delphi: How to insert the primary key value automatically ?

From: Christian Kaas <c.kaas_at_odn.de>
Date: 1997/09/24
Message-ID: <3429628f.578453@news.nuernberg.odn.de>#1/1

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;

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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US