Oracle Update row with minimum value -
i'm trying give kind of unique random code users without skipping number in range. table this
randomcode | isused | rnum -------------------------- 002        | y      | 1 004        | y      | 2 003        | null   | 3 005        | y      | 4 001        | null   | 5 so next randomcode use should 003 , 001. problem user can return code , should give number someonelse. in case i'm setting isused null.
i've tried selecting minimum rnum isused column null. , updading table. encountered race condition , users got duplicate randomcode.
any to
update table set isused = n'y' isused = null , rnum = min(rnum) returning
you made 2 little mistakes in code:
- you did - isused = null.- this condition returns false. nothing equates - null. use- isused nullinstead.
- you used - rnum = min(rnum). use subquery instead.
here's query these simple modifications.
update table set isused = n'y' isused null , rnum = (select min(rnum) table isused null) 
Comments
Post a Comment