Results 1 to 4 of 4

Thread: Autonumber.

  1. #1
    Join Date
    Dec 2003
    Posts
    76

    Unanswered: Autonumber.

    Hi,

    In my application I hve one issue that I wouldappreciate any kind of you

    I have an application, which uses an Oracle Database and I need to create an Autonumber column (COD_Customer) in Table Customer, for example.
    I have a Sequence named SEQ_Customer.

    I would like to use the Sequence, but not integrated in the application (C#) code in the Insert statement. Instead, I want to use it to populate the COD_Customer but only at Database level.
    I think that I might use the BEFORE_INSERT trigger, but I would not know if it works.
    Does the BEFORE_INSERT trigger inserts the SEQ_Customer.NEXTVAL in the right record that I'm about to insert?

    Thanks!

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    >Does the BEFORE_INSERT trigger inserts the SEQ_Customer.NEXTVAL in the right record that I'm about to insert?
    unless & until you post the code for this trigger, we have no idea what occurs inside this trigger.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Yes, BEFORE INSERT would do it. Here's an example (so that you'd get the idea):
    Code:
    SQL> desc test
     Name                          Null?    Type
     ----------------------------- -------- --------------------
     ID                                     NUMBER
     MY_NAME                                VARCHAR2(20)
    
    SQL> create or replace trigger trg_bi_test
      2    before insert on test
      3    for each row
      4  begin
      5    select seq_id.nextval into :new.id from dual;
      6  end;
      7  /
    
    Trigger created.
    
    SQL> insert into test (my_name) values ('Little');
    
    1 row created.
    
    SQL> insert into test (my_name) values ('Foot');
    
    1 row created.
    
    SQL> insert all
      2    into test (my_name) values ('Ana')
      3    into test (my_name) values ('Cedent')
      4    into test (my_name) values ('aucrun')
      5  select * from dual;
    
    3 rows created.
    
    SQL> select * from test;
    
            ID MY_NAME
    ---------- --------------------
             3 Little
             4 Foot
             5 Ana
             6 Cedent
             7 aucrun
    
    SQL>

  4. #4
    Join Date
    Dec 2003
    Posts
    76
    @LitleFoof

    Thanks a lot for your example, because it was exactly what I was asking and make me understand it.

    Thanks to anacedent too.

    I wish both of you, aGOOD 2011!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •