Order of data in Spool File

Hello,

I have a shell script through which I am executing .sql file and spooling the result of Query from .sql . I want to spool the result in ascending order. Is there any parameter to be set to print result in ascending or descending order.

Thanks in advance.

Add an "order by" clause to your query and that should sort the data the way you want.

1 Like

Thanks for reply. But I want to do it without adding 'order By' in Query. Is there any way to do it.

You could use the sort command on the spool file, but there will be problems for example with headings.
The order by clause is the cleanest and easiest way and was designed to do what you ask for.

Sorting within the SQL statement will be the most efficient, use the database sort order and respect values such as dates which in your output might look nice but are a nightmare to sort by the shell. Is there a reason you can't update the SQL? If the SQL is used by other processes, make a copy of it and change that instead.

Can you show us the SQL and some meaningful sample output from it? (in CODE tags, of course)

Thanks,
Robin