Re: Dynamic "Orde by" parameter in Oracle Stored procedure

From: joel garry <joel-garry_at_home.com>
Date: Mon, 16 Aug 2010 14:43:46 -0700 (PDT)
Message-ID: <94c38569-f487-46ea-a41b-52aa97d4ec65_at_l25g2000prn.googlegroups.com>



On Aug 16, 11:51 am, Amritha <amritha.da..._at_gmail.com> wrote:
> Hi,
>
> I would like to execute a SELECT * from table1 order by <XYZ>
> and get the results into IN OUT cursor.
>
> I want to pass XYZ as input parameter to stored procedure.
> It is treating it as string.
>
> For example: if XYZ value is field1, it is executing the SQL statement
> as
> SELECT * from table1 order by 'field1'
> instead of
> SELECT * from table1 order by field1
>
> Please help.

http://www.freelists.org/post/oracle-l/using-variable-name-in-order-by,2

Or use dynamic sql with a bind variable for the order by. http://www.oracle-base.com/articles/misc/LiteralsSubstitutionVariablesAndBindVariables.php

jg

--
_at_home.com is bogus.  “The Accidents of Style: Good Advice on How Not
to Write Badly,” is just out from St. Martin’s Griffin. It covers 350
errors that mar the writing of amateurs and professionals. But what
about editors? Author Charles Elster is mortified by a recurring
accident appearing in “The Accidents of Style.” Twelve times his
middle name, Harrington, is misspelled Huntington.
Received on Mon Aug 16 2010 - 16:43:46 CDT

Original text of this message