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 -> Re: Dynamic SQL in Stored Procedure

Re: Dynamic SQL in Stored Procedure

From: Ing. Martin Gamperl <mgampi_at_ibm.net>
Date: 1998/01/31
Message-ID: <34D3356F.666D553E@ibm.net>#1/1

Hi Mark,

try to use the DBMS_SQL.xxxxxx package to solve your problem. With this package you can generate SQL-Statements dynamically. For example we used this fragment of code to insert values into a table which rows are changed arbitrary.

            vCommand := vCommand || ')';

Mark Aurit schrieb:

> Im using the Oracle Web Server, and I want to give the customer the
> ability choose a sort; in other words, affect the ORDER BY. Their
> request will be passed to a stored procedure, and Im wondering how
> (and if) I can change the SQL dynamically. I could do something like
> IF var1 = 'A' THEN
> .. do some cursor stuff and issue a SELECT..
> ORDER BY colA
> ELSE
> ORDER BY colB
> END IF;
> But I hate the idea of all that code Ill have to duplicate. Can I say
> something like:
> IF var1 = 'A' then
> var2 := 'emp_id';
> else
> var2 := 'city';
> end if;
> Followed by:
> .. cursor stuff and a SELECT ...
> ORDER BY var2

>

> Or some such construct?
>

> Any ideas greatly appreciated.
> Mark_Aurit @ mail.northgrum.com
--
---------------------------------------------------
*  Ing. Martin Gamperl
*  MGS Softwareentwicklung
*  Klosterwiesgasse 31/IV
*  A-8010 GRAZ
*  Tel.    : +43-316-83 58 26
*  Fax     : +43-316-83 58 26
*  Mobil   : +43-664-40 03 032
*  EMail   : mgampi_at_ibm.net
---------------------------------------------------
Received on Sat Jan 31 1998 - 00:00:00 CST

Original text of this message

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