-- Version:		2025.7.31  14:52:27
Drop Table T_LOV_FCODE@

Create Table T_LOV_FCODE(
Type		DECIMAL(1,0)		NOT NULL,
Code		VARCHAR(20)		NOT NULL,
Name		VARCHAR(20)		NOT NULL,
Content		VARCHAR(100)		NOT NULL,
Usable		DECIMAL(1,0)		NOT NULL,
toc		TIMESTAMP,
tom		TIMESTAMP,
mop		VARCHAR(120),
mou		VARCHAR(30),
CONSTRAINT pk_T_LOV_FCODE PRIMARY KEY (Type, Code)
)
IN TB8KUSREMS INDEX IN TB8KIDXEMS@
Alter Table T_LOV_FCODE ALTER COLUMN Usable SET WITH Default 0@

COMMENT ON Table T_LOV_FCODE IS '故障代码对应表'@

COMMENT ON T_LOV_FCODE (Type IS '故障代码解析类型：0-整体解析；1-按位解析')@
COMMENT ON T_LOV_FCODE (Code IS '故障代码')@
COMMENT ON T_LOV_FCODE (Name IS '故障名称')@
COMMENT ON T_LOV_FCODE (Content IS '故障说明')@
COMMENT ON T_LOV_FCODE (Usable IS '是否启用报警')@

/****************************************************************************
						INSERT TRIGGER FOR TABLE
							  T_LOV_FCODE
*****************************************************************************/
DROP TRIGGER ins_b_T_LOV_FCODE@

CREATE OR REPLACE TRIGGER ins_b_T_LOV_FCODE
BEFORE INSERT ON T_LOV_FCODE REFERENCING NEW AS NEWROW FOR EACH ROW
MODE DB2SQL
BEGIN ATOMIC
	DECLARE	programm	VARCHAR(120);
	DECLARE	auth	VARCHAR(30);

	set (programm,auth) = (SELECT APPL_NAME,AUTHID FROM SYSIBMADM.APPLICATIONS WHERE APPL_ID = (SELECT APPLICATION_ID() FROM dual));

	set NEWROW.toc = (values sysdate);
	set NEWROW.tom = (values sysdate);
	set NEWROW.mop = programm;
	set NEWROW.mou = auth;
END
@
/****************************************************************************
						UPDATE TRIGGER FOR TABLE
							  T_LOV_FCODE
*****************************************************************************/
DROP TRIGGER upd_b_T_LOV_FCODE@

CREATE OR REPLACE TRIGGER upd_b_T_LOV_FCODE
BEFORE UPDATE ON T_LOV_FCODE REFERENCING NEW AS NEWROW FOR EACH ROW
MODE DB2SQL
BEGIN ATOMIC
	DECLARE	programm	VARCHAR(120);
	DECLARE	auth	VARCHAR(30);

	set (programm,auth) = (SELECT APPL_NAME,AUTHID FROM SYSIBMADM.APPLICATIONS WHERE APPL_ID = (SELECT APPLICATION_ID() FROM dual));

	set NEWROW.tom = (values sysdate);
	set NEWROW.mop = programm;
	set NEWROW.mou = auth;
END
@
