0% found this document useful (0 votes)
64 views4 pages

This Is The Document For PLSQL and Its Uses ..: Salary 17000

This document discusses the use of PL/SQL functions and procedures to retrieve and update employee data stored in a database table. It includes a function that checks if an employee's salary meets a given minimum. It also contains procedures that use cursors to iterate through employee records and update salaries based on department. The final procedure demonstrates updating salaries by 10% for employees in a certain department.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views4 pages

This Is The Document For PLSQL and Its Uses ..: Salary 17000

This document discusses the use of PL/SQL functions and procedures to retrieve and update employee data stored in a database table. It includes a function that checks if an employee's salary meets a given minimum. It also contains procedures that use cursors to iterate through employee records and update salaries based on department. The final procedure demonstrates updating salaries by 10% for employees in a certain department.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

ThisisthedocumentforPlsqlanditsuses..

createorreplacefunctionemployee_details(p_empnumnumber,p_salary
number)returnnumberis
v_first_namevarchar2(100);
v_last_NAMEVARCHAR2(100);
V_SALARYNUMBER;
eMP_SALEXCEPTION;
begin
selectfirst_name
,last_NAME
,SALARY
intov_first_name
,v_last_NAME
,V_SALARY
fromsystem.emp
whereemployee_id=p_empnum;
salary=17000
IFV_SALARY<p_salaryTHEN
raiseeMP_SAL;
else
DBMS_OUTPUT.PUT_LINE('NameofEmployee:'||v_first_name||v_last_NAME);
return1;
ENDIF;
andrownum=1;
exception
wheneMP_SALthen
DBMS_OUTPUT.PUT_LINE('fromNOEMPExceptionSALARYIDLESSTHAT'||p_salary);
return0;
whenno_DATA_FOUNDthen
DBMS_OUTPUT.PUT_LINE('fromno_datefoundExceptionSALARYIDLESSTHAT'||
p_salary);
DBMS_OUTPUT.PUT_LINE('SQLCODE'||SQLCODE);
DBMS_OUTPUT.PUT_LINE('SQLERRM'||SQLERRM);
return0;
whenothersthen
DBMS_OUTPUT.PUT_LINE('fromOthersExceptionSALARYIDLESSTHAT'||p_salary);
end;

declare
v_first_namevarchar2(100);
v_last_NAMEVARCHAR2(100);
V_SALARYNUMBER;
eMP_SALEXCEPTION;
begin
selectfirst_name
,last_NAME
,SALARY
intov_first_name

,v_last_NAME
,V_SALARY
fromsystem.emp
whereemployee_id=1300;
salary=17000
IFV_SALARY<5000THEN
raiseeMP_SAL;
ENDIF;
andrownum=1;
DBMS_OUTPUT.PUT_LINE('NameofEmployee:'||v_first_name||v_last_NAME);
exception
wheneMP_SALthen
DBMS_OUTPUT.PUT_LINE('fromNOEMPExceptionSALARYIDLESSTHAT5000');
whenno_DATA_FOUNDthen
DBMS_OUTPUT.PUT_LINE('fromno_datefoundExceptionSALARYIDLESSTHAT5000');
DBMS_OUTPUT.PUT_LINE('SQLCODE'||SQLCODE);
DBMS_OUTPUT.PUT_LINE('SQLERRM'||SQLERRM);
whenothersthen
DBMS_OUTPUT.PUT_LINE('fromOthersExceptionSALARYIDLESSTHAT5000');
end;

cursor
begin
updatesystem.emp
setsalary=2800
whereemployee_id=:p_empnum;
ifSQL%FOUNDthen
DBMS_OUTPUT.PUT_LINE('Rowfound:');
else
DBMS_OUTPUT.PUT_LINE('Rownotfound:');
endif;
end;

commit

rollback
select*fromsystem.emp
whereemployee_id=:p_empnum;

declare
cursorc_allempis
selectemployee_id

,DEPARTMENT_ID
fromsystem.emp
whereDEPARTMENT_ID=10;
v_deptnonumber;
v_empidnumber;
begin
OPENc_allemp;Opencursor

loop

FETCHc_allempINTOv_empid,v_deptno;fetchvalues

EXITWHENc_allemp%NOTFOUNDISNULL;

ifv_deptno=10then

updatesystem.emp
setsalary=2000
whereemployee_id=v_empid;

commit;

elsifv_deptno=20then

updatesystem.emp
setsalary=4000
whereemployee_id=v_empid;
commit;
else

null;

endif;

endloop;

CLOSEc_allemp;closecursor
end;

declare
cursorc_allempis
selectemployee_id
,DEPARTMENT_ID
,salary
fromsystem.emp;
whereDEPARTMENT_ID=10;
v_salarynumber;
begin
DBMS_OUTPUT.PUT_LINE('hi');
foriinc_allemp
loop

ifi.DEPARTMENT_ID=20then

DBMS_OUTPUT.PUT_LINE('beforesalary:'||i.Salary);
updatesystem.emp
setsalary=salary+(salary/10)
whereemployee_id=i.employee_id;

selectsalary
intov_salary
fromsystem.emp
whereemployee_id=i.employee_id;

DBMS_OUTPUT.PUT_LINE('aftersalary:'||v_salary);

endif;

endloop;

end;

You might also like