Вы находитесь на странице: 1из 3

Database System Lab 01

MCS Fall 19 (Afternoon)


Instructor: Hareem Aslam TA: Ahsan Ali
Time: 120 min Marks: 60

Instructions:
• Work on this lab individually. Discussion is not allowed.
• Evaluation will be conducted within lab
• Anyone caught being indulged in the act of plagiarism would
be awarded F grade in this lab.

1. Open the following URL in any Browser to access the Oracle Database Server.
http://databasesrv/isqlplus
2. Initiate a SQL*Plus session using the user ID and password provided by the instructor
3. Open and Select the SampleDB.sql database file to load sample database and test database file.
4. Test and explore database file by Executing the SELECT statement.

SQL> SELECT ename, job, sal


2 FROM emp;

5. Run these queries:

SQL> SELECT *
2 FROM emp;

SQL> SELECT empno


2 FROM emp;

SQL> SELECT empno, ename, job


2 FROM emp;

SQL> SELECT ename, sal+100


2 FROM emp;

SQL> SELECT ename, sal*2/100 “TAX”


2 FROM emp;

SQL> SELECT empno, ename, job, sal, sal*12 “Annual Sal”


2 FROM emp;

SQL> SELECT DISTINCT job


2 FROM emp;
6. There are four coding errors in this statement. Can you identify them?

SQL> SELECT empno, ename,


2 salary x 12 Annual Salary
3 FROM emp;
7. Show the structure of the DEPT table and Select all data from the DEPT table.

Name Null? Type


------------------------------------------------------------------

DEPTNO Not Null NUMBER(2)


DNAME VARCHAR2 (14)
LOC VARCHAR2(13)

DEPTNO DNAME LOC


-----------------------------------------------------------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON

8. Show the structure of the Emp table.

Name Null? Type


---------------------------------------------------------
EMPNO NOT NULL NUMBER (4)
ENAME VARCHAR2(10)
JOB VARCHAR2 (9)
MGR NUMBER (9)
HIREDATE DATE
SAL NUMBER (7, 2)
COMM NUMBER (7, 2)
DEPTNO NOT NULL NUMBER (2)

9. Create a query to display the name, job, hire date, and employee number for each employee. with
employee number appearing first.

EMPNO ENAME JOB HIREDATE


-----------------------------------------------------------------------
7839 KING PRESIDENT 17-NOV-81
7698 BLAKE MANAGER 01-MAY-81
7782 CLARK MANAGER 09-JUN-81
7566 JONES MANAGER 02-APR-81
7654 MARTIN SALESMAN 28-SEP-81
10. Create a query to display unique jobs from the EMP table.
JOB
--------------
ANALYSIT
CLERK
MANAGER
PRESIDENT
SALESMAN

11. Name the column headings Emp#, Employee, Job, and Hire Date. respectively. Rerun your query
Emp # Employee Job HIRE DATE
--------------------------------------------------------------------------
7839 KING PRESIDENT 17-NOV-81
7698 BLAKE MANAGER 01-MAY-81
7782 CLARK MANAGER 09-JUN-81
7566 JONES MANAGER 02-APR-81
7654 MARTIN SALESMAN 28-SEP-81

12. Display the name concatenated with the job. Separated by a comma and space, and name the
column Employee and Title.
Employee and Title
-------------------------
KING, PRESIDENT
BLAKE, MANAGER
CLARK, MANAGER
JONES, MANAGER
MARTIN, SALESMAN
ALLEN, SALESMAN
TURNER, SALESMAN

13. Create a query to display all the data from the EMP table. Separate each column by a comma.
Name the column THE_OUTPUT.

THE_OUTPUT
-------------------------------------------------------------------
7839, KING, PRESIDENT, 17-NOV-81, 5000, 10
7698, BLAKE, MANAGER, 7839, 01-MAY-81, 2850, 30
7782, CLARK, MANAGER, 7839, 09-JUN-81, 2450, 10
7566, JONES, MANAGER, 7839, 02-APR-81, 2975, 20

Good Luck

Вам также может понравиться