plsql - How to set cursor field name from another cursor? Oracle -
i need take cursor fields names cursor this:
for rec1 in (select * table1) loop rec2 in (select * table2) loop if rec1.[rec2.field_name] <> '*' ... end if; end loop; end loop;
oracle not designed kind of behavior. way can think of achieve use dynamic pl/sql produce functionality you're looking for:
declare v_field_value varchar2(2000); begin rec1 in (select * table1) loop rec2 in (select * table2) loop execute immediate 'begin :value := :rec1.' || :rec2.field_name || '; end;' using out v_field_value, in rec1; if v_field_value <> '*' ... end if; end loop; end loop; end;
however, because approach can work doesn't mean should use it. if field not string, instance, oracle implicitly convert value, may result in different value expect. if code, use last resort, after considering implementing same functionality outside database , redesigning database's structure avoid need type of code.
based on comment error mentioned in comment, i've modified code pass records in using bind variables.
Comments
Post a Comment