Sort problem on dynamic query !!
Hi,
I have a dynamic query written in pl/sql, when I check "Sort" for each field in Report Attribute, error message raised up as "ORA-01785: ORDER BY item must be the number of a SELECT-list expression".
If I do not check Sort, it works fine. In my apps I need all fields sorted by user, how to fix this problem?
My query as below:
declare
query varchar2(2000):='select';
s_class varchar2(1000);
cursor c1 is select * from demo_preference;
begin
for c1_val in c1 loop
if c1_val.login is not null then
query := query ||' ' || 'login' || ',';
end if;
if c1_val.id is not null then
query := query ||' ' || 'id' || ',';
end if;
.......
end loop;
query := SUBSTR(query, 1, length(query)-1);
s_class := '(NVL(:P2_class, ''%'' || ''null%'') = ''%'' || ''null%'' OR
EXISTS (SELECT 1 FROM apex_collections WHERE collection_name = ''P2CLASSCOL'' AND c001 = class))';
query := query ||' ' || 'from ming.reg_report_view1 where'
|| ' ' || s_class;
return(query);
end;