plsql assignments1-4
plsql assignments1-4
declare
v_exp number;
v_sal number;
new_sal number;
cursor cur_v is select empno,ename,job,hiredate,sal from emp;
begin
for i in cur_v
loop
v_exp := months_between(sysdate,i.hiredate)/12;
--dbms_output.put_line(v_exp);
if v_exp < 2
then new_sal := i.sal + 0.15*i.sal;
elsif v_exp >2 and v_exp<4
then new_sal := i.sal + 0.25*i.sal;
elsif v_exp > 4
then new_sal := i.sal + 0.35*i.sal;
end if;
dbms_output.put_line(i.ename||' '||i.job||' '||i.sal||' '||new_sal);
update emp set sal = new_sal where empno = i.empno;
end loop;
end;
-----------3-------------
1 declare
2 grade char;
3 nam emp.ename%type;
4 salary emp.sal%type;
5 begin
6 select ename,sal into nam,salary from emp where empno = 7839;
7 case
8 when salary>25000 then grade := 'a';
9 when salary>15000 then grade := 'b';
10 else grade := 'c';
11 dbms_output.put_line(nam||' '||salary||' '||grade);
12 end case;
13* end;
SQL> /
KING 5000 c
--------------2---------------
1 declare
2 emid emp.empno%type :=&id;
3 eid number;
4 begin
5 select empno into eid from emp where empno=emid;
6 if eid = emid then dbms_output.put_line('emp id found');
7 else dbms_output.put_line('emp id not found');
8 end if;
9* end;
--------------4----------------
declare
cursor c_emp is select * from emp where sal>2000;
v_emp c_emp%rowtype;
begin
open c_emp;
loop
fetch c_emp into v_emp;
exit when c_emp %notfound;
dbms_output.put_line(v_emp.ename||' '||v_emp.sal);
end loop;
close c_emp;
end;
-----------------5---------------
declare
cur_var sys_refcursor;
dno departments.department_id%type;
dname departments.department_name%type;
begin
dbms_output.put_line('dept no less than 40');
open cur_var for select department_id,department_name from departments where
department_id<40;
loop
fetch cur_var into dno,dname;
exit when cur_var%notfound;
dbms_output.put_line(dno||' '||dname);
end loop;
close cur_var;
dbms_output.put_line('
');
dbms_output.put_line(dno||' '||dname);
end loop;
close cur_var;
end;
-----------------6-----------------
declare
v_ename employees.first_name%type;
v_ejob employees.job_id%type;
cursor emp_cursor is select first_name,job_id from employees;
begin
open emp_cursor;
loop
fetch emp_cursor into v_ename,v_ejob;
exit when emp_cursor%rowcount>5;
dbms_output.put_line(v_ename||' '||v_ejob);
end loop;
close emp_cursor;
end;
----------------7-----------------
begin
top_earner(5);
end;
KING 5000
FORD 3000
SCOTT 3000
JONES 2975
BLAKE 2850
---------------8---------------
---------------9---------------
----------------or-----------
begin
cred_elig_status;
end;
10
----------------11-----------------
------------------12-----------------
create or replace function check_dept(dept_num number)
return boolean
is
eid dept.deptno%type;
begin
select count(*) into eid from dept where deptno=dept_num;
if eid =0 then return false;
else return true;
end if;
end;
create or replace procedure my_emp(emp_no emp.empno%type,emp_name emp.ename%type,
work_type emp.job%type,m_num emp.mgr%type,joining_date emp.hiredate%type,
salary emp.sal%type,commission emp.comm%type,dept_no emp.deptno%type)
is
value boolean;
begin
value := check_dept(dept_no);
if value = false then dbms_output.put_line('no such dept');
else
insert into emp
values(emp_no,emp_name,work_type,m_num,joining_date,salary,commission,dept_no);
dbms_output.put_line('insertion of date completed');
end if;
end;
begin
my_emp(5680,'sowmya','hr',7839,'10-07-2001',5000,1000,40);
end;
------------------13----------------
begin
proc_auth;
end;
----------------------14--------------------
-------package sequence---------
------------package body-------------
------function implementation
--------procedure implementation
begin
trans_pkg.proc_trans(1234567890,'debit',500);
end;
----------------------15----------------------