943,865 Members | Top Members by Rank

Ad:
  • Oracle Discussion Thread
  • Unsolved
  • Views: 2391
  • Oracle RSS
Nov 5th, 2008
0

Autogenerated Primary Key.. Pls Help !!

Expand Post »
When some datas are inserted in to a DB table from a jsp page, how do i get the primary key in my table autogenerated?? finiding out the highest value for the primary key in the table? Pls help me wid the coding in JAVA or HTML.. I use SQL*PLus.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lakshma.sugunan is offline Offline
2 posts
since Nov 2008
Nov 5th, 2008
0

Re: Autogenerated Primary Key.. Pls Help !!

you need to create a sequence. As you can guess this is an object that gives you numbers from sequence. then you should get next value from sequence. so you will always have different pk. here is a link that shows you how to create and use it.
after creating it you will probably do something like that

insert into a(pk,col1,col2) values (sqn.nextval,'value1','value3')
Reputation Points: 31
Solved Threads: 5
Light Poster
yilmazhuseyin is offline Offline
48 posts
since Oct 2006
Nov 5th, 2008
0

Re: Autogenerated Primary Key.. Pls Help !!

you can use either a sequence or the max value of PK field +1 for the next unique not null value.
Featured Poster
Reputation Points: 665
Solved Threads: 427
Posting Genius
debasisdas is offline Offline
6,406 posts
since Feb 2007
Apr 5th, 2010
0
Re: Autogenerated Primary Key.. Pls Help !!
I dont want to revive a 2008 post but i think ill save somene time, if the table is empty ull get an error simply using max+1, i finally choose to use the NVL2 handy function to get this:

SELECT NVL2(MAX(CODE_COLUMN),MAX(CODE_COLUMN)+1,1) NEXT_CODE_COLUMN FROM TABLE_NAME
Last edited by emsm; Apr 5th, 2010 at 4:23 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
emsm is offline Offline
1 posts
since Apr 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Oracle Forum Timeline: Import Excel .xls sheet into an Oracle Table
Next Thread in Oracle Forum Timeline: PL/SQL command





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC