海信家电”换帅 “ 高玉玲接替代慧忠出任新任董事长
2024-11-22
create table emp (emp_id number(5), emp_name varchar2(20), emp_salary number(4)); |
create table dept (dept_id number(3), dept_name varchar2(20), emp_id number(5)); |
/*给emp表添加记录的存储过程*/ create or replace procedure ins_table_emp(p_emp_id number,p_emp_name varchar2,p_emp_salary number) as v_emp_id number:=p_emp_id; v_emp_name varchar2(20):=p_emp_name; v_emp_salary number:=p_emp_salary; begin insert into emp values (v_emp_id,v_emp_name,v_emp_salary); end ins_table_emp; /*给dept表添加记录的存储过程*/ create or replace procedure ins_table_dept(p_dept_id number,p_dept_name varchar2,p_emp_id number) as v_dept_id number:=p_dept_id; v_dept_name varchar2(20):=p_dept_name; v_emp_id number:=p_emp_id; begin insert into dept values (v_dept_id,v_dept_name,v_emp_id); end ins_table_emp; /*调用相应的存储过程实现记录添加*/ begin ins_table_emp(10000,'',4000); ins_table_emp(10001,'??èy',2300); ins_table_emp(10002,'3?t',3500); ins_table_emp(10003,'à???',3500); ins_table_emp(10004,'á?ò?',3500); ins_table_dept(111,'DD?t2?',10000); ins_table_dept(111,'DD?t2?',10001); ins_table_dept(111,'DD?t2?',10002); ins_table_dept(112,'??ê?2?',10003); ins_table_dept(113,'êD3?2?',10004); end; |
create or replace procedure add_salary(p_dept_name varchar2) as v_dept_name varchar2(20):=p_dept_name; begin update emp set emp.EMP_SALARY=emp.EMP_SALARY*1.2 where emp.EMP_ID in (select emp.EMP_ID from emp,dept where emp.EMP_ID=dept.EMP_ID and dept.DEPT_ID='??ê?2?'); end add_salary; |
create or replace trigger print_salary_change before delete or insert or update on emp--触发事件 for each row-- 每修改一行都需要调用此过程 declare --只有触发器的声明需要declare,过程和函数都不需要 salary_balance number; begin --:new 与:old分别代表该行在修改前和修改后的记录 salary_balance=:new.salary=:old.salary; dbms_output.PUT_LINE('old salary is: '|| :old.salary); dbms_output.PUT_LINE('old salary is: '|| :new.salary); dbms_output.PUT_LINE('old salary is: '|| to_char(salary_balance)); end print_salary_change; |
/*包头部分*/ create or replace package debug as procedure debug(v_description varchar2,v_valueOfvariable varchar2) procedure reset; v_numberOfLine number; end debug; /*包体部分*/ create or replace package body debug as procedure debug(v_description varchar2,v_valueOfvariable varchar2) is begin insert into debugtable values(v_numberOfLine,v_description,v_valueOfvariable); v_numberOfLine:=v_numberOfLine+1; end debug; procedure reset is begin v_numberOfLine:=1; delete from debugtable; end reset; /*初始化部分*/ begin reset; end debug; |
评论 {{userinfo.comments}}
{{child.content}}
{{question.question}}
提交