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

Home -> Community -> Usenet -> c.d.o.misc -> Variable Order By clause

Variable Order By clause

From: David Gilbert <nepherim42_at_hotmail.com>
Date: Tue, 10 Aug 1999 17:18:53 -0400
Message-ID: <37B0973D.81B55B95@hotmail.com>


Question:



Why can I not use variables in the ORDER BY clause of a PL/SQL cursor? Is there any way to produce the same effect in PL/SQL, without resorting to dymanic SQL?

Background:



I'm trying to create a cursor that has a variable ORDER BY clause. The sample code below runs, but does not perform the ORDER BY clause correctly (it produces the same results as the query without the ORDER BY clause).

Any ideas welcome,

Thanks,

~ ~ David

declare

   ord1 integer := 1;
   ord2 integer := 2;

   CURSOR c_Known_Issues IS

      SELECT
         seq_no,
         issue_type
      FROM   known_issues
      WHERE  system_id = 99
      ORDER BY ord1, ord2;
	

begin

   FOR known_Issue IN c_Known_Issues LOOP

      dbms_output.put_line(known_Issue.seq_No);

   END LOOP; end;

Produces output:
2
1
16
15
14
13
12
11
10
9
8
7
6
5
4
28
30
31
36
37 Received on Tue Aug 10 1999 - 16:18:53 CDT

Original text of this message

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