PROCEDURE parse_name (fullname_in IN VARCHAR2, fname_out OUT caller.first_name%TYPE, lname_out OUT caller.last_name%TYPE) IS /* Trimmed and uppercased version of name. */ fullname_int VARCHAR2(255) := LTRIM (RTRIM (UPPER (fullname_in))); /* The location of the comma delimiter in the name. */ delim_comma NUMBER := INSTR (fullname_int, ','); /* Location of the first space delimiter in the name. */ delim_space NUMBER := INSTR (fullname_int, ' '); BEGIN IF delim_comma = 0 AND delim_space = 0 THEN /* No comma, no space: return whole string as LAST name. */ lname_out := fullname_int; fname_out := NULL; ELSIF delim_comma != 0 THEN /* Found a comma in the string! Use LAST, FIRST format. || || Use SUBSTR to grab everything from the beginning of the || name to just before comma and assign it to last name. */ lname_out := SUBSTR (fullname_int, 1, delim_comma-1); /* || Use SUBSTR to grab everything from just after the comma || and assign it to the first name. Use LTRIM to || get rid of any blanks between the comma and the first name. */ fname_out := LTRIM (SUBSTR (fullname_int, delim_comma+1)); ELSIF delim_space != 0 THEN /* Found a space in the string! Use FIRST LAST format. || || Use SUBSTR to grab everything from the beginning of the || name to just before the space and assign to first name. */ fname_out := SUBSTR (fullname_int, 1, delim_space-1); /* || Use SUBSTR to grab everything from just after the space || and assign it to the last name. Use RTRIM to || get rid of any multiple spaces before the last name. */ lname_out := LTRIM (SUBSTR (fullname_int, delim_space+1)); END IF; END parse_name;