Convert string to be used as a column name in Oracle -


i want use convert column name string or vice versa. need query run in emm suite named unica (ibm experience one).

i have string i.e. 'cl_credit_limit' need use in query string populate table (using case) , need use column name. both in same query.

more specifically, pass value macro(in unica) once (either string (with ' ') or column name). need way convert these each other , doesn't matter 1 preferably column name string.

i know if there's

it sounds me need build query dynamically , execute it. perhaps following give ideas:

declare   strquery       varchar2(32767);   strcolumn_name varchar2(100) := 'cl_credit_limit';   ccursor        sys_refcursor;   ncolumn_value  number;   strval2        varchar2(32767);   dtval3         date; begin   strquery := 'select ' || strcolumn_name || ', field2, field3 ' ||               'from some_table ' ||                 'where ' || strcolumn_name || ' > 10000';    open ccursor strquery;    loop     fetch ccursor       ncolumn_value, strval2, dtval3;     exit when ccursor%notfound;      -- fetched values - example...      dbms_output.put_line(strcolumn_name || '=' || ncolumn_value ||                          '  field2=''' || strval2 || '''' ||                          '  field3=' || to_char(dtval3, 'dd-mon-yyyy'));      execute immediate 'update some_other_table ' ||                       'set some_column = ' ||                         'case '                           'when ' || strcolumn_name || ' = ''cl_credit_limit'' 123 ' ||                           'when ' || strcolumn_name || ' = ''cl_other'' 456 ' ||                           'else 789 '                          'end '                       'when key_column = ''something or other''';   end loop;    close ccursor; end; 

share , enjoy.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -