Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Dynamic Sorts in Pl/Sql

Dynamic Sorts in Pl/Sql

From: Patrick Casey <casey_at_unc.edu>
Date: Thu, 18 Jan 2001 17:32:52 -0500
Message-ID: <947quk$ev$1@news2.isis.unc.edu>

We are trying to create a procedure that will be able to sort fields dynamically. We want the same fields for each query, but at some times we want it sorted by one field, and sometimes by another.

We created the following procedure:
PROCEDURE testSort
(in sort field IN VARCHAR2,
in sort order IN VARCHAR2 DEFAULT 'asc', out cursor OUT pjcCursor)
IS
BEGIN
if in sort order = 'asc' then
OPEN out cursor FOR
SELECT cat itm id, cat itm nm FROM ITP CATALOG ITEM ORDER BY in sort field ASC;
else
open out cursor FOR
select cat itm id, cat itm nm FROM itp catalog item order by in sort field DESC;
end if;
END; It allows us to pass in a field name to sort by. Now, it works fine on ASC, but it never works on DESC. We think this is because Oracle really sees this query as

OPEN out cursor FOR
SELECT cat itm id FROM ITP CATALOG ITEM
ORDER BY 'in sort field' ASC; <-- notice quotes around field name

It seems to ignore everything following.....Now, I did try to create a procedure that had the sort field hardcoded, with quotes around the name and it would not sort either. So, that seems to be the problem, the quotes.

Does anyone have any guesses as to how we can make this work????

-- 

Thanks.

Patrick Casey
Applications Analyst Programmer II
UNC - Chapel Hill
patrick casey_at_unc.edu
919.962.0549

--
Received on Thu Jan 18 2001 - 16:32:52 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US