Ameer Practicals

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

declare

Vsalary emp.sal%Type;
begin
select sal into vsalary
from emp
where ename='KING';
case vsalary
when 5000 then
Dbms_output.put_line('The salary of the employee king is' ||vsalary);
when 4000 then
Dbms_output.put_line('The salary of the employee king is' ||vsalary);
when 2000 then
Dbms_output.put_line('The salary of the employee king is' ||vsalary);
else
end case;
end;
-----------------------------------------------------------------------------------Error Trapping Functions With solutions
-------------------------------------------------------------------------------------declare
v_empno emp.empno%type:=&Empno;
V_inc emp.sal%type:=&Increment;
v_sal emp.sal%type;
e_High_salary Exception;
Begin
Select sal into v_sal
from emp
where empno=v_empno;
if V_sal>2000 then
raise e_high_salary;
end if;
update emp
set sal=sal+v_inc
where empno=v_empno;
Dbms_output.put_line('Succusfully updated the salary');
exception
when e_high_salary then
raise_application_error(-20001, 'Salary is Too high');
Dbms_output.putline('Salary is already Hign you cannot increment the salary');
end;
-------------------------------------------------------------------------------------------------------------Solution 2
--------------------------------------------------------------------------------

------------------------------Declare
error_msg varchar2(100);
Error_code number;
V_sal emp.sal%type;
Begin
select ename into v_sal
from emp
where empno=7895;
-----Exception part
exception when others then
error_msg :=Sqlerrm;
Error_code :=sqlcode;
dbms_output.put_line(error_msg ||Error_code);
end;
---------------------------------------------------------------------------------------------------------Hello World Program in Pl/SQL
---------------------------------------------------------------------------------------------------------Create or replace procedure Helloworld is
X Vachar2(200);
Begin
x :='Hello World';
Dbms_output.Put_line(X);
end;
-----------------------------------------------------------------------------------------------------------Program for incrementing the salaries according to Jobs of the e
mployees.
------------------------------------------------------------------------------------------------------------Create procedure salary_increment as
v_job emp.Job%type;
v_sal emp.Sal%type;
v_empno emp.empno%type:=7782;
v_Increment emp.sal%type;
V_new_salary emp.Sal%type;
begin
select job,sal into v_job, V_sal from emp
where empno=v_empno;
case v_job
when 'MANAGER' THEN

if v_sal<2500 then
v_increment :=0.50;
else v_increment :=0;
enf if;
when 'CLARK' then
if v_sal<1000 then
v_increment :=0.10;
else v_increment :=0;
end if;
end case;
if (v_increment <> 0) then
v_new_salary := v_sal+v_sal*v_increment;
dbms_output.put_line('The incremented salary is' :v_new_salary || 'The old salar
y was ' :v_sal);
else
dbms_output.put_line ('No Hike');
end if;
end;
------------------------------------------------------------------------------------------Procedure with Parameters ---IN-OUT-INOUT Modes
------------------------------------------------------------------------------------------Create or replace procedure inparametermode
( P_Name in varchar2(100)) as
x vachar2(100);
begin
x:=P_name;
dbms_output.put_line(x);
End inparametermode;
Execution on toad
----------------begin
inparametermode('My name is Ameer');
End;
Output:
------My name is Ameer
------------------------------------------------------------------------------------------------With out parameter example
------------------------------------------------------------------------------------------------create or replace procedure outparameteraddition
(
P_A in number;
P_B in number;
P_c out Number) as
begin

p_c:=P_A+P_B;
end outparameteraddition
Calling the procedure
--------------------declare
x Number;
Begin
outparameteraddition(7,8,x)
dbms_output.Put_line(x);
end;
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

You might also like