dbTalk Databases Forums  

Dynamic "Orde by" parameter in Oracle Stored procedure

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Dynamic "Orde by" parameter in Oracle Stored procedure in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Amritha
 
Posts: n/a

Default Dynamic "Orde by" parameter in Oracle Stored procedure - 08-16-2010 , 01:51 PM






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.

Reply With Quote
  #2  
Old   
Gerard H. Pille
 
Posts: n/a

Default Re: Dynamic "Orde by" parameter in Oracle Stored procedure - 08-16-2010 , 02:07 PM






Amritha wrote:
Quote:
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.

I suppose you could use a ref_cursor, but what kind of design requires such construction?

Reply With Quote
  #3  
Old   
joel garry
 
Posts: n/a

Default Re: Dynamic "Orde by" parameter in Oracle Stored procedure - 08-16-2010 , 04:43 PM



On Aug 16, 11:51*am, Amritha <amritha.da... (AT) gmail (DOT) com> wrote:
Quote:
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...-in-order-by,2

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

jg
--
@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.

Reply With Quote
  #4  
Old   
Mark D Powell
 
Posts: n/a

Default Re: Dynamic "Orde by" parameter in Oracle Stored procedure - 08-17-2010 , 07:44 AM



On Aug 16, 3:07*pm, "Gerard H. Pille" <g... (AT) skynet (DOT) be> wrote:
Quote:
Amritha 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.

I suppose you could use a ref_cursor, but what kind of design requires such construction?- Hide quoted text -

- Show quoted text -
If there are a limited number of desired order by clauses then this
can be done using a weakly typed Reference Cursor. Based on the input
just assign the correct SQL statement to being the Reference Cursor
value.

Depending on the problem trying to be solved another approach might be
to define a view that performs the base SQL statement and just specify
the desired order by on the query against the join.

Another alternate might be the use of a pipelined function.

Only as a last resort would I use string concatenation and execute
immediate to solve the problem using dynamic SQL.

HTH -- Mark D Powell --

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.