Home » SQL & PL/SQL » SQL & PL/SQL » insert incremented value (plsql)
insert incremented value [message #641293] Thu, 13 August 2015 01:39 Go to next message
sanodani
Messages: 98
Registered: October 2014
Member
Hallo,

I would like to insert the incremented value for one columm in the table. Can anyone please help me how can i do this? Smile

test case:

create table m_test  (
 name varchar2(20),
 oid number,
 aid number,
 bid number,
 text varchar2(50),
 c_text varchar2(20)
 
 );
 
insert into m_test (name, oid, aid, bid, text, c_text) values('MAN', 11, 2, 2, 'Text for Testing', 'Maddy');



So, i would like to have the value for oid as 12 in next row and other coulum value will be provided, that somehow it need to check the previous value for oid and make increment by 1 and insert it.

Any help please?
Thankx
Re: insert incremented value [message #641294 is a reply to message #641293] Thu, 13 August 2015 01:53 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Use a sequence.
Re: insert incremented value [message #641297 is a reply to message #641293] Thu, 13 August 2015 02:21 Go to previous messageGo to next message
pablolee
Messages: 2882
Registered: May 2007
Location: Scotland
Senior Member
sanodani wrote on Thu, 13 August 2015 07:39


So, i would like to have the value for oid as 12 in next row and other coulum value will be provided, that somehow it need to check the previous value for oid and make increment by 1 and insert it.

Not really feasible in a multi-user environment. Your best bet is, (as LF has already said) use a sequence. You cannot guarantee contiguous values (no gaps) but you CAN guarantee the order of your data and with that, you can generate a contiguous set of numbers at query time if that is necessary.
Re: insert incremented value [message #641298 is a reply to message #641294] Thu, 13 August 2015 02:24 Go to previous messageGo to next message
Michel Cadot
Messages: 68647
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Link
And if you are in 12c you can use an identity column.

Re: insert incremented value [message #641328 is a reply to message #641298] Thu, 13 August 2015 06:34 Go to previous message
sanodani
Messages: 98
Registered: October 2014
Member
Thank you all for your valuable Suggestion.
Smile
Previous Topic: Cursor Query help
Next Topic: "Merge" Values in one field with case?
Goto Forum:
  


Current Time: Fri Apr 26 17:12:01 CDT 2024