Wenn die Bedingung in PL/SQL-Skript mit cursor und loop

Ich würde Sie gerne Fragen, wie Sie nach Hilfe oder Beratung in diesem speziellen Fall.

Ich habe die Tabelle "Teams". Die Tabelle enthält 3 Spalten - Problem, Responsible_team und More_Info (alle varchar2).

Habe ich eine PL/SQL-Skript mit cursor und eine Schleife für die Auswahl, wie viele teams als Problem Beschreibung, die Sie geben (einige zufällige Wort, das Sie denken, es könnte Ihnen helfen, das verantwortliche team). Das Teil funktioniert großartig für mich.

Aber ich weiß nicht, wie zu kompilieren, die IF-Bedingung drin. Wenn kein team fand nach eingegebenen Wort Beschreibung, würde ich gerne einige grundlegende Ausgabe dbms_output.put_line ("Verantwortliches team ist nicht gefunden').
Es gibt 2 Möglichkeiten, wie ich das Skript schrieb. Classic loop-und while-Schleife.
Ich wäre froh für jeden Rat.

1.Skript

set verify off
DECLARE
    v_issue teams.issue%type; --variable for issue column from teams table
    v_respteam teams.responsible_team%type; --variable for responsible_team column from teams table
    v_info teams.more_info%type; --variable for more_info column from teams table

--cursor declaration
    CURSOR c_respteam
    RETURN teams%ROWTYPE
    IS
        SELECT issue, responsible_team, more_info
        FROM teams
        WHERE lower(issue) like '%&Describe_Issue%';
BEGIN
    OPEN c_respteam;
    LOOP
      FETCH c_respteam into v_issue, v_respteam, v_info;
      EXIT when c_respteam%NOTFOUND;
      dbms_output.put_line('Responsible team is '|| v_respteam || ' --> ' || v_info);        
    END LOOP;
    CLOSE c_respteam;
end;
/

2.Skript

-- cursor with while loop
set verify off
DECLARE
    v_issue teams.issue%type; --variable for issue column from teams table
    v_respteam teams.responsible_team%type; --variable for responsible_team column from teams table
    v_info teams.more_info%type; --variable for more_info column from teams table

CURSOR c_respteam
RETURN teams%ROWTYPE IS
    SELECT issue, responsible_team, more_info
    FROM teams
    WHERE lower(issue) like '%&Describe_Issue%';

BEGIN
OPEN c_respteam;
FETCH c_respteam INTO v_issue, v_respteam, v_info;
WHILE c_respteam%FOUND
LOOP
dbms_output.put_line('Responsible team is '|| v_respteam || ' --> ' || v_info);
FETCH c_respteam INTO v_issue, v_respteam, v_info;
END LOOP;
CLOSE c_respteam;
END;
/
Schreibe einen Kommentar