I figured out what was going on. It turns out that MySQL tries to look for a user-defined function when no built-in function matches, and if no database is selected, it throws the "No database selected" error.