Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 24th, 2012  |  syntax: None  |  size: 0.54 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. can we store the result of dynamic query into a variable and use it in if block?
  2. Declare
  3. v_count number
  4. v_sql varchar2(1000);
  5.  
  6. begin
  7.  
  8. v_count :='select count(*) from table_name';
  9.  
  10.  Execute Immediate v_count;
  11.  
  12. if(v_count <>0) then
  13.  
  14. v_sql :='delete table_name where x=X' ;
  15.  
  16. Execute Immediate v_sql ;
  17.  
  18. End if ;
  19.  
  20. end;
  21.        
  22. Declare
  23. v_statement varchar2(32767);
  24. v_count number;
  25. v_sql varchar2(1000);
  26.  
  27. begin
  28.  
  29.  v_statement :='select count(*) from table_name';
  30.  
  31.  Execute Immediate l_statement into v_count;
  32.  
  33.   if v_count >0 then
  34.    ...
  35.   end if ;
  36.  
  37. end;