473,398 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Need help on the Oracle Sequence Number

Ken
I got an Access database that need to be converted to Oracle 9i.
Somehow the Trigger we created to simulate the "AUTO NUMBER" on Access
could not create the sequence number as soon as the value has been
inserted. The sequence number can only be created after we go to the
second line. Please see the trigger below.

Is there anyway we could create a trigger that could create the
sequence number as soon as we enter a value? It should be very
similar to the "Auto Number" on Access, or "Identity Seed" on SQL
Server.

----------------------------------------------------------
1. sequence SNP.SECTION_ID_SQ:

CREATE SEQUENCE SNP.SECTION_ID_SQ
START WITH 1
INCREMENT BY 1
NOMINVALUE
NOMAXVALUE
NOCYCLE
CACHE 20
NOORDER
/
GRANT SELECT ON SNP.SECTION_ID_SQ TO "PUBLIC"
/

2. Trigger SNP.SNP001_T_I_GET_NEXT_SECTION_ID:

CREATE OR REPLACE TRIGGER SNP.SNP001_T_I_GET_NEXT_SECTION_ID
BEFORE INSERT
ON SNP.SNP001_SECTION
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW WHEN (new.section_id IS NULL)
BEGIN
SELECT section_id_sq.nextval
INTO :new.section_id
FROM dual;
END;
Nov 13 '05 #1
2 2498
Ken wrote:
Is there anyway we could create a trigger that could create the
sequence number as soon as we enter a value? It should be very
similar to the "Auto Number" on Access, or "Identity Seed" on SQL
Server.


No. You'd get the same behavior in SQL Server too, you might appreciate
the fact that the server cannot generate a number until you ask it to,
unless you save the record after entering the first bit of data (not
practical if you have required columns) then the first time you contact
the server about that record is when you've finished with it. Do what
everyone else does and re-design your front end to cope. You shouldn't
be *that* interested in the number that's been generated anyway.

Some groups dropped, FFS Ken, c.d.o.marketplace? You after a job?

--
This sig left intentionally blank
Nov 13 '05 #2
On 2 Dec 2004, kl*****@gmail.com wrote:
I got an Access database that need to be converted to Oracle
9i. Somehow the Trigger we created to simulate the "AUTO
NUMBER" on Access could not create the sequence number as soon
as the value has been inserted. The sequence number can only
be created after we go to the second line. Please see the
trigger below.

Is there anyway we could create a trigger that could create the
sequence number as soon as we enter a value? It should be very
similar to the "Auto Number" on Access, or "Identity Seed" on
SQL Server.

----------------------------------------------------------
1. sequence SNP.SECTION_ID_SQ:

CREATE SEQUENCE SNP.SECTION_ID_SQ
START WITH 1
INCREMENT BY 1
NOMINVALUE
NOMAXVALUE
NOCYCLE
CACHE 20
NOORDER
/
GRANT SELECT ON SNP.SECTION_ID_SQ TO "PUBLIC"
/

2. Trigger SNP.SNP001_T_I_GET_NEXT_SECTION_ID:

CREATE OR REPLACE TRIGGER SNP.SNP001_T_I_GET_NEXT_SECTION_ID
BEFORE INSERT
ON SNP.SNP001_SECTION
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW WHEN (new.section_id IS NULL)
BEGIN
SELECT section_id_sq.nextval
INTO :new.section_id
FROM dual;
END;


No, the best you can do is put section_id_sq.nextval within your
insert statement.

--
Galen Boyer
Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Philip D Heady | last post by:
Ok I'm a newbie to using Oracle9i w/ PHP, been a MySQL guy... What is the proper sql statement to use insert tables, etc. as below.? I don't know much about how OciParse works. I can connect...
1
by: Phil Hindmoor | last post by:
Hi, I am sure if anyone can help me, you guys can! I am an Informix Developer, moving to Oracle 8i and later databases. I am struggling to find the Oracle equivelant to many of the useful...
2
by: Ryan Wagner | last post by:
I am doing many SQL insert statements to insert records into an oracle database. I need the order of the records, after inserting all records, to be the same as the order I inserted them in. Right...
1
by: Mike Landis | last post by:
Hello, Has anyone a small tool or somekind of document which could help me to convert Oracle SQL scripts to SQL Server? Scripts are not very Oracle specified. Thanks, Below is a Script...
1
by: Ken | last post by:
I got an Access database that need to be converted to Oracle 9i. Somehow the Trigger we created to simulate the "AUTO NUMBER" on Access could not create the sequence number as soon as the value has...
4
by: dhcomcast | last post by:
We're starting to use Oracle for the back-end instead of a separate Access .mdb file for the data and everything as gone surprisingly well so far. We are learning Oracle as we go; Yikes! But we...
14
by: ruediger.michels | last post by:
hi, 1. is there a statement in ms sql, what creates a sequence? cant find anything in web :-( -oracle: CREATE SEQUENCE XYZ INCREMENT BY 1 START WITH 1 NOCYCLE CACHE 20; -ms sql: ??? 2....
2
by: charlie19102 | last post by:
We make use of sequences throughout our application. However, one in particular is causing concern. The sequence is tied to a table and increments when an insert trigger fires on the table. The...
0
debasisdas
by: debasisdas | last post by:
PL/SQL: Sequences ================ In Oracle, the sequences object provides a sequential series of numbers to applications without the overhead of disk I/O or transaction locking. These values are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.