-------------------------------触发器测试---------------------------------------- ----创建测试表 CREATE TABLE ZYJ_CS ( ID INT , NAME NVARCHAR2(20) ); --插入测试数据 INSERT INTO ZYJ_CS(ID,NAME) VALUES (1,'测试'); INSERT INTO ZYJ_CS(ID,NAME) VALUES (2,'测试2'); INSERT INTO ZYJ_CS(ID,NAME) VALUES (3,'测试3'); COMMIT; SELECT * FROM ZYJ_CS; --创建备份表 CREATE TABLE ZYJ_CS_BK AS SELECT * FROM ZYJ_CS WHERE 1=0; SELECT * FROM ZYJ_CS_BK; --创建触发器 CREATE OR REPLACE TRIGGER TG_ZYJ_CS_DEL BEFORE DELETE ON ZYJ_CS FOR EACH ROW BEGIN INSERT INTO ZYJ_CS_BK(ID,NAME)VALUES(:OLD.ID,:OLD.NAME); END ; --触发器测试 SELECT * FROM ZYJ_CS_BK WHERE ID=1; DELETE FROM ZYJ_CS WHERE ID=1; COMMIT; SELECT * FROM ZYJ_CS_BK WHERE ID=1; --删除表 DROP TABLE ZYJ_CS; DROP TABLE ZYJ_CS_BK; -------------------------------有参带返回值函数---------------------------------------- --创建有参函数,返回三数最大值 CREATE OR REPLACE FUNCTION FN_GETMAX( NUM1 IN NUMBER, NUM2 IN NUMBER, NUM3 IN NUMBER ) RETURN NUMBER AS MAXNUM NUMBER :=0; BEGIN SELECT GREATEST(GREATEST(NUM1,NUM2),NUM3) INTO MAXNUM FROM DUAL; RETURN MAXNUM; END ; --调用 SELECT FN_GETMAX(23,45,89) AS 最大值 FROM DUAL;