Pls help me its urgent [message #41259] |
Thu, 12 December 2002 07:01 |
Vinod
Messages: 76 Registered: April 1999
|
Member |
|
|
I have a column called description with values as follows
Admin Support
Admin Support
Admin Support
Air Support
Cable - Disaster Response
Cable - Operational Support
Cable - PMPP (Preparedness)
Cable - Program Support
Capacity Building
Capacity Building
Chemical, Biological, Radiological, & Nuclear
Commodity Procurement Contract
Communications
Computer Support
Contract Services (warehousing)
Coordination
Coordination
Disaster Assistance Response Program
I have another column in this table for which i have to update with the sequence nos. The update should happen in such a way that if the description is same then i have update with sequence.currval and if the description is different then i have to update with sequence.nextval for each row as follows
Admin Support----- 1
Admin Support----- 1
Admin Support----- 1
Air Support----- 2
Cable - Disaster Response----- 3
Cable - Operational Support----- 4
Cable - PMPP (Preparedness)----- 5
Cable - Program Support----- 6
Capacity Building----- 7
Capacity Building----- 7
Chemical, Biological, Radiological----- 8
Commodity Procurement Contract----- 9
Communications----- 10
Computer Support----- 11
Contract Services----- 12
Coordination----- 13
Coordination----- 13
Disaster Assistance Response----- 14
Pls help me how do i do this, this is very urgent
Thanks
Vinod
|
|
|
|
Re: Pls help me its urgent [message #41264 is a reply to message #41261] |
Thu, 12 December 2002 07:58 |
Vinod
Messages: 76 Registered: April 1999
|
Member |
|
|
I did what u told as follows
create or replace view dum
as select rownum r, sector_description from (select sector_description,count(*)
from sector_lookup group by sector_description)
/
update sector_lookup set dummy=(select dummy from dum
where sector_lookup.sector_description =
dum.sector_description)where exists (select * from dum where sector_lookup.sector_description=
dum.sector_description)
/
It said 66 rows updated but there was null values
I also tried the same thing on emp, but the new seq column was updated with null values
pls help me
Thanks
Vinod
|
|
|
|
Re: Pls help me its urgent [message #41272 is a reply to message #41259] |
Thu, 12 December 2002 11:27 |
Todd Barry
Messages: 4819 Registered: August 2001
|
Senior Member |
|
|
I wouldn't recommend storing this sequence value in the table. It is better to use analytic functions at query time to calculate the value.
If you store the value, think about what happens when you add new rows to this table. You have to go look up what the sequence is for this description.
Instead, just:
sql>select description, dense_rank() over (order by description) seqval
2 from t;
DESCRIPTION SEQVAL
-------------------------------------------------- ---------
Admin Support 1
Admin Support 1
Admin Support 1
Air Support 2
Cable - Disaster Response 3
Cable - Operational Support 4
Cable - PMPP (Preparedness) 5
Cable - Program Support 6
Capacity Building 7
Capacity Building 7
Chemical, Biological, Radiological, & Nuclear 8
Commodity Procurement Contract 9
Communications 10
Computer Support 11
Contract Services (warehousing) 12
Coordination 13
Coordination 13
Disaster Assistance Response Program 14
If you just have to store the value, the update can be done with:
update t t1
set seq = (select seq
from (select rowid, dense_rank() over (order by description) seq
from t) t2
where t2.rowid = t1.rowid);
|
|
|