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

Create Table T_RULE_SAMPLE_3D(
RuleId		VARCHAR(50)		NOT NULL,
X1		DECIMAL(8,2)		NOT NULL,
X2		DECIMAL(8,2)		NOT NULL,
X3		DECIMAL(8,2)		NOT NULL,
Flag		DECIMAL(4),
Count		DECIMAL(8),
toc		TIMESTAMP,
tom		TIMESTAMP,
mop		VARCHAR(120),
mou		VARCHAR(30),
CONSTRAINT pk_T_RULE_SAMPLE_3D PRIMARY KEY (RuleId, X1, X2, X3)
)
IN TB8KUSREMS INDEX IN TB8KIDXEMS@

COMMENT ON Table T_RULE_SAMPLE_3D IS '2维统计样本表'@

COMMENT ON T_RULE_SAMPLE_3D (RuleId IS '规则id')@
COMMENT ON T_RULE_SAMPLE_3D (X1 IS '样本值')@
COMMENT ON T_RULE_SAMPLE_3D (X2 IS '样本值')@
COMMENT ON T_RULE_SAMPLE_3D (X3 IS '样本值')@
COMMENT ON T_RULE_SAMPLE_3D (Flag IS '是否有效')@
COMMENT ON T_RULE_SAMPLE_3D (Count IS '统计的频次')@

/****************************************************************************
						INSERT TRIGGER FOR TABLE
							  T_RULE_SAMPLE_3D
*****************************************************************************/
DROP TRIGGER ins_b_T_RULE_SAMPLE_3D@

CREATE OR REPLACE TRIGGER ins_b_T_RULE_SAMPLE_3D
BEFORE INSERT ON T_RULE_SAMPLE_3D 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_RULE_SAMPLE_3D
*****************************************************************************/
DROP TRIGGER upd_b_T_RULE_SAMPLE_3D@

CREATE OR REPLACE TRIGGER upd_b_T_RULE_SAMPLE_3D
BEFORE UPDATE ON T_RULE_SAMPLE_3D 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
@
