用于类型编译的构造函数代码,但是我的代码并未明确匹配它。
我尝试创建一种仅覆盖默认构造函数的类型(该构造函数希望将所有字段用作参数),但是这给了我一个语法错误。
create or replace
type QUARTER_RANGE as OBJECT
(
START_QUARTER VARCHAR(6),
END_QUARTER VARCHAR(6),
constructor function QUARTER_RANGE return self as result,
constructor function QUARTER_RANGE(startQuarterIn VARCHAR, endQuarterIn VARCHAR) return self as result
);
create or replace
type body QUARTER_RANGE as
constructor function QUARTER_RANGE return self as result
as
begin
self.start_quarter := null;
self.end_quarter := null;
return;
end;
constructor function QUARTER_RANGE(startQuarterIn VARCHAR, endQuarterIn VARCHAR) return self as result
as
begin
if not some_validation_function(startQuarterIn) then
RAISE_APPLICATION_ERROR (-20000, 'Invalid start quarter id'||startQuarterIn);
elsif not some_validation_function(startQuarterIn) then
RAISE_APPLICATION_ERROR (-20000, 'Invalid end quarter id'||endQuarterIn);
else
self.start_quarter := startQuarterIn;
self.end_quarter := endQuarterIn;
end if;
return;
end;
end;
declare
testString varchar(256);
begin
testString := '2019Q1';
-- The code below generates
-- PLS-00307: too many declarations of 'QUARTER_RANGE' match this call
inputQuarterRange:= QUARTER_RANGE(testString,testString);
-- I tried this code below in an attempt to force it to match
-- the varchar types but it also generates the same error
-- PLS-00307: too many declarations of 'QUARTER_RANGE' match this call
inputQuarterRange:= QUARTER_RANGE('2019Q1','2019Q1');
end;