There is an excellent article on Writing PL/SQL in Oracle Application Express in the March/April 2014 edition of the Oracle Magazine.
There is a lot of useful information about where your code should be located. My favourite part of the article is comparison between the parameterless function relying on the Apex V function and a function that passes the values explicitly via parameters.
It is an excellent article that will repay the short time you will invest in reading it.