PROCEDURE validate_company (comp_name_inout IN OUT VARCHAR2, comp_id_out OUT NUMBER) IS /* Cursor as explained above */ CURSOR company_cur IS SELECT company_id, company_name FROM company WHERE company_name LIKE comp_name_inout || '%'; /* Declare two records against the same cursor. */ company_rec company_cur%ROWTYPE; duplicate_rec company_cur%ROWTYPE; BEGIN /* Open and perform the first fetch against cursor. */ OPEN company_cur; FETCH company_cur INTO company_rec; IF company_cur%NOTFOUND THEN /* Not even one match for this name. Display message and reject. */ MESSAGE (' No company found with name like "' || comp_name_inout || '".'); CLOSE company_cur; RAISE FORM_TRIGGER_FAILURE; ELSE /* || Found one match. Now FETCH again, but this time FETCH into the || duplicate_rec record. This is just a "place holder". I don't || need to see the contents of the record. I just need to know if || I can successfully retrieve another record from the cursor. */ FETCH company_cur INTO duplicate_rec; IF company_cur%NOTFOUND THEN /* || Found 1 match, but not second. Unique! Assign values to || the OUT parameters and close the cursor. */ comp_id_out := company_rec.company_id; comp_name_inout := company_rec.company_name; CLOSE company_cur; ELSE /* || AT LEAST two matches found for this name. I don't know how many || more and I do not care. Reject with message. */ MESSAGE (' More than one company matches name like "' || comp_name_inout || '".'); CLOSE company_cur; RAISE FORM_TRIGGER_FAILURE; END IF; END IF; END;