title: Create an object instance in PL/SQL using execute immediate and optional arguments
body: <p>I have an object defined like this:</p>
  
  <pre><code>create or replace type MYOBJ as object (
      field1 varchar2(100);
      field2 varchar2(100);
      field3 varchar2(100);
  );
  </code></pre>
  
  <p>and a function like this (I know I can use a constructor, whatever):</p>
  
  <pre><code>create or replace function new_myobj ( field1 varchar2 default null
                                       , field2 varchar2 default null
                                       , field3 varchar2 default null) 
                                         return myobj is
  v_obj MYOBJ;
  begin
      v_obj := myobj(field1, field2, field3);
      return v_obj;
  end new_obj;
  </code></pre>
  
  <p>I'm trying to create an instance of that object type like this</p>
  
  <pre><code>declare
     v_plsql_block varchar2(200);
     v_my_obj MYOBJ;
     v_field varchar2(200);
     v_some_value varchar2(200) := 3;
  begin 
      v_field := 'field1'
      v_plsql_block := 'begin :a := new_myobj('||v_field||' =&gt; :b); end;';
      execute immediate v_plsql_block using in v_some_value, out v_my_obj;
  end;
  </code></pre>
  
  <p>but I get an error:
  <code>PLS-00306: wrong number or types of arguments in call to 'NEW_MYOBJ'</code></p>
  
  <p>Is it even possible to do what I'm trying to?</p>
  
  <p>FTR in the actual code v_field should be defined dynamically.</p>