Home » Developer & Programmer » Forms » Sequence Number
Sequence Number [message #315910] Wed, 23 April 2008 03:19 Go to next message
*munnabhai*
Messages: 157
Registered: March 2008
Location: Riyadh
Senior Member
i have below table
VENDOR_ID NUMBER(15)
VENDOR_NAME NOT NULL VARCHAR2(30)
TELEPHONE VARCHAR2(15)

vendor id is unique

i want to create sequence # on vendor ID how to create sequence and on whic trigger we write code and what code we write. explain me please....


whenever the new record insert it will create sequence #

Regards
Re: Sequence Number [message #315914 is a reply to message #315910] Wed, 23 April 2008 03:57 Go to previous messageGo to next message
Littlefoot
Messages: 21823
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Create a sequence (let's call it MY_SEQ). Create a form. Open VENDOR_ID's Property palette. Under the "Data" node, modify "Initial value" property and put this into it:
:SEQUENCE.MY_SEQ.NEXTVAL
Re: Sequence Number [message #315931 is a reply to message #315910] Wed, 23 April 2008 04:57 Go to previous messageGo to next message
*munnabhai*
Messages: 157
Registered: March 2008
Location: Riyadh
Senior Member
thanks little it works fine

it is creating autonumber continues when this instance everytime

i want this autonumber should create when i insert the record.

Regards


Re: Sequence Number [message #315939 is a reply to message #315931] Wed, 23 April 2008 05:14 Go to previous message
Littlefoot
Messages: 21823
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Create a database trigger, such as
SQL> create table test
  2  (vendor_id   number,
  3   vendor_name varchar2(20),
  4   telephone   varchar2(15)
  5  );

Table created.

SQL>
SQL> create or replace trigger trg_test
  2    before insert on test
  3    for each row
  4  begin
  5    select my_seq.nextval into :new.vendor_id
  6    from dual;
  7  end;
  8  /

Trigger created.

SQL>
SQL> insert into test (vendor_name, telephone) values ('Little', '1234-567');

1 row created.

SQL>
SQL>
SQL> select * From test;

 VENDOR_ID VENDOR_NAME          TELEPHONE
---------- -------------------- ---------------
       142 Little               1234-567

SQL>

In other words, trigger will take care about setting the VENDOR_ID value during insert.

It could be done in one of Forms triggers as well (PRE-INSERT block-level, for example):
select my_seq.nextval into :test.vendor_id
  from dual;
Previous Topic: Calculations
Next Topic: Connecting to different schemas in one menu
Goto Forum:
  


Current Time: Sat Feb 08 16:12:52 CST 2025