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

Salary 17000: Dbms - Output - Put - Line

The document contains PL/SQL code that defines functions and procedures to retrieve and update employee data from a database table. It includes: 1) A function that takes an employee number and salary as parameters, looks up the employee's information, and checks if their salary is less than the parameter salary, returning 1 if true or raising an exception otherwise. 2) A procedure that uses a cursor to iterate through employees in a department, update their salaries based on the department, and commit the changes. 3) Another procedure that iterates through all employees, increases salaries in one department by 10% and outputs the results.
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)
75 views4 pages

Salary 17000: Dbms - Output - Put - Line

The document contains PL/SQL code that defines functions and procedures to retrieve and update employee data from a database table. It includes: 1) A function that takes an employee number and salary as parameters, looks up the employee's information, and checks if their salary is less than the parameter salary, returning 1 if true or raising an exception otherwise. 2) A procedure that uses a cursor to iterate through employees in a department, update their salaries based on the department, and commit the changes. 3) Another procedure that iterates through all employees, increases salaries in one department by 10% and outputs the results.
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

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