This article is a mirror article of machine translation, please click here to jump to the original article.

View: 15555|Reply: 0

[Communication] Write a PL/SQL block to swap the salaries of any two employees

[Copy link]
Posted on 3/22/2015 11:17:17 AM | | |
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.

  1. create table yuan(
  2.        y_id number,
  3.        y_maney number
  4. );
  5. commit;

  6. insert into yuan values(1,200);
  7. insert into yuan values(2,200);
  8. insert into yuan values(3,500);
  9. insert into yuan values(4,2000);

  10. select * from yuan;

  11. declare
  12.   yc exception;
  13.   a_yuan yuan.y_id%type := '&请输a入员工号';
  14.   b_yuan yuan.y_id%type := '&请输b入员工号';
  15.   a_m yuan.y_maney%type;
  16.   b_m yuan.y_maney%type;
  17. begin
  18.    select y_maney into a_m from yuan where y_id=a_yuan;
  19.    select y_maney into b_m from yuan where y_id=b_yuan;
  20. if a_yuan=b_yuan then
  21.    raise yc;
  22.    else
  23.     update yuan set y_maney=a_m where y_id=b_yuan;
  24.     update yuan set y_maney=b_m where y_id=a_yuan;
  25.    end if;
  26. exception
  27.   when yc then
  28.   dbms_output.put_line('错误,不能和自己互换');
  29. end;
Copy code






Previous:Wusoft intranet 1433 weak password IP, can elevate the control of the host, and attach a scanning tool
Next:ORA-01008:并非所有的变量都已绑定
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com