Overblog Suivre ce blog
Editer l'article Administration Créer mon blog

Search

Free tool

Look and Feel Project

21 octobre 2005 5 21 /10 /octobre /2005 00:00

Sometimes, on forums, I see questions about dynamic SQL.
This is one of them:

"Hello,
I would like to execute a function wich name is stored in a string.
How could I do ?"

The solution for this kind of problem is allways the dynamic SQL:

Connected to:
Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> CREATE OR REPLACE FUNCTION text_xx RETURN VARCHAR2
  2  IS
  3  BEGIN
  4    RETURN 'Hello' ;
  5  END ;
  6  /

Function created.

SQL> set serveroutput on
SQL>
SQL> DECLARE
  2    LC$Proc   VARCHAR2(100) := 'text_xx' ;
  3    LC$Return VARCHAR2(100) ;
  4  BEGIN
  5    EXECUTE IMMEDIATE 'SELECT ' || LC$Proc || ' FROM DUAL' INTO LC$Return ;
  6    Dbms_Output.put_Line( LC$Return ) ;
  7  END ;
  8 
  9  /
Hello

PL/SQL procedure successfully completed.

SQL>


Francois

Partager cet article

Repost 0
Francois Degrelle - dans Oracle PL-SQL
commenter cet article

commentaires