title: Why ths works in anonymous but not in a procedure?
body: <p>If I do the following, everything is fine:</p>
  
  <pre><code>declare
    l_foo clob;
  begin
  select
  regexp_replace(
    dbms_metadata.get_ddl('USER', 'SCOTT', null) ||
    dbms_metadata.GET_GRANTED_DDL ('SYSTEM_GRANT', 'SCOTT') ||
    dbms_metadata.GET_GRANTED_DDL ('OBJECT_GRANT', 'SCOTT') ||
    dbms_metadata.GET_GRANTED_DDL ('ROLE_GRANT', 'SCOTT')
  ,'"' || chr(10), '";' || chr(10)) 
  into l_foo 
  from dual;
  end;
  /
  </code></pre>
  
  <p>But if I wrap this in a procedure:</p>
  
  <pre><code>create procedure tests is
    l_foo clob;
  begin
  select
  regexp_replace(
    dbms_metadata.get_ddl('USER', 'SCOTT', null) ||
    dbms_metadata.GET_GRANTED_DDL ('SYSTEM_GRANT', 'SCOTT') ||
    dbms_metadata.GET_GRANTED_DDL ('OBJECT_GRANT', 'SCOTT') ||
    dbms_metadata.GET_GRANTED_DDL ('ROLE_GRANT', 'SCOTT')
  ,'"' || chr(10), '";' || chr(10)) 
  into l_foo 
  from dual;
  end;
  /
  </code></pre>
  
  <p>And execute the procedure by "exec tests;" then I catch a object SCOTT of type USER not found in schema SCOTT.</p>
  
  <p>Why is this and how do I get around?</p>
  
  <p>Thanks 
  Chris</p>