Wednesday, August 5, 2009

Oracle Report Builder Order by Issue

When we use Oracle, we can have SQL Navigator for back end packages, Form Builder for creating forms and Report Builder to generate reports. There was an issue in a report that was to order by using name for a sub data model query(not the main data model query) and several times this issue was reported, but when I go through the report, it was already ordered by name.


Assume,
branch and dept are tables in the database.
name and code are some table columns (fields) in these both tables.

Suppose the main data model query was,

SELECT branch.code, branch.name
FROM branch
ORDER BY branch.code;

And, sub data model query was,

SELECT dept.code, dept.name
FROM dept
ORDER BY dept.name;

As we know, according to the second query, department details should be ordered by name. But, in my case, this didn't happen.

The sub data model (not the sub data model query) in the Report Builder appeared as

code
name

So, we changed the positions of those fields (name to be in the first position) in the sub data model (not in the sub data model query).

Thereafter, it displayed like

name
code

Then, we run the report, it ordered properly and the issue was successfully sorted out. :)

But, even we don't change the field which is going to be ordered to the first position in the data model, it works for some cases. So, if anyone knows the exact reason for this, I wish, you will definitely share your ideas with me. :)

Amazing Products