最近学习pl/sql,文章中的一个例子没有实验成功,后来仔细读文章才发现原来是11g的新特性
10g的代码如下
- CREATE OR REPLACE TRIGGER emp_tri
- BEFORE INSERT ON employees
- FOR EACH ROW
- DECLARE
- v_employee_id employees.employee_id%type;
- BEGIN
- select employees_seq.nextval into
- v_employee_id from dual;
- :NEW.EMPLOYEE_ID:=v_employee_id;
- :NEW.EMAIL:='xxx@163.com';
- :NEW.PHONE_NUMBER:='110.110.110';
- :NEW.HIRE_DATE:=SYSDATE;
- :NEW.JOB_ID:='SH_CLERK';
- :NEW.MANAGER_ID:=124;
- :NEW.DEPARTMENT_ID:=50;
- END;
-
- insert into employees(first_name,last_name,salary)
- values('li','qu',20000);
11g对sequence引用方便多了
- CREATE OR REPLACE TRIGGER emp_tri
- BEFORE INSERT ON employees
- FOR EACH ROW
- BEGIN
- :NEW.EMPLOYEE_ID:=employees_seq.nextval;
- :NEW.EMAIL:='xxx@163.com';
- :NEW.PHONE_NUMBER:='110.110.110';
- :NEW.HIRE_DATE:=SYSDATE;
- :NEW.JOB_ID:='SH_CLERK';
- :NEW.MANAGER_ID:=124;
- :NEW.DEPARTMENT_ID:=50;
- END;
-
- insert into employees(first_name,last_name,salary)
- values('li','qu',20000);
确实11g就连写触发器都简单了,如果简单的触发器甚至都不要学pl/sql了。
阅读(1399) | 评论(0) | 转发(0) |