Let's just assume that the function accepts a parameter. Based on certain condition, it either needs to insert a record or update the existing one.

You can split up the logic of insert and update as two separate function. Here the main function almost acts as a wrapper. The main business logic resides in two different function, which can be reused elsewhere as required.