【发布时间】:2015-08-21 19:29:19
【问题描述】:
我想编写一个程序,首先打印员工的员工编号和薪水(即 7839)。然后它将根据以下条件增加员工 7839 的工资(这将是员工表中的员工编号):
Condition-1: If experience is more than 10 years, increase salary by 20%.
Condition-2: If experience is greater than 5 years, increase salary by 10%.
Condition-3: All others will get an increase of 5% in the salary.
该程序将在增加之前和之后打印员工编号和工资我尝试了以下步骤但不确定它有多准确..
我需要将其转换为 PROCEDURE 代码。
请指教
DECLARE
veno emp.empno%type:=&veno;
vsal emp.sal%type;
vexp number;
BEGIN
select empno,sal,trunc(to_char(months_between(sysdate,hiredate)/12))into veno,vsal,vexp from emp where empno=veno;
DBMS_OUTPUT.PUT_LINE('before update:' ||chr(10)||veno||chr(10)||vsal);
if vexp>=10 then
update emp set sal=sal+(sal*.20) where empno=veno;
select sal into vsal from emp where empno=veno;
DBMS_OUTPUT.PUT_LINE('after update:' ||chr(10)||vsal);
elsif vexp>=5 then
update emp set sal=sal+(sal*.10) where empno=veno;
select sal into vsal from emp where empno=veno;
DBMS_OUTPUT.PUT_LINE('after update:' ||chr(10)||vsal);
else
update emp set sal=sal+(sal*.05) where empno=veno;
select sal into vsal from emp where empno=veno;
DBMS_OUTPUT.PUT_LINE('after update:' ||chr(10)||vsal);
end if;
END;
/
【问题讨论】:
-
我的第一个想法是这个程序会被认为是一个匿名块,而不是一个过程。过程是可以按名称调用的存储程序。其次,虽然该程序并不漂亮,但它似乎可以根据您发布的要求运行。
-
那么,你想从你的代码中创建过程吗?
-
是的,我想用我的代码创建一个程序..请帮助
-
这是stackoverflow.com/q/32137151/272735 的副本,它不仅是重复的,而且是相同的。
标签: oracle stored-procedures plsql procedure