i ask or advice in particular case.
i have table called "teams". table contains 3 columns - issue, responsible_team , more_info (all varchar2).
i have pl/sql script cursor , loop selecting many teams issue description type (some random word think might find responsible team). part works great me.
but not know how compile if condition in there. if no team found according typed word description, basic output dbms_output.put_line('responsible team not found'). there 2 ways how wrote script. classic loop , while loop. happy advice.
1.script
set verify off declare v_issue teams.issue%type; --variable issue column teams table v_respteam teams.responsible_team%type; --variable responsible_team column teams table v_info teams.more_info%type; --variable more_info column teams table --cursor declaration cursor c_respteam return teams%rowtype select issue, responsible_team, more_info teams lower(issue) '%&describe_issue%'; begin open c_respteam; loop fetch c_respteam v_issue, v_respteam, v_info; exit when c_respteam%notfound; dbms_output.put_line('responsible team '|| v_respteam || ' --> ' || v_info); end loop; close c_respteam; end; / 2.script
-- cursor while loop set verify off declare v_issue teams.issue%type; --variable issue column teams table v_respteam teams.responsible_team%type; --variable responsible_team column teams table v_info teams.more_info%type; --variable more_info column teams table cursor c_respteam return teams%rowtype select issue, responsible_team, more_info teams lower(issue) '%&describe_issue%'; begin open c_respteam; fetch c_respteam v_issue, v_respteam, v_info; while c_respteam%found loop dbms_output.put_line('responsible team '|| v_respteam || ' --> ' || v_info); fetch c_respteam v_issue, v_respteam, v_info; end loop; close c_respteam; end; /
you rewrite to:
declare l_found boolean :=false; cursor c_respteam select issue ,responsible_team ,more_info teams lower(issue) '%&describe_issue%'; begin r in c_respteam loop l_found := true; dbms_output.put_line('responsible team ' || r.responsible_team || ' --> ' || r.more_info); end loop; if not l_found dbms_output.put_line('no records found'); end if; end; /
Comments
Post a Comment