2015-08-21 72 views
-2

我想編寫一個PROCEDURE,它將首先打印員工的員工編號和工資(即7839)。 然後,它會增加僱員7839的薪水(這將是在表中僱員僱員 號),按照以下條件:使用HR數據庫的步驟

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; 
/
+0

BTW哪裏是'where'條件? – Crazy2crack

+0

不知道如何寫它 – Shak

+0

給我們表名和它們如何相互關聯如何? – mmmmmpie

回答

0

試試這個其他人與返回的條款去添加例外塊

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; 
/
+0

嘗試在您的程序中執行相同的步驟@Shak – Nepolian

+0

您試過了!@Shak – Nepolian