oracle - PLSQL UPDATE OF with Join -
i'm trying create plsql statement updates money in inventory of characters money creatures they've fought
the following code i've been trying:
declare inv_money character.money%type; cursor updmoney select * character id in (select character_id inst_creature) update of money; begin v_character in updmoney loop select inst_creature.money inv_money inst_creature,character inst_creature.character_id = character.id; update character set money = money+inv_money current of updmoney; end loop; commit; end;
there character_id in inst_creature table used define character fought creature.
i'm getting error ora-01422: exact fetch returns more requested number of rows.
i've been trying fix using google solution nothing has been working far. thoughts?
what happens when character has killed more 1 monster? ora-01422, that's what. select ... syntax populates scalar value, 1 row. when query returns more 1 row pl/sql hurls ora-01422.
" there solution work?"
the easiest way fix query returns 1 row. you're adding money character's trove, can use aggregate:
select sum(inst_creature.money) inv_money inst_creature,character inst_creature.character_id = character.id;
so 1 row per character, , 1 update per character.
Comments
Post a Comment