FUNCTION bite_and_switch (tripart_string_in IN VARCHAR2) RETURN VARCHAR2 IS /* Location of first underscore */ first_delim_loc NUMBER := INSTR (tripart_string_in, '_', 1, 1); /* Location of second underscore */ second_delim_loc NUMBER := INSTR (tripart_string_in, '_', 1, 2); /* Return value of function, set by default to incoming string. */ return_value VARCHAR2(1000) := tripart_string_in; BEGIN /* Only switch words if two delimiters are found. */ IF second_delim_loc > 0 THEN /* Pull out the first and second words */ first_word := SUBSTR (tripart_string_in, 1, first_delim_loc - 1); second_word := SUBSTR (tripart_string_in, second__delim_loc + 1); /* Switch the words and stick them together. */ return_value := second_word || '_' || first_word; END IF; /* Return the switched string */ RETURN return_value; END bite_and_switch;