1. Initiate a SQL*Plus session using the user ID and password for the user you created. 2.

True or False. SQL*Plus commands access the database? FALSE 3. True or False. Will the SELECT statement execute successfully? SQL>SELECT ename, job, sal Salary 2 FROM emp; TRUE 4. True or False. Will the SELECT statement execute successfully? SQL>SELECT * 2 FROM salgrade; TRUE 5. There are four coding errors in this statement. Identify them. SQL>SELECT empno,ename salary X 12 ANNUAL SALARY 2 FROM emp; A. The EMP table does not contain a column called salary. The column is called sal. B. The multiplication operator is *, not x as shown in line 2. C. The ANNUAL SALARY alias cannot include spaces. The alias should read ANNUAL_SALARY or be enclosed in double quotation marks. D. A comma is missing after the column name ENAME. 6. Show the structure of the DEPT table. Select all data from the DEPT table. SQL> DESCRIBE dept SQL> SELECT * 2 FROM dept; 7. Show the structure of the EMP table. Create a query to display the name, jo b, hire date and employee number for each employee with employee number appearing first. Sa ve your SQL statement to a file named plq7.sql. SQL> DESCRIBE emp SQL> SELECT empno, ename, job, hiredate 2 FROM emp; SQL> SAVE p1q7.sql 8. Run your query in the plq7.sql file. SQL> START p1q7.sql 9. Create a query to display unique jobs from the EMP table. SQL> SELECT DISTINCT job 2 FROM emp; 10. Load plq7.sql into the SQL buffer. Name the column headings Emp #, Employe e, Job and Hire Date, respectively. Show how you did this.

3.sql to list the name and salary of employees who earn more than $1500 and are in department 10 or 30. 5. salary and commission for all employees who ear commission s. Label the column Employee and Month Salary. Practice 2: 1. Display the name concatenated with the job.sql to display the name and salary for all employees whose salar y is not in the range of $1500 and $2850. Display the names of all employees where the third letter of their name is . SQL> i 2i job "Job". Resave your SQL statement to a file named p2q6. Order the query in ascending order by start date. Name the column THE_OUTPUT. 2. Display the name and title of all employees who do not have a manager. 6. ' job "Employee and Title" 2 FROM emp. and start date of employees hired between February 20.' 3 comm '. 9. 7. Create a query to display all data from the EMP table.850.' ename '. Resave your SQL statement to file named p2q3. Modify p2q3. 1981 and May 1.sql SQL> 1 SELECT empno "Emp #". Run your query. 12.sql REPLACE SQL> START p1q7. 10.' job '.' sal '. Show how you did this. separated by a comma and space.sql. and name the column Employee and Title. Display the name. 4.SQL> GET p1q7. Display the name and hire date of every employee who was hired in 1982. Rerun your query. Create a query to display the employee name and department number for employ ee number 7566.sql. Separate each colum n by a comma. Rerun your query. Modify p2ql. Sort data in descending order of salary and commissions. 1981. Save your SQL statement to a file named p2ql. respectively. ename "Employee".' hiredate '. 8.sql 11. hiredate "Hire Date" 3i SQL> SAVE p1q7.' deptno THE_OUTPUT 4 FROM emp. SQL> SELECT ename '.' 2 mgr '.sql. Create a query to display the name and salary of employees earning more than $2. job. Display the employee name. Display the employee name and department number of all employee in departmen ts 10 and 30 in alphabetical order by name. SQL> SELECT empno '.

3. Create a query to display name and salary for all employees. Resave your query as p2q13. 11. A. Save your SQL statement to a f ile named p3q2. Modify your query p3q2.sql to add a column that will subtract the old salary from the new salary. Label . Display the employee's name. Rerun your query. for all employees who se name starts with J. 5. Label the column REVIEW. Format the dates to appea r in the format similar to "Sunday. Format the sal ary to be 15 characters long. 10. job and salary for all employees whose job is Clerk or Analyst and their salary is not equal to $1000. For each employee display the employee name and calculate the number of mont hs between today and the date the employee was hired. Run the query in the file p3q2. 2. Write a query that produces the following for each employee: <employee name > earns <salary> monthly but wants <3 times salary>. Display the name. Modify p2q6. Label the column Dream Salaries. 9. hire date and day of the week on which the employee start ed. hire date and salary review date which is the f irst Monday after six months of service. or M. 7.an A. the Seventh of September. Label the column MONTHS_WORKED. salary and salary increase by 15% express ed as a whole number. Label the column Date. Display the employee number. 13. 6. Display the names of all employees that have two Ls in their name and are i n department 30 or their manager is 7782. Order your results by the number of months employed. Practice 3: 1. Write a query that will display the employee's name with the first letter ca pitalized and all others letters lowercase and the length of their name. 12.sql. salary and commission for all employee s whose commission amount is greater than their salary increased by 10%.sql.sql to display the name. Label the column SALARY. $3000 or $5000. 8. Round the number of months up to the closest whole number. name. 4.sql. 1981". Label the column New Salary. Write a query to display the current date. left-padded with $. Give each column an appropriate label. Rerun your query. Display the name. Label the column Increase.

sql. If the employee does not earn commission. Display the employee name and employee number along with their manager's nam e and manager number. 3.sql. as per the table shown below JOB GRADE PRESIDENT A MANAGER B ANALYST C SALESMAN D CLERK E None of the above O Practice 4: 1. Each asterisk signifies a hundred dollars. Run p4q7. 7. 11.sql to display all employees including King. and department na me for all employees who work in DALLAS. Display the employee name and department name for all employees who have a A in their name. department number. Order the results by the day of the week starting with Mon day. Write a query to display the name. Create a unique listing of all jobs that are in department 30. department name and location of all employees who earn a commission. Create a query that displays the employees' names and indicates the amount of their salaries through asterisks. Emp#. put "No Commission". 6. Modify p4q6. department number. 4.the column DAY. who has no manager. Label the columns Employee. Sort the da ta in descending order of salary.sql. Label the column COMM. Create a query that will display the employee name. Create a query that will display the employee name and commission amount. 13. respec tively. Write a query to display the employee name. Write a query that displays the grade of all employees based on the value o f the column JOB. Resave as p4q7. Write a query to display the name. Manager and Mgr#. . Give each column an appropriate label. Save your SQL statement in a file called p4q6.sql. 8. Save your SQL statement in a file called p4q4. and a ll the employees that work in the same department as a given employee. 2. Label the column EMPLOYEE_AND_THEIR_SALARIES. department number. 12. 5. Include the location of department 30 in the output. job. and department name f or all employees.

sal FROM emp WHERE sal NOT BETWEEN 1500 AND 2850 / SQL> START p2q3. Display all employees' names and hire dates along with their manager's name and hire date for all employees who were hired before their managers. Create a query to display the name and hire date of any employee hired afte r the employee Blake. salary.9. and Mgr Hiredate. job. Label the columns Empl oyee. sal 2 FROM emp 3 WHERE sal> 2850.sql 4.sql 7. respectively. 5. SQL> EDIT p2q1. SQL> SELECT ename.sql SELECT ename. SQL> SELECT ename. SQL> SAVE p2q1. Answer 2: 1.30) / SQL> START p2q6. job. SQL> EDIT p2q3. 10.sql SELECT ename "Employees". Show the structure of the SALGRADE table. sal "Monthly Salary" FROM emp WHERE sal > 1500 AND deptno IN (10.'DD-MON-YYYY') 6 ORDER BY hiredate. 3. 11.sql 2.30) 4 ORDER BY ename. . SQL> SELECT ename. and grade for all employees. SQL> SELECT ename. 6. hiredate 2 FROM emp 3 WHERE hiredate BETWEEN 4 TO_DATE('20-Feb-1981'. deptno 2 FROM emp 3 WHERE deptno IN (10. Emp Hiredate. deptno 2 FROM emp 3 WHERE empno=7566. Create a query that will display the name. Manager. department name.'DD-MON-YYYY') AND 5 TO_DATE('01-May-1981'.

8. 13. sal. job. SQL> SELECT ename 2 FROM emp 3 WHERE ename LIKE '__A%'.0) "New Salary". ename. SQL> SELECT ename. SQL> START p3q2.sql 3. 2 FROM emp 3 WHERE job IN ('CLERK'. 12. sal. SQL> SELECT sysdate "Date" 2 FROM dual. 5000). 11. job 2 FROM emp 3 WHERE mgr IS NULL. SQL> EDIT p3q2. SQL> SELECT ename. ROUND(sal*1.sql 4. 10. sal "Monthly Salary".sql Answer 3: 1. 2 ROUND(sal*1. comm 2 FROM emp 3 WHERE comm IS NOT NULL 4 ORDER BY sal DESC.15. 2. SQL> SELECT ename 2 FROM emp 3 WHERE ename LIKE '%L%L%' 4 AND deptno=30 5 OR mgr=7782. SQL> EDIT p2q6.sql SELECT ename "Employees".15. 'ANALYST') 4 AND sal NOT IN (1000.0) "New Salary" 3 FROM emp SQL> SAVE p3q2.sql SELECT empno.1 / SQL> START p2q13. SQL> SELECT empno. hiredate 2 FROM emp 3 WHERE hiredate LIKE '%82'.SQL> SELECT ename. . comm DESC. 3000. sal. SQL> SELECT ename. ename. sal. comm FROM emp WHERE comm > sal*1. 9.

job 2 3 FROM emp. hiredate 2 TO_CHAR(hiredate. SQL> SELECT ename 2 3 4 5 6 FROM emp.00') ' monthly but wants' TO_CHAR(sal*3. 2 3 'E'. ROUND(MONTHS_BETWEEN 2 (SYSDATE.6). . SQL> SELECT RPAD(ename. 13.999. 11. SQL> SELECT INITCAP(ename) "Name". 'fm$99.' "Dream Salaries" 8. ' earns' TO_CHAR(sal. 'SALESMAN'. SQL> SELECT ename.'d'). "the" Ddspth "of" Month.00') '. 'CLERK'. SQL> SELECT ename 2 3 FROM emp NVL(TO_CHAR(comm). 'D'. hiredate)) MONTHS_WORKED 3 FROM emp 4 ORDER BY MONTHS_BETWEEN(SYSDATE. SQL> SELECT ename. 2 LENGTH(ename) "Length" 3 FROM emp 4 WHERE ename LIKE 'J%' 5 OR ename LIKE 'M%' 6 OR ename LIKE 'A%' 10.. '$') SALARY 9. SQL> SELECT job DECODE(job. YYYY') REVIEW 5 FROM emp 6. 'DAY') DAY 2 FROM emp 3 ORDER BY TO_CHAR(hiredate-1.ROUND(sal*1.'*') 2 EMPLOYEE_AND_THEIR_SALARIES 3 FROM emp 4 ORDER BY sal DESC. 15. SQL> SELECT ename. 7. 'C'.0) -sal "Increase" FROM emp / SQL> START p3q2. SQL> SELECT ename. 3 'MONDAY').8) ' ' RPAD(' '.'No Commission') COMM 12. hiredate).15. hiredate 2 TO_CHAR(NEXT_DAY(ADD_MONTHS(hiredate.999.sql 5. 4 'fmDay.sal/100+1.'fm$99. LPAD(sal. 'ANALYST'.

loc 2 FROM emp e. d. d.job.deptno=d.4 5 6 '0') GRADE 7 FROM emp. dept d 3 WHERE e.deptno. d.deptno department.ename "Employee". dept d 3 WHERE e.empno.ename. SQL> SELECT e. . m.empno "Emp#".deptno.dname 2 FROM emp e.loc 2 FROM emp e. d.empno<>c. 'A'.comm IS NOT NULL. 'B'. e. e. 4. SQL> SELECT e. e. SQL>EDIT p4q6. dept d 3 WHERE e.ename "Employee".deptno. d. SQL> SELECT e.ename "Manager".mgr=m.ename employee 2 c.deptno 4 AND e.sql 8.ename "Manager". emp m WHERE e. d. SQL> SELECT e. 6.empno(+). 2 m. SQL> SELECT e. 'PRESIDENT'. 'MANAGER'.empno "Mgr#" FROM emp e.deptno=d.job. SQL> SAVE p4q7.ename.deptno=c. dept d 3 WHERE e. dept d 3 WHERE e. m. 5.deptno.sql 7.deptno 4 AND e. SQL> SAVE p4q6.ename.sql SELECT e.deptno 4 AND e.loc='DALLAS'.deptno=d.deptno=d.ename LIKE '%A%'.empno 6 ORDER BY e. e. e.empno "Emp#".deptno 5 AND e.mgr=m.deptno=30. SQL> SELECT e.deptno 4 AND d. c.ename.dname 2 FROM emp e.ename.ename. m. Answer 4: 1. e. emp c 4 WHERE e. 3.dname 2 FROM emp e.deptno=d. SQL> SELECT DISTINCT e. e.dname. emp m 4 WHERE e.empno "Mgr#" 3 FROM emp e.ename colleague 3 FROM emp e. 2.

SQL> SELECT e.job. We can obtain these names By querying the view V$Instance.ename. when you arrange tables into logical groups.losal AND s. dept d. e sal.sal BETWEEN s. 10.hiredate 2 FROM emp.hiredate< m.deptno 4 AND e.grade 2 FROM emp e.mgr=m.hiredate. 5 AND e.ename.ename "Manager". 11. m. SQL> SELECT emp. we need to know _______ ______ And _________________________.hiredate "Mgr Hiredate" 3 FROM emp e. e. Sample Test (study guide) 1) Organizing tables into groups is good for performance. it is c alled: a) Segments d) Tablespaces b) Extents e) Partitions c) Block 2) a) Smallest unit of Disk I/O in a Database Management System Segment b) Extent e) Record c) Bit d) Block 3) a) One or more contiguous Blocks Segment b) Extent e) Record c) Bit d) Cursor 4) In JDeveloper a ___________ contains several Projects 5) To Establish an Oracle connection in Jdeveloper. emp blake 3 WHERE blake.dname.hisal. d.hiredate<emp.deptno=d. salgrade s 3 WHERE e.ename "Employee". .deptno='BLAKE' 4 AND blake. In Oracle. emp m 4 WHERE e.9. s. emp.empno. SQL> DESCRIBE salgrade SQL> SELECT e. e. security and ease of maintenance.hiredate "Emp Hiredate" 2 m.hiredate.

but not in 4NF.6) Difference between Stored Procedure. Describe them in the order that you would try them. ___________________________________________ 7) What is a cursor in PL/SQL and Embedded SQL with C ? Why do I need it ? What is the corresponding object in Java that performs the same function ? 8) If your Database is slow.edu .edu/~mguimara/3310/tfinal. describe all the mechanisms that you know that the DBA should investigate to speed it up. Then conv ert the table to 4NF. In what order should we create the tabl es ? 14) In what order should we drop the tables ? 15) A view in Oracle corresponds to what in MS-Access ? 16) Give two reasons why one would want to create a view ? 17) What is the difference between a view and a materialized view ? When do you want one or another ? 18) Concurrency and SQL questions in: http://science. Trigger and Anonym ous Blocks.doc Concurrency questions in the sample test at coffee. Stored Function.Kennesaw. 10) Give an example of a Table that is in 3NF and BCN. 11) Can a Foreign Key have Null Values Yes No 12) Can we update the value of a Primary Key ? Explain when and when not ? 13) For Employee and Department Tables. 9) :What is the difference between 3NF and Boyce-Codd Normal Form ? Answer by giving an example of a Table that is in 3NF but is not in 4NF.kennesaw.

Exhibition. populate the database. To simplify the assignm ent. execute tr iggers and methods. 3. 2. and execute queries. Exhibition must store a nested table of REFs to ArtObjects. A trigger must be implemented on the ArtObject side of the createdBy relation ship to update the inverse of the relationship when the artist of an object is i nitialized or modified. ArtObject and Artist must be implemented as object tables. 6. You will need to implement procedures to add and remove individual objects to/from the nested tab le. You can assume that the createdBy relationship will only be set on the ArtObject side of the relationship. where and when is this clause applied ? 22) Explain the clause For Update and NOWAIT. you will be using the SQL Plus environment to create the appropriate databa se schema. 4. Using the UML diagram of the Art Museum enterprise on the following page. establish and modify relationships between objects. modify attribute v alues of objects. objectCount must be implemented as a function that returns the number of art . Artist must store a VARRAY of REFs to ArtObjects for the inverse of the creat edBy relationship. 7. and query information about objects. 5. 23) What are the three blocks (parts) of an SQL program ? 24) Convert the code on page 649 to Object-Relational DBMS. In other words. 21) Explain the Clause ON DELETE/UPDATE RESTRICT/CASCADE/SET NULL. you are to develop a database application usi ng Oracle 8i that allows you to add objects to object tables.19) What are three the conditions that would make a field interesting to index o n ? 20) List 3 different types of indexes and describe when to use it and when to no t use it. 25) The purpose of this assignment is to give you experience in the use of objec t-relational database (ORDBMS) concepts. ArtObject must store a REF to Artist for the createdBy relationship (note tha t artist is a required value of ArtObject). The database application that you create must meet the following requirements: 1. displayExhibit must be implemented as a function that returns an array of Exh ibition object REFs as a derived inverse of the onExhibit relationship.

15. 8. Schedule AO1. AO2. 4. 18. AO5. Create an artist with name Sue. 20. Create at art object with id AO1 (artist is Joe). 17. 9. 13. Create an art object with id AO5 (artist is Sue). 10. 7. Create an exhibition with name EX1. year. Query: Display the name of each artist together with the idNo of their art o bjects. AO4. add these objects to the nested table in EX1). AO6 for EX2. and endDate of each exhibition together with the idNo of the art objects in the exhibit. Similar to the School Database example provided to you on the class Object Relat ional web page.objects in an exhibition. title. execute displayExhibits. type. you do not have to be concerned with implementing constr aints on dates for exhibitions and artists. Test Script (must be executed in the specified order): 1. Create an art object with id AO4 (artist is Sue). Create an art object with id AO3 (artist is Bob). Create an exhibition with name EX2. Repeat the query in step 15. Schedule AO3. AO3 for EX1 (i. you will create sql scripts to demonstrate the functionality of your project using the test sequence on the following page. Change the artist of AO4 to Bob. Create an art object with id AO2 (artist is Joe). 3. For this assignment.. 6. . 21. 14. 12. For this assignment. 2. 11. Create an art object with id AO6 (artist is Sue). 16. 5. 8. Create an artist with name Bob. Query: For each artobject.e. 9. Query: Display the idNo. and artist name for each art obj ect. you can assume that none of the objects will be deleted (otherwise you would have to write triggers to maintain inverses for delete oper ations). 19. Remove AO6 from the nested table in EX2. Create an artist with name Joe. Query: For each exhibit. Query: Display the name. startDate. execute objectCount.

25. Repeat the query in 17. A disk with the . A hardcopy of the execution of your test script. . 24. 3. Schedule AO6 for EX1 23. A hardcopy of the . Repeat the query in 16. Repeat the query in 18. Deliverables: 1.sql files.sql files needed to create the database and demonstrate the items above.22. 2.