Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Pl/sql newbie question....
Use a sequence. What you are trying to do is have a surrogate primary key.
If you do what you suggest it is quite possible you will have the same count
2x at some point. Instead use a sequence and a trigger.
Jim
<smenard_at_avior.com> wrote in message
news:20021004.131536.165344818.12214_at_avior.com...
> I have a table:
>
> inv_id, count,qty,size1,size2
> 1 1 2 3 6
> 2 1 2 3 4
> 1 2 4 8 10
>
> where the keys is a composite ind_id and coount.
>
> What is the best way to implement the column count when i insert a new
> row in this table...?
>
> i do it like that but i'm not sure because i don't lock the table...
>
> cursor test_cur is select count(*) from inv where inv_id=1;
> ...
> fetch text_cur into nb_count;
>
> nb_count:=nb_count+1;
>
> insert into inv_id values(1,nb_count,43,12,44);
>
> what is the best way to that in Oracle?
Received on Fri Oct 04 2002 - 21:20:55 CDT