Search code examples
oracle-databaseplsqlconstructorclob

Problems using clob as a parameter to a constructor


I have the following PL/SQL code:

create type testingclob as object (
  member_value number,
  constructor function testingclob(
    i_aclob    clob
  ) return self as result
);
/
create type body testingclob as
  constructor function testingclob(
    i_aclob    clob
  ) return self as result
  is
  begin
    member_value := 0;
    return;
  end;
end;
/
declare 
   l_test testingclob;
begin

   l_test := new testingclob('some text');
end;

But I get the error

ORA-06550: line 5, column 18:
PLS-00307: too many declarations of 'TESTINGCLOB' match this call
ORA-06550: line 5, column 4:

The compilation of the type works fine. However it appears that I cannot use the constructor. Does anybody know what I am doing wrong?


Solution

  • The parameter 'some text' should be declared as clob.

    declare 
       l_param clob;
       l_test testingclob;
    begin
       l_param:= 'some text';
       l_test := new testingclob(l_param);
    end; 
    

    By default, the system supplies a default constructor that accepts a parameter corresponding to each attribute, see https://docs.oracle.com/cd/B13789_01/appdev.101/b10807/10_objs.htm#i16312 chapter 'defining object constructors'. Therefore the constructor cannot be determined definitely because none of them hits the input parameter varchar2.

    Try

    begin
       l_test := new testingclob(1);
    end;
    

    This is your default constructor.