3

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?

2
  • 1
    Use show err to print detail on the error. Commented Dec 18, 2012 at 9:26
  • Is there a particular reason why you need to call dbms_output with dynamic PL/SQL? Commented Dec 19, 2012 at 4:10

1 Answer 1

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

works...

Sign up to request clarification or add additional context in comments.

2 Comments

Basically, the answer is that dbms_output is a procedure and so can only be executed within a PL/SQL block.
@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.