updating multiple rows
517262Jun 19 2006 — edited Jun 19 2006I wrote the code below to check my location's table, search for the structure name fro each row. If the structure_name = 'state command', it should get the structure_id, go to me state table, compare the location's structure_id to state_id, get the associated state_name and display it.
the code does it correctly for the ist row but inserts / updates the same value for all the rows..
pls assist me in getting the correct pl/sql code...something may be wrong with my loop statement.
Thanks.
declare
v_loc_id location.location_id%type;
v_loc_name location.location_name%type;
v_structure_id location.structure_id%type;
v_structure_name location.structure_name%type;
v_counter number(10);
v_location location%rowtype;
v_structure_ids location.description%type;
counteris number(10) :=1 ;
begin
select max(location_id)
into v_counter
from location;
select location_id, location_name, structure_id, structure_name
into v_loc_id, v_loc_name, v_structure_id, v_structure_name
from location;
for counteris in 1 .. v_counter loop
if V_structure_name = 'STATE COMMAND' then
select state.state
into v_structure_ids
from tbl_state state
where v_structure_id = state.state_id;
update location
set description = v_structure_ids;
else
update location
set description = 'why';
end if;
end loop;
end;