|
-
Nov 7th, 2001, 10:55 AM
#1
Thread Starter
Frenzied Member
Oracle Autonumber?
How do you create a field in an Oracle table so that it will generate its own key? I hope that makes sense.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Nov 7th, 2001, 11:13 AM
#2
Addicted Member
From Deja...
You can get a similar "autonumber" functionality programing an easy to code
"before insert trigger" that gets the next value of the sequence and put it
into the table for you.
You must use a sequence. To create a sequence see the "Create Sequence"
command of SQL Then on a trigger either on database (Before Insert) or
on a form (PRE-INSERT) you write the following Code:
Select Seq Name.NextVal
Into Field Name
From DUAL;
where "Seq Name" the name of the sequence you created and "Field Name"
the column which you want to be autonumbered.
Let supose that we have a table named A with a primary key column named id.
We also have a sequence called A_seq.
The following code builds the trigger who generates the primary key
automatically.
create or replace trigger TBI_A before insert on A
begin
--this generates de
select A_seq.nextval
into :new.id
from dual;
end;
Web/Application Developer
VB6 Ent (SP5), Win 2000,SQL Server 2000
-
Nov 7th, 2001, 11:29 AM
#3
Thread Starter
Frenzied Member
Okay... your response didn't help. and I'm not sure i understand the formatting.
This is what I have....
A table named "Errors". It has a field named "ErrorNum". In Access and SQL Server, any time a new record is added to that row, that field will generate its own value, a UID. I am trying to port this application to use an Oracle DB, but the DDLs I was given have not helped.
I am trying to avoid changing the code to such a dramatic degree that I have two seperate products. How can I define this table to compensate for what the code is expecting?
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Nov 7th, 2001, 11:34 AM
#4
Addicted Member
Oracle doesn't have an autonumber as such.
It has a 'Sequence' which can be used to figure out the next available UID before you insert a record.
Therefore you really only have two options.
1) Use the above. Get the next number in the sequence and use that.
2) Create a GUID to use.
Both of which will have to be put into a 'Before Insert' trigger.
S@NSIS
Web/Application Developer
VB6 Ent (SP5), Win 2000,SQL Server 2000
-
Nov 7th, 2001, 11:39 AM
#5
Thread Starter
Frenzied Member
Okay, I found this article: http://www.jlcomp.demon.co.uk/faq/autonumb.html.
I think it is saying the same as you were (but with punctuation). If I understand, I can use this and it won't change the SQL statements already in the code, right?
If so, this will work. We never supply this value, so I'm not worried about that, but we will query and return it to the user.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Nov 7th, 2001, 11:41 AM
#6
Addicted Member
Your link doesn't work!
As for 'punctuation', if you look at the top of the first post I made, I said it came from Deja (I actually searched for it).
Web/Application Developer
VB6 Ent (SP5), Win 2000,SQL Server 2000
-
Nov 7th, 2001, 11:44 AM
#7
Thread Starter
Frenzied Member
*rotfl* Sorry, the forums incorporated the sentence ending period into the URL.
It should be
not
http://www.jlcomp.demon.co.uk/faq/autonumb.html.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Nov 7th, 2001, 11:45 AM
#8
Addicted Member
I see
Web/Application Developer
VB6 Ent (SP5), Win 2000,SQL Server 2000
-
Nov 7th, 2001, 12:05 PM
#9
Thread Starter
Frenzied Member
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|