plsql - oracle sql dynamic query to select column in cursor -
i've declared below cursor , variables:
l_level varchar2(100); l_level_value varchar2(100); l_select_clause clob; cursor l_data select level1, level2, level3 levels;
then loop through cursor:
for c1line in l_data loop case when c1line.level1 null l_level := 'c1line.level2' when c1line.level2 null l_level := 'c1line.level3' when c1line.level3 null l_level := 'c1line.level4' else l_level := null end case; end loop; l_select_clause := 'select ' || l_level || ' l_level_value dual;'; execute immediate l_select_clause;
and have other statements execute depending on selected variable l_level_value
my problem when execute procedure following error:
ora-00904: "c1line"."level2": invalid identifier ora-06512: @ "my_procedure", line 110 ora-06512: @ line 2
does know have done wrong? thanks
about actual error c1line.level1
, open cursor dynamically? seems valid in thee code have shown
then..
execute immediate
accepts bind variable, whereas should after execution only. mention, semicolon (;
) not needed in query string
l_select_clause := 'select ' || l_level || ' dual'; execute immediate l_select_clause l_level_value;
Comments
Post a Comment