user3820014
user3820014

Reputation: 27

How to change order by condition in cursor based on some value

This is my problem.

if ord = 'd' then
   Ordby:= 'name'
else
   Ordby:= 'type'.
end if;
declare cursor file is
  select type,name,location, from filemstr order by ordby;
  begin
    for i in file
    loop
  end;

Problem is order by ordby is not working. It always ordering by default. Is that possible to use a variable to order? I need to order this on the following condition. I don't want to declare cursor two times.

Upvotes: 0

Views: 463

Answers (1)

Nick.Mc
Nick.Mc

Reputation: 19184

declare cursor file is
  select type,name,location, from filemstr order by decode(ord,'d',name,type)
  begin
    for i in file
    loop
  end;

Upvotes: 2

Related Questions