我已经定义了此触发器,以控制删除后对象之间的引用,以便在架构中不保留任何“悬挂引用”:
CREATE TRIGGER gestionRefTransferencia
BEFORE DELETE ON Corriente
REFERENCING OLD AS O
FOR EACH ROW MODE DB2SQL
BEGIN
UPDATE Transferencia SET Cuenta_receptora = NULL WHERE Cuenta_receptora = O.oid;
END@
但是db2返回以下错误:
“操作“ =”的操作数的数据类型不兼容或不可比较”
任何想法为何?不能比较引用数据类型?
这是我的模式:
CREATE TYPE Cuenta_udt AS (
IBAN VARCHAR(28),
Saldo REAL,
Numero_de_cuenta BIGINT,
Fecha_creacion DATE
) mode DB2SQL;
CREATE TYPE Operacion_udt AS (
Cod_Num INTEGER,
Descripcion VARCHAR(100),
Hora INTEGER,
Fecha DATE,
Cantidad REAL,
Cuenta_IBAN VARCHAR(28)
) mode DB2SQL;
CREATE TYPE De_ahorro_udt UNDER Cuenta_udt AS (
Interes REAL,
Ultimo_devengo INTEGER
) mode DB2SQL;
CREATE TYPE Corriente_udt UNDER Cuenta_udt AS (
Oficina_bancaria_Codigo INTEGER,
Oficina_bancaria_Direccion VARCHAR(100)
) mode DB2SQL;
CREATE TYPE Transferencia_udt UNDER Operacion_udt AS (
Cuenta_IBAN_receptora VARCHAR(28),
Cuenta_receptora REF(Cuenta_udt)
) mode DB2SQL;
CREATE TABLE Cuenta OF Cuenta_udt (
REF IS oid USER GENERATED,
IBAN WITH OPTIONS NOT NULL,
Saldo WITH OPTIONS NOT NULL,
Numero_de_cuenta WITH OPTIONS NOT NULL,
Fecha_creacion WITH OPTIONS NOT NULL,
CONSTRAINT pk_cuenta PRIMARY KEY(IBAN)
);
CREATE TABLE Operacion OF Operacion_udt (
REF IS oid USER GENERATED,
Cod_Num WITH OPTIONS NOT NULL,
Hora WITH OPTIONS NOT NULL,
Fecha WITH OPTIONS NOT NULL,
Cantidad WITH OPTIONS NOT NULL,
Cuenta_IBAN WITH OPTIONS NOT NULL,
CONSTRAINT pk_operacion PRIMARY KEY(Cod_Num),
FOREIGN KEY (Cuenta_IBAN) REFERENCES Cuenta(IBAN) ON DELETE CASCADE
);
CREATE TABLE Corriente OF Corriente_udt UNDER Cuenta INHERIT SELECT PRIVILEGES (
FOREIGN KEY (Oficina_bancaria_Codigo, Oficina_bancaria_Direccion) REFERENCES Oficina_bancaria(Codigo, Direccion) ON DELETE SET NULL
);
CREATE TABLE Transferencia OF Transferencia_udt UNDER Operacion INHERIT SELECT PRIVILEGES (
Cuenta_receptora WITH OPTIONS SCOPE Cuenta,
FOREIGN KEY (Cuenta_IBAN_receptora) REFERENCES Cuenta(IBAN) ON DELETE CASCADE
);
答案 0 :(得分:0)
要比较两种不同的参考数据类型,请对其进行适当的转换。
例如,如果您的CUENTA_UDT层次结构具有“ REF USING BIGINT” 并且如果您的OPERACION_UDT使用“ REF USING BIGINT”,那么您的触发器可能如下所示:
CREATE or replace TRIGGER gestionRefTransferencia
BEFORE DELETE ON Corriente
REFERENCING OLD AS O
FOR EACH ROW MODE DB2SQL
BEGIN
UPDATE Transferencia SET Cuenta_receptora = NULL WHERE cast(Cuenta_receptora as bigint) = cast(O.OID as bigint);
END@
如果两个层次结构的引用类型使用不同的基本类型,则将其强制转换/转换为通用基本类型以进行比较。