0% found this document useful (0 votes)
24 views6 pages

Exp 1

The document outlines a PL/SQL exercise focused on creating and manipulating tables in Oracle8.0, including creating tables for jobs, employees, deposits, and loans, as well as performing various SQL queries for data retrieval, insertion, updating, and deletion. It provides specific SQL commands to execute tasks such as filtering data based on conditions, aggregating results, and managing table structures.

Uploaded by

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

Exp 1

The document outlines a PL/SQL exercise focused on creating and manipulating tables in Oracle8.0, including creating tables for jobs, employees, deposits, and loans, as well as performing various SQL queries for data retrieval, insertion, updating, and deletion. It provides specific SQL commands to execute tasks such as filtering data based on conditions, aggregating results, and managing table structures.

Uploaded by

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

Exercise Number :1

Title of the Exercise : commands in PL/SQL


Date of the Exercise :

Aim:
To Explore various commands given in PL/SQL in Oracle8.0.

1. Create Table Job (job_id, job_title, min_sal, max_sal);

2. Create table Employee (emp_no, emp_name, emp_sal, emp_comm, dept_no);

3. Create table deposit(a_no,cname,bname,amount,a_date);

4. Create table borrow(loanno,cname,bname,amount);


1. Insert following values in the table Employee.

2. Insert following values in the table job.

3. Insert following values in the table deposit.

4. Insert following values in the table Borrow.


Perform following queries
1. Retrieve all data from employee, jobs and deposit.

SELECT * FROM EMPLOYEE;


SELECT * FROM JOB;
SELECT * FROM DEPOSIT;
SELECT * FROM BORROW;
2. Give details of account no. and deposited rupees of customershaving account opened between
dates 01-01-06 and 25-07-06.

SELECT ACC_NO, AMMOUNT FROM DEPOSITE WHERE ADATE BETWEEN ‘1-JAN-06’


AND ’25- JUL-06’;
3. Display all jobs with minimum salary is greater than 4000.

SELECT * FROM JOB WHERE MIN_SAL > 4000.

4. Display name and salary of employee whose department no is 20. Give alias name to name of
employee.

SELECT EMP_NAME AS “NAME”,EMP_SAL FROM EMPLOYEE WHERE DEPT_NO=20;

5. Display employee no,name and department details of thoseemployee whose department lies
in(10,20)

SELECT EMP_NO,EMP_NAME,DEPT_NO FROM EMPLOYEE WHERE DEPT_NO IN (10,20);


6. Display all employee whose name start with ‘A’ and third character is ‘‘a’.

SELECT * FROM EMPLOYEE WHERE EMP_NAME LIKE ‘A_a%’;

7. Display name, number and salary of those employees whose name is 5 characters long and first
three characters are ‘Ani’.

SELECT EMP_NAME,EMP_NO,EMP_SAL FROM EMPLOYEE WHERE EMP_NAME LIKE


‘Ani_______’;

8. Display the non-null values of employees and also employee name second character should be ‘n’
and string should be 5 character long.

SELECT * FROM EMPLOYEE WHERE EMP_COMM IS NOT NULL AND EMP_NAME LIKE
‘__n__’;
9. Display the null values of employee and also employee name’s third character should be ‘a’.

SELECT * FROM EMPLOYEE WHERE EMP_COMM IS NULLAND EMP_NAME LIKE


‘____a%’;

10. What will be output if you are giving LIKE predicate as ‘%\_%’ ESCAPE‘\’

SELECT * FROM JOB WHERE JOB_ID LIKE ‘%\_%’ ESCAPE ‘\’;

11. List total deposit from deposit.

SELECT SUM (AMOUNT) FROM DEPOSIT;

12. List total loan from karolbagh branch.

SELECT SUM (AMOUNT) FROM BORROW WHERE BNAME='KAROLBAGH';

13. Give maximum loan from branch vrce.

SELECT MAX (AMOUNT) FROM BORROW_42 WHERE BNAME=’VRCE’;

14. Count total number of customers.

SELECT COUNT (CNAME) FROM CUSTOMERS;

15. Count total number of customer’s cities.

SELECT COUNT (DISTINCT CITY) FROM CUSTOMERS;

16. Create table supplier from employee with all the columns.

CREATE TABLE SUPPLIER AS SELECT * FROM EMPLOYEE;

17. Create table sup1 from employee with first two columns.

CREATE TABLE SUP21 AS SELECT EMP_NO,EMP_NAME FROM EMPLOYEE;

18. Create table sup2 from employee with no data.

CREATE TABLE SUPPLIER23 AS SELECT * FROM EMPLOYEE WHERE EMP_NO=NULL;

19. Insert the data into sup2 from employee whose second charactershould be ‘n’ and string should
be 5 characters long in employee name field.
INSERT INTO SUP21 (EMP_NO) SELECT (EMP_NO) FROM EMPLOYEE WHERE
EMP_NAME LIKE '_____a_____';

20. Delete all the rows from sup1.

TRUNCATE TABLE SUP1;

21. Delete the detail of supplier whose sup_no is 103.

DELETE FROM SUPPLIER WHERE SUP_NO=103;

22. Rename the table sup2.

RENAME SUP2 TO SUP3;

23. Destroy table sup1 with all the data.

DROP TABLE SUP1;

24. Update the value dept_no to 10 where second character of emp. nameis ‘m’.

UPDATE EMPLOYEE SET DEPT_NO=10 WHERE EMP_NAME LIKE ‘_m%’;

25. Update the value of employee name whose employee number is 103.

UPDATE EMPLOYEE SET EMP_NAME=’DARSHAN’ WHERE EMP_NO=103;

26. Find the average salaries for each department without displayingthe respective department
numbers.

SELECT AVG(EMP_SAL) FROM EMPLOYEE GROUP BY DEPT_NO;

27. Write a query to display the total salary being paid to each job title, within each
department.

SELECT DEPT_NO,SUM(EMP_SAL) FROM EMPLOYEE GROUP BY DEPT_NO;

28. Find the average salaries > 2000 for each department without displaying the respective
department numbers.

SELECT AVG(EMP_SAL) FROM EMPLOYEE GROUP BY DEPT_NO HAVING


AVG(EMP_SAL)
> 2000;
29. List the branches having sum of deposit more than 5000 and locatedin city bombay.
SELECT D.B_NAME FROM DEPOSITE D , BRANCH B WHERE D.B_NAME =B.BNAME AND
B.CITY=’BOMBAY’ GROUP BY D.B_NAME HAVING SUM(D.AMMOUNT) > 5000;

You might also like