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: sequences

Re: sequences

From: Joel R. Kallman <jkallman_at_us.oracle.com>
Date: Sun, 23 Aug 1998 20:10:48 GMT
Message-ID: <35e0769f.864713@newshost.us.oracle.com>


On Sun, 23 Aug 1998 14:20:01 -0400, "bubba" <brittonb_at_webt.com> wrote:

>I made a sequence for a customers table that is used for the primary key.
>
>When I insert data using an INSERT sql statement, I can use the
>sqncCustomerID.nextval syntax.
>
>However, I have an issue where we are using Access 97 to update some data.
>
>How can I set a trigger so that oracle automatically inserts the next value
>into the primary key?
>
>This is done very easily in MS SQL with the Autonumber data type.
>

This is also done very easily using a trigger in Oracle!

I'm able to get this working with MS Access 97 and Oracle8. I executed the following DDL:

CREATE TABLE foo (id NUMBER, num NUMBER);

CREATE SEQUENCE foo_id_seq;

CREATE OR REPLACE TRIGGER foo_iu BEFORE INSERT ON foo FOR EACH ROW DECLARE
  id NUMBER;
BEGIN
  SELECT foo_id_seq.NEXTVAL INTO id FROM DUAL;   :new.id := id;
END; That's all there is to it. Now, if I perform the following from SQL*Plus:

  INSERT INTO foo (num) VALUES(2000);
  COMMIT; The ID column will be automatically populated with the next value from the sequence.

If I attach this table using MS Access, and I add rows to this table using the DataSheet view and only populate the NUM column, the ID column will automatically be populated with the sequence values.

>Can somebody tell me how to do this in Oracle? I don't want to have to teach
>my users how to write SQL insert statements just to edit and enter some
>simple data.
>
>brittonb_at_webt.com
>
>

BTW....I answered this same question in this same newsgroup on 5/1/1998. Sometime check out the Usenet archive DejaNews at http://www.dejanews.com. Chances are someone has already asked and received an answer to your question.

Hope this helps.
Thanks!

Joel

Joel R. Kallman Oracle Government, Education, & Health

Columbus, OH                             http://govt.us.oracle.com

jkallman@us.oracle.com                   http://www.oracle.com




The statements and opinions expressed here are my own and do not necessarily represent those of Oracle Corporation. Received on Sun Aug 23 1998 - 15:10:48 CDT

Original text of this message

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