PLSQL order by issue

后端 未结 4 1657
遥遥无期
遥遥无期 2020-12-22 08:49

Rolled back to revision one, then edited somewhat. See revised question.

I have an interesting issue with the below SELECT.

Its about ORDER BY clause; I am

4条回答
  •  -上瘾入骨i
    2020-12-22 09:00

    Try to select the ORDER BY clause as a separate column using the DECODE() function:

    SELECT DECODE(p_sortby, 'ID', gl.group_id, 'NAME', group_name) AS sort, ...
    ...
    ORDER BY 1
    

    Edit:

    I'm not sure what you mean by "doesn't work". If you mean that member_count is not sorted as you expect, use TO_CHAR(gl.member_count, '000000') to enforce a formatted string conversion. (adjust format mask to expected number of digits)

提交回复
热议问题