0% found this document useful (0 votes)
184 views

Oracle Lab Exercise SQL: Practice 1

The document contains an Oracle SQL lab exercise with multiple questions testing SQL skills. It includes questions on the SELECT statement, identifying errors, displaying table structures and data, creating queries to select specific columns, and concatenating columns. The questions range from basic to more advanced concepts like combining columns and separating results with commas.

Uploaded by

sadiya siddiqua
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
184 views

Oracle Lab Exercise SQL: Practice 1

The document contains an Oracle SQL lab exercise with multiple questions testing SQL skills. It includes questions on the SELECT statement, identifying errors, displaying table structures and data, creating queries to select specific columns, and concatenating columns. The questions range from basic to more advanced concepts like combining columns and separating results with commas.

Uploaded by

sadiya siddiqua
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

Oracle Lab Exercise

SQL
Practice 1

1. Will the SELECT statement execute successfully?


True/False
SQL> SELECT ename, job, sal Salary
2 FROM emp;
Ans:True

2. Will the SELECT statement execute successfully?


True/False
SQL> SELECT *
2 FROM salgrade;
Ans: True

3. There are three coding errors in this statement. Can you identify them?
SQL> SELECT empno, ename
2 salary x 12 ANNUAL SALARY
3 FROM emp;
Ans:select empno,ename,sal*12 sal salary from emp;

4. Show the structure of the DEPT table. 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
Ans:

1
5. Show the structure of the EMP table. Create a query to display the name, job, hire date
and employee number for each employee, with employee number appearing first. Save
your SQL statement to a file named p1q7.sql.
Name Null? Type
--------- -------- -------------
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NOT NULL NUMBER(2)
Ans:

2
6. Run your query in the file p1q7.sql.
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
7499 ALLEN SALESMAN 20-FEB-81
7844 TURNER SALESMAN 08-SEP-81
7900 JAMES CLERK 03-DEC-81
7521 WARD SALESMAN 22-FEB-81
7902 FORD ANALYST 03-DEC-81
7369 SMITH CLERK 17-DEC-80
7788 SCOTT ANALYST 09-DEC-82
7876 ADAMS CLERK 12-JAN-83
7934 MILLER CLERK 23-JAN-82
14 rows selected.
Ans:

3
7. Create a query to display unique jobs from the EMP table.
JOB
-----------
ANALYST
CLERK
MANAGER
PRESIDENT
SALESMAN
Ans:

If you have time, complete the following exercises:


8. Load p1q7.sql into the SQL buffer. 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
7499 ALLEN SALESMAN 20-FEB-81
7844 TURNER SALESMAN 08-SEP-81
7900 JAMES CLERK 03-DEC-81
7521 WARD SALESMAN 22-FEB-81
7902 FORD ANALYST 03-DEC-81
7369 SMITH CLERK 17-DEC-80
7788 SCOTT ANALYST 09-DEC-82
7876 ADAMS CLERK 12-JAN-83
7934 MILLER CLERK 23-JAN-82
14 rows selected.

4
Ans:

9. 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
JAMES, CLERK
WARD, SALESMAN
FORD, ANALYST
SMITH, CLERK
SCOTT, ANALYST
ADAMS, CLERK
MILLER, CLERK
14 rows selected.
Ans:

5
If you want extra challenge, complete the following exercises:
10. 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
7654,MARTIN,SALESMAN,7698,28-SEP-81,1250,1400,30
7499,ALLEN,SALESMAN,7698,20-FEB-81,1600,300,30
7844,TURNER,SALESMAN,7698,08-SEP-81,1500,0,30
7900,JAMES,CLERK,7698,03-DEC-81,950,,30
7521,WARD,SALESMAN,7698,22-FEB-81,1250,500,30
7902,FORD,ANALYST,7566,03-DEC-81,3000,,20
7369,SMITH,CLERK,7902,17-DEC-80,800,,20
7788,SCOTT,ANALYST,7566,09-DEC-82,3000,,20
7876,ADAMS,CLERK,7788,12-JAN-83,1100,,20
7934,MILLER,CLERK,7782,23-JAN-82,1300,,10
14 rows selected.
Ans:

You might also like