在 Oracle 11g 中,我有以下类型:
CREATE OR REPLACE TYPE "T_XMLTABLE" AS OBJECT (
zeile NUMBER,
spalte NUMBER,
wert VARCHAR2(1000),
xml NUMBER,
link VARCHAR2(1000),
target VARCHAR2(100),
srt NUMBER,
typ NUMBER,
format VARCHAR2(100),
uebersetzbar NUMBER,
tooltip VARCHAR2(100),
kommentar NUMBER,
output NUMBER,
CONSTRUCTOR FUNCTION t_xmltable(p_zeile NUMBER,
p_spalte NUMBER,
p_wert VARCHAR2,
p_xml NUMBER,
p_link VARCHAR2 DEFAULT NULL,
p_target VARCHAR2 DEFAULT NULL,
p_srt NUMBER DEFAULT 0,
p_typ NUMBER DEFAULT 1,
p_format VARCHAR2 DEFAULT NULL,
p_uebersetzbar NUMBER DEFAULT 0,
p_tooltip VARCHAR2 DEFAULT NULL,
p_kommentar NUMBER DEFAULT 0,
p_output NUMBER DEFAULT 7) RETURN SELF AS RESULT
)
CREATE OR REPLACE TYPE BODY t_xmltable AS
CONSTRUCTOR FUNCTION t_xmltable(p_zeile NUMBER,
p_spalte NUMBER,
p_wert VARCHAR2,
p_xml NUMBER,
p_link VARCHAR2 DEFAULT NULL,
p_target VARCHAR2 DEFAULT NULL,
p_srt NUMBER DEFAULT 0,
p_typ NUMBER DEFAULT 1,
p_format VARCHAR2 DEFAULT NULL,
p_uebersetzbar NUMBER DEFAULT 0,
p_tooltip VARCHAR2 DEFAULT NULL,
p_kommentar NUMBER DEFAULT 0,
p_output NUMBER DEFAULT 7) RETURN SELF AS RESULT
AS
BEGIN
self.zeile := p_zeile;
self.spalte := p_spalte;
self.wert := p_wert;
self.xml := p_xml;
self.link := p_link;
self.target := p_target;
self.srt := p_srt;
self.typ := p_typ;
self.format := p_format;
self.uebersetzbar := p_uebersetzbar;
self.tooltip := p_tooltip;
self.kommentar := p_kommentar;
self.output := p_output;
RETURN;
END;
END;
如您所见,它有相当多的成员,它们通过构造函数使用默认值进行初始化。在我们得到构造函数之前,类型是这样初始化的:
t_xmltable(zeile => v_y,
spalte => v_x,
wert => 'someval',
xml => 1337,
link => NULL,
target => NULL,
srt => 0,
typ => 1,
format => NULL,
uebersetzbar => 1,
tooltip => NULL,
kommentar => 0,
output => 7);
现在,我介绍了构造函数来摆脱不必要的默认值。但似乎这些默认值不能与命名参数一起使用。我真的不想失去它们的舒适感,重构所有使用该类型的代码将是一项相当大的工作。
以下作品:
DECLARE
x t_xmltable;
BEGIN
x := t_xmltable(1, 1, 'a', 1);
END;
以下不是:
DECLARE
x t_xmltable;
BEGIN
x := t_xmltable(zeile => 1, spalte => 1, wert => 'a', xml => 1);
END;
有人有一些巧妙的想法如何解决这个问题吗?