PLSQL order by issue

后端 未结 4 1675
遥遥无期
遥遥无期 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条回答
  •  渐次进展
    2020-12-22 09:05

    If you want to do that, you will have to do dynamic SQL with PL/SQL.

    DECLARE
      sql_str VARCHAR2(500);
      sortby  VARCHAR2(30) := 'your_column_name';
    BEGIN
     -- Dynamic PL/SQL block invokes subprogram:
      sql_str := 'select * from your_table where a = 1 order by :a';
    
      OPEN CURSOR v_your_cursor for sql_str USING sortby;
    
      -- Then iterate your cursor.
    END;
    /
    

提交回复
热议问题