Here is a working example of one way to do it:

DECLARE
   result_var1                   VARCHAR2( 50 );
   result_var2                   VARCHAR2( 50 );
   variable_col_name             VARCHAR2( 20 ) := upper('PCT_FREE');
   query_string                  VARCHAR2( 2000 );
   xpath                         VARCHAR2( 40 );

   TYPE cur_typ IS REF CURSOR;

   c                             cur_typ;
BEGIN
   xpath                      := '''/ROW/'||variable_col_name||'''';
   query_string               :=
      'select EXTRACTVALUE (VALUE (e), ''/ROW/TABLE_NAME''), EXTRACTVALUE
(VALUE (e), '||xpath||')
        from table(xmlsequence(cursor(select * from user_tables where rownum
< 4)))e';

   OPEN c FOR query_string;

   LOOP
      FETCH c
       INTO result_var1, result_var2;

      EXIT WHEN c%NOTFOUND;
      DBMS_OUTPUT.put_line( result_var1 || '   ' || result_var2 );
   END LOOP;
END;















On Thu, May 13, 2010 at 9:54 AM, Michael Moore <[email protected]>wrote:

>
> http://stanford.edu/dept/itss/docs/oracle/10g/appdev.101/a97269/pc_04dat.htm#i24497
>
>
> <http://stanford.edu/dept/itss/docs/oracle/10g/appdev.101/a97269/pc_04dat.htm#i24497>You
> can use CONTEXT variables for this.
> Mike
>
> On Thu, May 13, 2010 at 1:18 AM, kah <[email protected]> wrote:
>
>> Hi All,
>>
>>
>> I have this problem where i am suppose to determine the value of a
>> variable.
>> However at design time, I do not know the name of the variable.
>>
>> During run time, the variable name will be given and based on the
>> given variable name, I need to find the value of the specified
>> variable name.
>>
>>
>> DECLARE
>>
>> VARIABLE_NAME VARCHAR2(1000);
>> VARIABLE1 VARCHAR2(1000):=1;
>> VARIABLE2 VARIABLE2(1000):=2;
>>
>> BEGIN
>>
>> VARIABLE_NAME:='VARIABLE1';
>>
>> END;
>>
>> In the above example of the value of VARIABLE_NAME is 'VARIABLE1'.
>> Therefore I need to return the value '1'.
>> And if the VARIABLE_NAME is 'VARIABLE2', then the value to return
>> would be '2'.
>>
>> I know this can be done using simple if else, however if the number of
>> Variables is unknown or very large.
>> Then if else would not do.
>>
>> Please advise, thanks
>>
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Oracle PL/SQL" group.
>> To post to this group, send email to [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/Oracle-PLSQL?hl=en
>
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Oracle PL/SQL" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Oracle-PLSQL?hl=en

Reply via email to