Thank you all for your detailed answers!
My conclusion is:
- Use "FOR IN EXECUTE" if you want to sort by many different columns depending
on the function paramaters.
- Use "IF" and a seperate SQL-statement for every sort-column provided by the
function parameter if you only want to sort by a few different columns and
want to optimize the performance of your function.