Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Dynamic SQL in Stored Procedure
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.
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
>
>
-- --------------------------------------------------- * 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
![]() |
![]() |