|
Tip: You can define two variables and enter the numbers of the two employees from the keyboard, if the two numbers are the same, throw a custom exception, otherwise the salary is swapped.
- create table yuan(
- y_id number,
- y_maney number
- );
- commit;
- insert into yuan values(1,200);
- insert into yuan values(2,200);
- insert into yuan values(3,500);
- insert into yuan values(4,2000);
- select * from yuan;
- declare
- yc exception;
- a_yuan yuan.y_id%type := '&请输a入员工号';
- b_yuan yuan.y_id%type := '&请输b入员工号';
- a_m yuan.y_maney%type;
- b_m yuan.y_maney%type;
- begin
- select y_maney into a_m from yuan where y_id=a_yuan;
- select y_maney into b_m from yuan where y_id=b_yuan;
- if a_yuan=b_yuan then
- raise yc;
- else
- update yuan set y_maney=a_m where y_id=b_yuan;
- update yuan set y_maney=b_m where y_id=a_yuan;
- end if;
- exception
- when yc then
- dbms_output.put_line('错误,不能和自己互换');
- end;
Copy code
|