Question

I have an object defined like this:

create or replace type MYOBJ as object (
    field1 varchar2(100);
    field2 varchar2(100);
    field3 varchar2(100);
);

and a function like this (I know I can use a constructor, whatever):

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;

I'm trying to create an instance of that object type like this

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||' => :b); end;';
    execute immediate v_plsql_block using in v_some_value, out v_my_obj;
end;

but I get an error: PLS-00306: wrong number or types of arguments in call to 'NEW_MYOBJ'

Is it even possible to do what I'm trying to?

FTR in the actual code v_field should be defined dynamically.

Was it helpful?

Solution

Just replace the order of the params in the using clause:

execute immediate v_plsql_block using out v_my_obj, in v_some_value;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top