日期:2014-05-16 浏览次数:20390 次
--1
CREATE TABLE GAN_TEST (
ID VARCHAR2(40) PRIMARY KEY,
NAME VARCHAR2(40) NOT NULL,
ADRRESS VARCHAR2(40),
AGE NUMBER(2),
SEX VARCHAR2(1),
CHECK (SEX IN('M','W'))
);
--2
CREATE OR REPLACE VIEW GAN_TEST_V AS
? SELECT ID,NAME,SEX FROM GAN_TEST
--3
CREATE OR REPLACE TRIGGER GAN_TEST_V_T
INSTEAD OF INSERT OR UPDATE OR DELETE ON GAN_TEST_V
? FOR EACH ROW
BEGIN
? IF INSERTING THEN
??? INSERT INTO GAN_TEST INFO(
??? INFO.ID,
??? INFO.NAME,
??? INFO.SEX)
???
?? VALUES(
??? :NEW.ID,
??? :NEW.NAME,
??? :NEW.SEX
?? );
?END IF;
?
?IF UPDATING THEN
??? UPDATE GAN_TEST T
?????? SET T.NAME = :NEW.NAME
???? WHERE T.ID = :NEW.ID;
? END IF;
?IF DELETING THEN
??? DELETE FROM GAN_TEST T
??? WHERE T.ID=:OLD.ID;
? END IF;
END;
?
--4
INSERT INTO GAN_TEST_V VALUES('1','GANLIANG2','M');?
UPDATE GAN_TEST_V T SET T.NAME='GANDDLIANG'? WHERE T.ID = '1'
DELETE FROM GAN_TEST_V WHERE ID ='1'