Using the ORDER BY Clause of the SELECT Statement

The ORDER BY clause of the SELECT statement implies that the query returns more than one row. Unless you use the DECLARE statement of SQL to define a Select cursor or a Function cursor, the database server issues an error if you specify the ORDER BY clause outside the context of a FOREACH loop to process the returned rows individually within an SPL routine.

For the syntax and usage of the DECLARE statement in SPL routines, see Declaring a Dynamic Cursor in an SPL Routine.