Execute immediate dbms_output.put_line

10,369
declare
v_str varchar2(200);
begin
v_str := q'!begin dbms_output.put_line('Hello world'); end;!';
Execute immediate v_str;
end;
/

works...

Share:
10,369
David Kakauridze
Author by

David Kakauridze

Updated on June 27, 2022

Comments

  • David Kakauridze
    David Kakauridze almost 2 years

    I have code like this:

    set serveroutput on
    
    declare
    v_str varchar2(200);
    begin
    v_str := q'!dbms_output.put_line('Hello world');!';
    Execute immediate v_str;
    end;
    

    Oracle SQL Developer says that there's invalid SQL Statement, what's the problem?

    • kmkaplan
      kmkaplan over 11 years
      Use show err to print detail on the error.
    • Jeffrey Kemp
      Jeffrey Kemp over 11 years
      Is there a particular reason why you need to call dbms_output with dynamic PL/SQL?
  • Ben
    Ben over 11 years
    Basically, the answer is that dbms_output is a procedure and so can only be executed within a PL/SQL block.
  • Alex Poole
    Alex Poole over 11 years
    @Ben - really a reply to a comment on your deleted answer, but still relevant here; the q syntax is in the documentation under text literals.