在 Oracle 12c 中插入对象数据
Insert Object data in Oracle 12c
我试图在我的 table 中插入数据,其中一列是对象类型,但出现以下错误:
RA-06553: PLS-306: wrong number or types of arguments in call to 'SET_DATUME'
Table定义是:
CREATE TABLE Trebovanje (
BrDokumenta NUMBER,
Datumi DATUMI_T,
SifRJ NUMBER,
BrRadKnjiz NUMBER,
CONSTRAINT trebovanje_pk PRIMARY KEY (BrDokumenta),
CONSTRAINT treb_rj_fk FOREIGN KEY (SifRJ) REFERENCES RadnaJedinica (SifRJ),
CONSTRAINT trebovanje_zap_fk FOREIGN KEY (BrRadKnjiz) REFERENCES Zaposleni (BrRadKnjiz)
);
DATUMI_T 用户自定义类型:
create or replace TYPE DATUMI_T AS OBJECT (
DatPrijema DATE,
DatStampanja DATE,
MEMBER FUNCTION get_dat_prijema RETURN DATE,
MEMBER FUNCTION get_dat_stampanja RETURN DATE,
MEMBER PROCEDURE set_datume(p_dat_prijema DATE, p_dat_stampanja DATE),
MEMBER FUNCTION proveri_dat_stampanja(p_dat_stampanja DATE) RETURN BOOLEAN
);
create or replace TYPE BODY DATUMI_T AS
MEMBER FUNCTION get_dat_prijema RETURN DATE AS
BEGIN
RETURN self.DatPrijema;
END get_dat_prijema;
MEMBER FUNCTION get_dat_stampanja RETURN DATE AS
BEGIN
RETURN self.DatStampanja;
END get_dat_stampanja;
MEMBER PROCEDURE set_datume(p_dat_prijema DATE, p_dat_stampanja DATE) AS
BEGIN
self.DatPrijema := p_dat_prijema;
IF proveri_dat_stampanja(p_dat_stampanja)
THEN
self.DatStampanja := p_dat_stampanja;
ELSE
self.DatStampanja := SYSDATE;
END IF;
END set_datUME;
MEMBER FUNCTION proveri_dat_stampanja(p_dat_stampanja DATE) RETURN BOOLEAN AS
ok BOOLEAN;
BEGIN
ok := self.DatPrijema < p_dat_stampanja;
RETURN ok;
END proveri_dat_stampanja;
END;
还有我的插入语句:
insert into trebovanje values (
1,
DATUMI_T.set_datume(
TO_DATE('2017-01-02 17:44:33', 'YYYY-MM-DD HH24:MI:SS'),
TO_DATE('2017-01-02 17:55:33', 'YYYY-MM-DD HH24:MI:SS')
),
1,
1234);
对此有什么想法吗?
您似乎需要定义一个 "hides" 默认构造函数的构造函数。
CREATE OR REPLACE TYPE DATUMI_T AS OBJECT
(
DatPrijema DATE,
DatStampanja DATE,
MEMBER FUNCTION get_dat_prijema
RETURN DATE,
MEMBER FUNCTION get_dat_stampanja
RETURN DATE,
MEMBER PROCEDURE set_datume(p_dat_prijema DATE, p_dat_stampanja DATE),
MEMBER FUNCTION proveri_dat_stampanja(p_dat_stampanja DATE)
RETURN BOOLEAN,
/* the declaration of your own constructor ( same name of the type ) */
CONSTRUCTOR FUNCTION DATUMI_T(DatPrijema DATE, DatStampanja DATE)
RETURN SELF AS RESULT
);
create or replace TYPE BODY DATUMI_T AS
MEMBER FUNCTION get_dat_prijema RETURN DATE AS
BEGIN
RETURN self.DatPrijema;
END get_dat_prijema;
MEMBER FUNCTION get_dat_stampanja RETURN DATE AS
BEGIN
RETURN self.DatStampanja;
END get_dat_stampanja;
MEMBER PROCEDURE set_datume(p_dat_prijema DATE, p_dat_stampanja DATE) AS
BEGIN
self.DatPrijema := p_dat_prijema;
IF proveri_dat_stampanja(p_dat_stampanja)
THEN
self.DatStampanja := p_dat_stampanja;
ELSE
self.DatStampanja := SYSDATE;
END IF;
END set_datUME;
/* the body of your constructor */
CONSTRUCTOR FUNCTION DATUMI_T(DatPrijema DATE, DatStampanja DATE)
RETURN SELF AS RESULT as
BEGIN
self.DatPrijema := DatPrijema;
IF proveri_dat_stampanja(DatStampanja)
THEN
self.DatStampanja := DatStampanja;
ELSE
self.DatStampanja := SYSDATE;
END IF;
return;
END DATUMI_T;
MEMBER FUNCTION proveri_dat_stampanja(p_dat_stampanja DATE) RETURN BOOLEAN AS
ok BOOLEAN;
BEGIN
ok := self.DatPrijema < p_dat_stampanja;
RETURN ok;
END proveri_dat_stampanja;
END;
我试图在我的 table 中插入数据,其中一列是对象类型,但出现以下错误:
RA-06553: PLS-306: wrong number or types of arguments in call to 'SET_DATUME'
Table定义是:
CREATE TABLE Trebovanje (
BrDokumenta NUMBER,
Datumi DATUMI_T,
SifRJ NUMBER,
BrRadKnjiz NUMBER,
CONSTRAINT trebovanje_pk PRIMARY KEY (BrDokumenta),
CONSTRAINT treb_rj_fk FOREIGN KEY (SifRJ) REFERENCES RadnaJedinica (SifRJ),
CONSTRAINT trebovanje_zap_fk FOREIGN KEY (BrRadKnjiz) REFERENCES Zaposleni (BrRadKnjiz)
);
DATUMI_T 用户自定义类型:
create or replace TYPE DATUMI_T AS OBJECT (
DatPrijema DATE,
DatStampanja DATE,
MEMBER FUNCTION get_dat_prijema RETURN DATE,
MEMBER FUNCTION get_dat_stampanja RETURN DATE,
MEMBER PROCEDURE set_datume(p_dat_prijema DATE, p_dat_stampanja DATE),
MEMBER FUNCTION proveri_dat_stampanja(p_dat_stampanja DATE) RETURN BOOLEAN
);
create or replace TYPE BODY DATUMI_T AS
MEMBER FUNCTION get_dat_prijema RETURN DATE AS
BEGIN
RETURN self.DatPrijema;
END get_dat_prijema;
MEMBER FUNCTION get_dat_stampanja RETURN DATE AS
BEGIN
RETURN self.DatStampanja;
END get_dat_stampanja;
MEMBER PROCEDURE set_datume(p_dat_prijema DATE, p_dat_stampanja DATE) AS
BEGIN
self.DatPrijema := p_dat_prijema;
IF proveri_dat_stampanja(p_dat_stampanja)
THEN
self.DatStampanja := p_dat_stampanja;
ELSE
self.DatStampanja := SYSDATE;
END IF;
END set_datUME;
MEMBER FUNCTION proveri_dat_stampanja(p_dat_stampanja DATE) RETURN BOOLEAN AS
ok BOOLEAN;
BEGIN
ok := self.DatPrijema < p_dat_stampanja;
RETURN ok;
END proveri_dat_stampanja;
END;
还有我的插入语句:
insert into trebovanje values (
1,
DATUMI_T.set_datume(
TO_DATE('2017-01-02 17:44:33', 'YYYY-MM-DD HH24:MI:SS'),
TO_DATE('2017-01-02 17:55:33', 'YYYY-MM-DD HH24:MI:SS')
),
1,
1234);
对此有什么想法吗?
您似乎需要定义一个 "hides" 默认构造函数的构造函数。
CREATE OR REPLACE TYPE DATUMI_T AS OBJECT
(
DatPrijema DATE,
DatStampanja DATE,
MEMBER FUNCTION get_dat_prijema
RETURN DATE,
MEMBER FUNCTION get_dat_stampanja
RETURN DATE,
MEMBER PROCEDURE set_datume(p_dat_prijema DATE, p_dat_stampanja DATE),
MEMBER FUNCTION proveri_dat_stampanja(p_dat_stampanja DATE)
RETURN BOOLEAN,
/* the declaration of your own constructor ( same name of the type ) */
CONSTRUCTOR FUNCTION DATUMI_T(DatPrijema DATE, DatStampanja DATE)
RETURN SELF AS RESULT
);
create or replace TYPE BODY DATUMI_T AS
MEMBER FUNCTION get_dat_prijema RETURN DATE AS
BEGIN
RETURN self.DatPrijema;
END get_dat_prijema;
MEMBER FUNCTION get_dat_stampanja RETURN DATE AS
BEGIN
RETURN self.DatStampanja;
END get_dat_stampanja;
MEMBER PROCEDURE set_datume(p_dat_prijema DATE, p_dat_stampanja DATE) AS
BEGIN
self.DatPrijema := p_dat_prijema;
IF proveri_dat_stampanja(p_dat_stampanja)
THEN
self.DatStampanja := p_dat_stampanja;
ELSE
self.DatStampanja := SYSDATE;
END IF;
END set_datUME;
/* the body of your constructor */
CONSTRUCTOR FUNCTION DATUMI_T(DatPrijema DATE, DatStampanja DATE)
RETURN SELF AS RESULT as
BEGIN
self.DatPrijema := DatPrijema;
IF proveri_dat_stampanja(DatStampanja)
THEN
self.DatStampanja := DatStampanja;
ELSE
self.DatStampanja := SYSDATE;
END IF;
return;
END DATUMI_T;
MEMBER FUNCTION proveri_dat_stampanja(p_dat_stampanja DATE) RETURN BOOLEAN AS
ok BOOLEAN;
BEGIN
ok := self.DatPrijema < p_dat_stampanja;
RETURN ok;
END proveri_dat_stampanja;
END;