CREATE OR REPLACE FUNCTION "BEPAAL_ROL"("P_AANVRAAGROL" IN VARCHAR2) RETURN VARCHAR2 IS --initialize variables here cursor c_rol is select rol rol , steekwoord1 sw1 , steekwoord2 sw2 , steekwoord3 sw3 from rol_vertaal; r_rol c_rol%rowtype; l_return varchar2(100); -- main body BEGIN open c_rol; fetch c_rol into r_rol; while c_rol%found loop dbms_output.put_line('1 '||p_aanvraagrol); if soundex(p_aanvraagrol) = soundex(r_rol.sw1) then dbms_output.put_line('2 '||r_rol.sw1||' '||r_rol.sw2||' '||r_rol.sw3); if r_rol.sw2 is not null and soundex(p_aanvraagrol) = soundex(r_rol.sw2) then dbms_output.put_line('3 '||r_rol.sw2); if r_rol.sw3 is not null and soundex(p_aanvraagrol) = soundex(r_rol.sw3) then dbms_output.put_line('4 '||r_rol.sw3); l_return := r_rol.rol; exit; elsif r_rol.sw3 is null then dbms_output.put_line('5 '||r_rol.sw3); l_return := r_rol.rol; exit; end if; elsif r_rol.sw2 is null then dbms_output.put_line('6 '||r_rol.sw2); l_return := r_rol.rol; exit; end if; else dbms_output.put_line('7 '); l_return := 'Onbekend'; end if; dbms_output.put_line('8 '||l_return); fetch c_rol into r_rol; end loop; close c_rol; RETURN l_return; END; /