'How do I input an incremented value into selected column in Oracle SQL and/or PL/SQL?
I am in the process of updating a huge DB and can not for the life of me figure this out.
SELECT rank_column FROM schema.table
WHERE id IN (x,y,z,a,b,c) AND lll AND ooo
I'm a little stuck here since I need to set rank_column for x to be updated to 1A, rank_column for y to be 2A, z to be 3A, etc.
There are only 30 or so values here so I can do them by hand, but on the more difficult note, I also need to need to rank the values NOT in this list and we're talking about somewhere near 300,000+. The order for these should not matter, but how do I set the first read row to 1Z, the second to 2Z, the third to 3Z, etc? Thank you for any help it would be much appreciated!
I attempted to use pl/sql but every single time, it updates with the very same number so I might have 1B for all when I want 1B,2B,3B etc. I need something like this down below except I need to iterate each for each row. I attempted to put iterate:=iterate+1 inside of the set statement so everytime it sets rank it will iterate that rank, but I keep returning "missing equal sign" on the set line right over the equal sign.
DECLARE
iterate number:=1;
BEGIN
UPDATE schema.table
SET rank = iterate||'A'**,ITERATE = ITERATE + 1**
WHERE ID IN (11111,22222,33333,44444,55555,66666,777777,88888,99999)
AND type = '01'
AND manufacturer = '000111'
AND indicator = '0';
iterate:= iterate +1;
END;
Solution 1:[1]
Are you looking for something like this?
update tab_lvl set rank=rownum||'A' where id in (30,40,50,60,70,80,90,100);
8 rows updated.
select id,rank from tab_lvl where id in (30,40,50,60,70,80,90,100);
ID RANK
---------- ---------------
30 1A
40 2A
50 3A
60 4A
70 5A
80 6A
90 7A
100 8A
8 rows selected.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pankaj |
