0% found this document useful (0 votes)
3 views3 pages

Most Asked Ques

The document outlines SQL commands to create and manage employee and department tables, including foreign key relationships. It includes data insertion for departments and employees, as well as PL/SQL blocks for joining tables and calculating average and total salaries. Additionally, it defines packages for encapsulating procedures and functions related to salary calculations.

Uploaded by

pragathish003m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Most Asked Ques

The document outlines SQL commands to create and manage employee and department tables, including foreign key relationships. It includes data insertion for departments and employees, as well as PL/SQL blocks for joining tables and calculating average and total salaries. Additionally, it defines packages for encapsulating procedures and functions related to salary calculations.

Uploaded by

pragathish003m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

create table employee(

d_no number(3) ,
foreign key (d_no) references depart(d_no),
emp_name varchar(20) not null,
emp_id number(3) primary key,
email varchar(20),
contact number(20),
salary number(3)
);

create table depart(

d_name varchar(20),
d_no number(3) primary key
);
drop table employee;
drop table depart;

insert into depart values('marketing',1);


insert into depart values('sales',2);

insert into employee values (1,'vibo',302,'[email protected]',12345678,200);


insert into employee values (2,'viboee',303,'[email protected]',12345678,400);
insert into employee values (1,'viboff',308,'[email protected]',12345678,200);

declare
eid employee.emp_id%type;
ename employee.emp_name%type;
dname depart.d_name%type;
dno depart.d_no%type;
cursor joins is
select e.emp_id,e.emp_name,d.d_name from employee e join depart d on
e.d_no=d.d_no;
begin
open joins;
loop
fetch joins into eid ,ename ,dname;
exit when joins%notfound;
DBMS_OUTPUT.PUT_LINE('course_id: ' || eid);
DBMS_OUTPUT.PUT_LINE('course: ' || ename);
DBMS_OUTPUT.PUT_LINE('d_no: ' || dno);
DBMS_OUTPUT.PUT_LINE('department name: ' || dname);
end loop;
close joins;
end;
/

DECLARE
eid employee.emp_id%TYPE;
ename employee.emp_name%TYPE;
dname depart.d_name%TYPE;
dno depart.d_no%TYPE;
CURSOR joins IS
SELECT e.emp_id, e.emp_name, d.d_name, d.d_no
FROM employee e
JOIN depart d ON e.d_no = d.d_no;
BEGIN
OPEN joins;
LOOP
FETCH joins INTO eid, ename, dname, dno;
EXIT WHEN joins%NOTFOUND;
DBMS_OUTPUT.PUT_LINE('course_id: ' || eid);
DBMS_OUTPUT.PUT_LINE('course: ' || ename);
DBMS_OUTPUT.PUT_LINE('d_no: ' || dno);
DBMS_OUTPUT.PUT_LINE('department name: ' || dname);
END LOOP;
CLOSE joins;
END;
/

create or replace package pack as


procedure avg_sal;
end pack;
/

create or replace package body pack is


procedure avg_sal
is
begin
for i in (select avg(salary) s,d_no from employee group by d_no)
loop
DBMS_OUTPUT.PUT_LINE('COUNT OF COURSE ID ' || '' || i.s||' '||''||
i.d_no );
end loop;
end avg_sal;
end pack;
/

declare
begin
pack.avg_sal();
end;
/

create package pack1 as


function display
return integer;
end pack1;
/

create or replace package body pack1 as


function display
return integer is
s_tot integer;
s integer;
begin
s_tot:=s;
for i in (select sum(salary) s,d_no from employee group by d_no)
loop
DBMS_OUTPUT.PUT_LINE('COUNT OF COURSE ID ' || '' || i.s||' '||''||i.d_no );
end loop;
return s_tot;
end display;
end pack1;
/

declare
num integer;
begin
num:=pack1.display();
end;
/

You might also like