2014-07-09 43 views
0

这是我的问题。如何根据某些值以光标状态更改顺序

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; 

问题是秩序ordby不工作。它总是默认排序。有可能使用变量进行排序吗?我需要在以下条件下订购。我不想声明两次游标。

回答

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

为什么downvote?这是两种有效的方法之一,另一种是通过EXECUTE IMMEDIATE – Falco

+0

动态SQL我没有DV(以及谁做了似乎无法下定决心),但一些解释可能是有用的? –

+0

没有ord需要是一个(游标)参数才能工作? – Sathya

相关问题