Oracle Practical
Oracle Practical
Oracle Practical
Practical
1. Select all information from SALGRADE table. GRADE LOSAL HISAL -----------------------------------1 700 1200 2 1201 1400 3 1401 2000 4 2001 3000 5 3001 9999 HIREDATE ------------17-DEC-80 20-FEB-81 22-FEB-81 02-APR-81 28-SEP-81 01-MAY-81 09-JUN-81 19-APR-87 17-NOV-81 08-SEP-81 23-MAY-87 03-DEC-81 03-DEC-81 23-JAN-82 SAL --------800 1600 1250 2975 1250 2850 2450 3000 5000 1500 1100 950 3000 1300 COMM ---------300 500 1400 DEPTNO -----------20 30 30 20 30 30 10 20 10 30 20 30 20 10
2. Select all information from the EMP table. EMPNO ENAME JOB MGR ------------ -----------------------------7369 SMITH CLERK 7902 7499 ALLEN SALESMAN 7698 7521 WARD SALESMAN 7698 7566 JONES MANAGER 7839 7654 MARTIN SALESMAN 7698 7698 BLAKE MANAGER 7839 7782 CLARK MANAGER 7839 7788 SCOTT ANALYST 7566 7839 KING PRESIDENT 7844 TURNER SALESMAN 7698 7876 ADAMS CLERK 7788 7900 JAMES CLERK 7698 7902 FORD ANALYST 7566 7934 MILLER CLERK 7782 14 rows selected. 3.
List all employees with the EMPNO, ENAME, SAL and DEPTNO columns. EMPNO ENAME SAL DEPTNO ------------ --------------------------------7369 SMITH 800 20 7499 ALLEN 1600 30 7521 WARD 1250 30 7566 JONES 2975 20 7654 MARTIN 1250 30 7698 BLAKE 2850 30 7782 CLARK 2450 10 7788 SCOTT 3000 20 7839 KING 5000 10 7844 TURNER 1500 30 7876 ADAMS 1100 20 7900 JAMES 950 30 7902 FORD 3000 20 7934 MILLER 1300 10 List DEPARTMENT NO and DEPARTMENT NAME from the DEPT table DEPTNO DNAME ------------ -------------------10 ACCOUNTING 20 RESEARCH 30 SALES 40 OPERATIONS
4.
6.
7.
8.
13. List the employee name and salary increased by 15% and expressed as a whole number. DEPTNO ENAME SAL PCTSAL ---------- ---------------------------20 SMITH 800 920 30 ALLEN 1600 1840 30 WARD 1250 1438 20 JONES 2975 3421 30 MARTIN 1250 1438 30 BLAKE 2850 3278 10 CLARK 2450 2818 20 SCOTT 3000 3450 10 KING 5000 5750 30 TURNER 1500 1725 20 ADAMS 1100 1265 30 JAMES 950 1093 20 FORD 3000 3450 10 MILLER 1300 1495 14 rows selected. 14. Display all employees names which have TH or LL in them. ENAME -----------SMITH ALLEN MILLER
6 rows selected. 43. Who are the top 3 earners in the company? Display their name and salary. ENAME SAL ------------------SCOTT 3000 KING 5000 FORD 3000 44. In which year did most people join the company? Display the year and number of employees. YEAR NUMBER_OF_EMPLOYEES ---------------------1981 10 45. Write a query to display an * against the row of the most recently hired employee. Display ename, hiredate and column maxdate. Display the result in hiredate order. ENAME HIREDATE M -----------------SMITH 17-DEC-80 ALLEN 20-FEB-81 WARD 22-FEB-81 JONES 02-APR-81 BLAKE 01-MAY-81 CLARK 09-JUN-81 TURNER 08-SEP-81 MARTIN 28-SEP-81 KING 17-NOV-81 FORD 03-DEC-81 JAMES 03-DEC-81 MILLER 23-JAN-82 SCOTT 19-APR-87 ADAMS 23-MAY-87 * 14 rows selected. 46. Create a table called projects with columns as specified below. In addition define projid as the PRIMARY KEY column and ensure that p_end_date dates are not earlier than p_start_date dates. Column Name Data Type Size -----------------------------------------------------PROJID NUMBER 4 P_DESC VARCHAR2 20 P_START_DATE DATE P_END_DATE DATE BUDGET_AMOUNT NUMBER 7, 2 MAX_NO_STAFF NUMBER 2 47. Create a second table assignments as shown below. Define its projid column as a FOREIGN KEY which references the project table. Your tables empno column is further FOREIGN KEY to emp. These two columns (projid and empno) should not allow NULL values. Column Name Data Type Size -----------------------------------------------------PROJID NUMBER 4 EMPNO NUMBER 4 A_START_DATE DATE A_END_DATE DATE BILL_RATE NUMBER 4, 2 ASSIGN_TYPE VARCHAR2 2
53. Update assignment type to read WT instead of WR. A type of PF should be left unchanged. 54. Insert two more projects with assignments of your own choice. 55. Define a View which will produce the following output when referenced in a query. DEPTNO AVERAGE MAXIMUM MINIMUM SUM NO_SALS ------------------------------------------------------10 2916.66667 5000 1300 8750 3 20 2175 3000 800 10875 5 30 1566.66667 2850 950 9400 6 NO_COMMS ---------0 0 4
56. Using the View from question 1, extract the following information. Employee number should be entered at run-time. Enter value for empno: 7902 old 1: select emp.empno, ename, job, sal, hiredate, minimum, maximum, average from emp, aggre where emp.deptno = aggre.deptno and emp.empno = &empno new 1: select emp.empno, ename, job, sal, hiredate, minimum, maximum, average from emp, aggre where emp.deptno = aggre.deptno and emp.empno = 7902 EMPNO ---------7902 ENAME ---------FORD JOB --------ANALYST SAL --------3000 HIREDATE --------03-DEC-81 MINIMUM ---------800 MAXIMUM ---------3000 AVERAGE ---------2175
57. Create a View to enforce the following restrictions when Inserting data into the assignments table. a. Projid must be less than 2000. b. End date must be after Start date. c. Valid assign_types are PF, WT, ED. d. Bill_rate is less than 50.00 from assign_type Pf, less than 60.00 fro assign_type WT, less than 70.00 for assign_type ED. e. Empno must be valid. f. Remember WITH CHECK OPTION clause. 58. Insert minimum 3 records satisfying all the assign_type into assignments table using the View created.
10
59. Query the Data Dictionary to see your view. 60. Remove the created view and check whether the based table is affected or not. 61. Create a Non Unique Index on the projid column of the assignments table. 62. Query the appropriate Data Dictionary table to display information about your Indexes. 63. Drop the Index. 64. Create a Sequence for the empno column of emp table. 65. Change the increment value to 1 in the created Sequence. 66. Use the created Sequence to Insert the values for the empno. 67. Drop the Sequence. 68. Create the Synonym.
11