ORCEL触发器:TRI_HOURDB2REALTEMP
CREATE OR REPLACE TRIGGER TRI_HOURDB2REALTEMP AFTER
INSERT OR UPDATE ON "GW"."HOURDB" FOR EACH ROW
BEGIN
HOURDB_TO_REALTEMP(:NEW.SENID,:NEW.TIME,:NEW.V,:NEW.AVGV,:NEW.MAXV,:NEW.MAXT,:NEW.MINV,:NEW.MINT,:NEW.S,:NEW.AVGS,:NEW.MAXS,:NEW.MINS);
END;
参照1:HOURDB_TO_REALTEMP
CREATE OR REPLACE PROCEDURE HOURDB_TO_REALTEMP (
R_SENID in NUMBER,
R_TIME in DATE,
R_V in NUMBER,
R_AVGV in NUMBER,
R_MAXV in NUMBER,
R_MAXT in DATE,
R_MINV in NUMBER,
R_MINT in DATE,
R_S in NUMBER,
R_AVGS in NUMBER,
R_MAXS in NUMBER,
R_MINS in NUMBER
)
AS
BEGIN
DECLARE
NUM NUMBER(25);
TIMETEMP DATE;
BEGIN
NUM := 0;
SELECT count(*) into num from GW.WEATHER_REALTEMP_DATA where date_time = R_TIME and station_code = substr(R_SENID,6,5);
IF num = 0 and R_TIME < sysdate+1 THEN
case(mod(R_senid,100))
when 39 then
INSERT INTO GW.WEATHER_REALTEMP_DATA (STATION_CODE,DATE_TIME, WIND_DIRECTION) VALUES (substr(R_SENID,6,5), R_TIME, R_V);
when 81 then
INSERT INTO GW.WEATHER_REALTEMP_DATA (STATION_CODE,DATE_TIME, WIND_VELOC
ITY) VALUES (substr(R_SENID,6,5), R_TIME, R_V);
when 37 then
INSERT INTO GW.WEATHER_REALTEMP_DATA (STATION_CODE,DATE_TIME, TEMPERATURE) VALUES (substr(R_SENID,6,5), R_TIME, R_V);
when 84 then
INSERT INTO GW.WEATHER_REALTEMP_DATA (STATION_CODE,DATE_TIME, RAIN) VALUES (substr(R_SENID,6,5), R_TIME, R_V);
when 38 then
INSERT INTO GW.WEATHER_REALTEMP_DATA (STATION_CODE,DATE_TIME, HUMIDITY) VALUES (substr(R_SENID,6,5), R_TIME, R_V);
when 9 then
INSERT INTO GW.WEATHER_REALTEMP_DATA (STATION_CODE,DATE_TIME, PRESSURE) VALUES (substr(R_SENID,6,5), R_TIME, R_V);
else null;
end case;
ELSE
case(mod(R_senid,100))
when 39 then
UPDATE GW.WEATHER_REALTEMP_DATA SET WIND_DIRECTION = R_V WHERE STATION_CODE = substr(R_SENID,6,5) AND DATE_TIME = R_TIME ;
when 81 then
UPDATE GW.WEATHER_REALTEMP_DATA SET WIND_VELOCITY = R_V WHERE STATION_CODE = substr(R_SENID,6,5) AND DATE_TIME = R_TIME ;
when 37 then
UPDATE GW.WEATHER_REALTEMP_DATA SET TEMPERATURE = R_V WHERE STATION_CODE = substr(R_SENID,6,5) AND DATE_TIME = R_TIME ;
when 84 then
UPDATE GW.WEATHER_REALTEMP_DATA SET RAIN = R_V WHERE STATION_CODE = substr(R_SENID,6,5) AND DATE_TIME = R_TIME ;
when 38 then
UPDATE GW.WEATHER_REALTEMP_DATA SET HUMIDITY = R_V WHERE STATION_CODE = substr(R_SENID,6,5) AND DATE_TIME = R_TIME ;
when 9 then
UPDATE GW.WEATHER_REALTEMP_DATA SET PRESSURE = R_V WHERE STATION_CODE = substr(R_SENID,6,5) AND DATE_TIME = R_TIME ;
else null;
end case;
END IF;
END;
end;
写了第一个给你,都一样的,下面也是的,sqlserver里面有:new和:old,只能用inserted,deleted虚表来替代,所以可能麻烦一点,但是原理都是一样的哦。有问题扰枯再追问吧,望采纳。
if (object_id('TRI_HOURDB2REALTEMP', 'TR') is not null)
drop trigger TRI_HOURDB2REALTEMP
go
create trigger TRI_HOURDB2REALTEM
on t3 after insert,update
as
declare
@SENID varchar(1),
@TIME date,
敬如 @v varchar(1),
缓稿洞 @AVGV varchar(1),
@MAXV varchar(1)
....--把列都定义好
select @SENID=SENID,@TIME=TIME,@V=V,@AVGV=AVGV,@MAXV=MAXV,... from inserted;--把列都赋值
exec HOURDB_TO_REALTEMP @SENID,@TIME,@V,@AVGV,@MAXV,...;
go