apexlib_tabform and ORA-00911: invalid character

When validating a report by looping its values (i.e. :)

for i in 1 .. apexlib_tabform.getrowcount loop
  v_num := apexlib_tabform.nv('ATTR_ID', i);
end loop;

You can get an ORA-00911 message. My first attempt was to enhance the procedure ApexLib_Util.debug to find out more. Interesting outputs, but no indication for a solution though.

After some complexity reduction on my query, I found the entire query is parsed to the ApexLib_TabForm package and gets mis-interpreted  because of an order by clause in the query.

So, the solution is to get rid of the order by and use the sort checkboxes on the Report attributes page instead.