

CREATE TABLE cferr_mcm (
	rob_id		NUMBER    NOT NULL REFERENCES rob(rob_id),
	rob_pos		NUMBER(2) NOT NULL,
	begin_time	TIMESTAMP  NOT NULL,
	status		NUMBER(6) NOT NULL
);

CREATE TABLE cferr_ni (
	rob_id		NUMBER    NOT NULL REFERENCES rob(rob_id),
	rob_port	NUMBER(2) NOT NULL,
	begin_time	TIMESTAMP  NOT NULL,
	nimask		NUMBER(6) NOT NULL
);

CREATE TABLE cferr_adc (
	rob_id		NUMBER    NOT NULL REFERENCES rob(rob_id),
	rob_pos		NUMBER(2) NOT NULL,
	begin_time	TIMESTAMP  NOT NULL,
	adcmask		NUMBER(7) NOT NULL
);

CREATE OR REPLACE VIEW cferr_mcm_current AS
	SELECT 	rob_id,rob_pos,status
	FROM	cferr_mcm 
		NATURAL JOIN
		( SELECT rob_id,rob_pos,MAX(begin_time) AS curr_time
	          FROM cferr_mcm GROUP BY rob_id,rob_pos) last
	WHERE	curr_time=begin_time;

CREATE OR REPLACE VIEW cferr_adc_current AS
	SELECT 	rob_id,rob_pos,adcmask
	FROM	cferr_adc
		NATURAL JOIN
		( SELECT rob_id,rob_pos,MAX(begin_time) AS curr_time
	          FROM cferr_adc GROUP BY rob_id,rob_pos) last
	WHERE	curr_time=begin_time;

CREATE OR REPLACE VIEW cferr_ni_current AS
	SELECT 	rob_id,rob_port,nimask
	FROM	cferr_ni
		NATURAL JOIN
		( SELECT rob_id,rob_port,MAX(begin_time) AS curr_time
	          FROM cferr_ni GROUP BY rob_id,rob_port) last
	WHERE	curr_time=begin_time;
