Online Tutorials & Training Materials | STechies.com
Register Login
Advertisement

Oracle Interview Questions for Experienced Candidates

|| 0

Oracle Interview Questions for Experienced Candidates
Stechies

Q. Mark for review

Examine the structure of the EMPLOYEES and DEPARTMENTS tables:

EMPLOYEES
EMPLOYEE_ID NUMBER
DEPARTMENT_ID NUMBER
MANAGER_ID NUMBER
LAST_NAME VARCHAR2(25)

DEPARTMENTS
DEPARTMENT_ID NUMBER
MANAGER_ID NUMBER
DEPARTMENT_NAME VARCHAR2(35)
LOCATION_ID NUMBER

1. You want to create a report displaying employee last names, department names, and locations. Which query should you use to create an equi-join?

A. SELECT last_name, department_name, location_id FROM employees , departments ;

B. SELECT employees.last_name, departments.department_name, departments.location_id FROM employees e, departments D WHERE e.department_id =d.department_id;

C. SELECT e.last_name, d.department_name, d.location_id FROM employees e, departments D WHERE manager_id =manager_id;

D. SELECT e.last_name, d.department_name, d.location_id FROM employees e, departments D WHERE e.department_id =d.department_id;

Answer: D

Q. 2 Mark for review The PRODUCTS table has these columns:
PRODUCT_ID NUMBER(4)
PRODUCT_NAME VARCHAR2(45)
PRICE NUMBER(8,2)

Evaluate this SQL statement:
SELECT * FROM PRODUCTS ORDER BY price, product_name; 
What is true about the SQL statement?

A. The results are not sorted.

B. The results are sorted numerically.

C. The results are sorted alphabetically.

D. The results are sorted numerically and then alphabetically.

Answer: D

Q 3. Examine the data in the EMPLOYEES table:

LAST_NAME  DEPARTMENT_ID  SALARY
Getz   10    3000
Davis   20    1500
King   20    2200
Davis   30    5000

Which three subqueries work? (Choose three)

A. SELECT * FROM employees where salary > (SELECT MIN(salary) FROM employees GROUP BY department.id);

B. SELECT * FROM employees WHERE salary = (SELECT AVG(salary) FROM employees GROUP BY department_id);

C. SELECT distinct department_id FROM employees Where salary > ANY (SELECT AVG(salary) FROM employees GROUP BY department_id);

D. SELECT department_id FROM employees WHERE SALARY > ALL (SELECT AVG(salary) FROM employees GROUP BY department_id);

E. SELECT last_name FROM employees Where salary > ANY (SELECT MAX(salary) FROM employees GROUP BY department_id);

F. SELECT department_id FROM employees WHERE salary > ALL (SELECT AVG(salary) FROM employees GROUP BY AVG(SALARY));

Answer: C, D, E

Q 4. Mark for review Examine the structure of the EMPLOYEES table:

EMPLOYEE_ID NUMBER Primary Key
FIRST_NAME VARCHAR2(25)
LAST_NAME VARCHAR2(25)
HIRE_DATE DATE

You issue these statements:

CREATE table new_emp
( employee_id NUMBER,
name VARCHAR2(30));

INSERT INTO new_emp
SELECT employee_id , last_name from employees;

Savepoint s1;

UPDATE new_emp set name = UPPER(name);

Savepoint s2;

Delete from new_emp; Rollback to s2;

Delete from new_emp where employee_id =180;

UPDATE new_emp set name = 'James';

Rollback to s2;

UPDATE new_emp set name = 'James' WHERE employee_id =180;

Rollback;

At the end of this transaction, what is true?

A. You have no rows in the table.

B. You have an employee with the name of James.

C. You cannot roll back to the same savepoint more than once.

D. Your last update fails to update any rows because employee ID 180 was already deleted.

Answer: A

Q 5. Mark for review View the image below and examine the data in the EMPLOYEES and DEPARTMENTS tables.

On the EMPLOYEES table,
EMPLOYEE_ID is the primary key.
MGR_ID is the ID of managers and refers to the EMPLOYEE_ID.

On the DEPARTMENTS table,
DEPARTMENT_ID is the primary key.

Evaluate this UPDATE statement:

UPDATE employees SET mgr_id =
(SELECT mgr_id FROM employees WHERE dept_id = 
(SELECT department_id FROM departments WHERE department_name = 'Administration')

Salary = (SELECT salary FROM employees WHERE emp_name = 'Smith')

WHERE job_id = 'IT_ADMIN';

What happens when the statement is executed?

A. The statement executes successfully, leaves the manager ID as the existing value, and changes the salary to 4000 for the employees with ID 103 and105.

B. The statement executes successfully, changes the manager ID to NULL, and changes the salary to 4000 for the employees with ID 103 and 105.

C. The statement executes successfully, changes the manager ID to NULL, and changes the salary to 3000 for the employees with ID 103 and 105.

D. The statement fails because there is more than one row matching the employee name Smith.

E. The statement fails because there is more than one row matching the IT_ADMIN job ID in the EMPLOYEES table.

F. The statement fails because there is no 'Administration' department in the DEPARTMENTS table

Answer: D

Q 6. Mark for review

Examine the structure of the EMPLOYEES table:

EMPLOYEE_ID NUMBER NOT NULL
EMP_NAME VARCHAR2(30)
JOB_ID VARCHAR2(20)
SAL NUMBER
MGR_ID NUMBER
DEPARTMENT_ID NUMBER

You want to create a SQL script file that contains an INSERT statement. When the script is run, the INSERT statement should insert a row with the specified values into the EMPLOYEES table. The INSERT statement should pass values to the table columns as specified below:

EMPLOYEE_ID: Next value from the sequence EMP_ID_SEQEMP_NAME and JOB_ID:
As specified by the user during run time, through substitution variables SAL: 2000 MGR_ID: No value DEPARTMENT_ID: Supplied by the user during run time through substitution variable. The INSERT statement should fail if the user supplies a value other than 20 or 50. Which INSERT statement meets the above requirements?

A. INSERT INTO employeesVALUES (emp_id_seq.NEXTVAL, '&ename', '&jobid', 2000, NULL, &did);

B. INSERT INTO employeesVALUES (emp_id_seq.NEXTVAL, '&ename', '&jobid', 2000, NULL, &did IN (20,50));

C. INSERT INTO (SELECT * FROM employees WHERE department_id IN (20,50)) VALUES (emp_id_seq.NEXTVAL, '&ename', '&jobid', 2000, NULL, &did);

D. INSERT INTO (SELECT * FROM employees WHERE department_id IN (20,50) WITH CHECK OPTION)VALUES (emp_id_seq.NEXTVAL, '&ename', '&jobid', 2000, NULL, &did);

E. INSERT INTO (SELECT * FROM employees WHERE (department_id = 20 AND department_id = 50) WITH CHECK OPTION )VALUES (emp_id_seq.NEXTVAL, '&ename', '&jobid', 2000, NULL, &did);

Answer: D

Q 7. Mark for review

The EMP table contains these columns:

LAST_NAME VARCHAR2 (25)
SALARY NUMBER (6,2)
DEPARTMENT_ID NUMBER (6)

You need to display the employees who have not been assigned to any department. You write the SELECT statement:

SELECT LAST_NAME, SALARY, DEPARTMENT_ID FROM EMP WHERE DEPARTMENT_ID = NULL; What is true about this SQL statement?

A. The SQL statement displays the desired results.

B. The column in the WHERE clause should be changed to display the desired results.

C. The operator in the WHERE clause should be changed to display the desired results.

D. The WHERE clause should be changed to use an outer join to display the desired results.

Answer: C

Q 8. Mark for review Examine these statements:

CREATE ROLE registrar;
GRANT UPDATE ON student_grades TO registrar;
GRANT registrar to user1, user2, user3;

What does this set of SQL statements do?

A. The set of statements contains an error and does not work.

B. It creates a role called REGISTRAR, adds the MODIFY privilege on the STUDENT_GRADES object to the role, and gives the REGISTRAR role to three users.

C. It creates a role called REGISTRAR, adds the UPDATE privilege on the STUDENT_GRADES object to the role, and gives the REGISTRAR role to three users.

D. It creates a role called REGISTRAR, adds the UPDATE privilege on the STUDENT_GRADES object to the role, and creates three users with the role.

E. It creates a role called REGISTRAR, adds the UPDATE privilege on three users, and gives the REGISTRAR role to the STUDENT_GRADES object.

F. It creates a role called STUDENT_GRADES, adds the UPDATE privilege on three users, and gives the UPDATE role to the registrar.

Answer: C

Q 9. Mark for review You need to design a student registration database that contains several tables storing academic information. The STUDENTS table stores information about a student. The STUDENT_GRADES table stores information about the student's grades. Both of the tables have a column named STUDENT_ID. The STUDENT_ID column in the STUDENTS table is a primary key. You need to create a foreign key on the STUDENT_ID column of the STUDENT_GRADES table that points to the STUDENT_ID column of the STUDENTS table. Which statement creates the foreign key?

A. CREATE TABLE student_grades (student_id NUMBER(12),semester_end DATE, gpa NUMBER(4,3), CONSTRAINT student_id_fk REFERENCES (student_id) FOREIGN KEY students(student_id));

B. CREATE TABLE student_grades(student_id NUMBER(12),semester_end DATE, gpa NUMBER(4,3), student_id_fk FOREIGN KEY (student_id) REFERENCES students(student_id));

C. CREATE TABLE student_grades(student_id NUMBER(12),semester_end DATE, gpa NUMBER(4,3), CONSTRAINT FOREIGN KEY (student_id) REFERENCES students(student_id));

D. CREATE TABLE student_grades(student_id NUMBER(12),semester_end DATE, gpa NUMBER(4,3), CONSTRAINT student_id_fk FOREIGN KEY (student_id) REFERENCES students(student_id));

Answer: D

Q 10. Mark for review You need to create a view EMP_VU. The view should allow the users to manipulate the records of only the employees that are working for departments 10 or 20. Which SQL statement would you use to create the view EMP_VU?

A. CREATE VIEW emp_vu AS SELECT * FROM employees WHERE department_id IN (10,20);

B. CREATE VIEW emp_vu AS SELECT * FROM employees WHERE department_id IN (10,20) WITH READ ONLY;

C. CREATE VIEW emp_vu AS SELECT * FROM employees WHERE department_id IN (10,20) WITH CHECK OPTION;

D. CREATE FORCE VIEW emp_vu AS SELECT * FROM employees WHERE department_id IN (10,20);]

E. CREATE FORCE VIEW emp_vu AS SELECT * FROM employees WHERE department_id IN (10,20) NO UPDATE;

Answer: C

Q 11. Mark for review View the image below and examine the data from the EMP table. The COMMISSION column shows the monthly commission earned by the employee. Which two tasks would require subqueries or joins in order to be performed in a single step? (Choose two.)

A. listing the employees who earn the same amount of commission as employee 3

B. finding the total commission earned by the employees in department 10

C. finding the number of employees who earn a commission that is higher than the average commission of the company

D. listing the departments whose average commission is more than 600 E. listing the employees who do not earn commission and who are working for department 20 in descending order of the employee ID

E. listing the employees whose annual commission is more than 6000

Answer: A,C

Q 12. Mark for review The STUDENT_GRADES table has these columns: STUDENT_ID NUMBER(12) SEMESTER_END DATE GPA NUMBER(4,3) The registrar has requested a report listing the students' grade point averages (GPA), sorted from highest grade point average to lowest within each semester, starting from the earliest date. Which statement accomplishes this?

A. SELECT student_id, semester_end, gpa FROM student_grades ORDER BY semester_end DESC, gpa DESC;

B. SELECT student_id, semester_end, gpa FROM student_grades ORDER BY semester_end ASC, gpa ASC;

C. SELECT student_id, semester_end, gpa FROM student_grades ORDER BY semester_end, gpa DESC;

D. SELECT student_id, semester_end, gpa FROM student_grades ORDER BY gpa DESC, semester_end DESC;

E. SELECT student_id, semester_end, gpa FROM student_grades ORDER BY gpa DESC, semester_end ASC;

Answer: C

Q 13. Mark for review Examine the structure of the EMPLOYEES and NEW_EMPLOYEES tables: EMPLOYEES EMPLOYEE_ID NUMBER Primary Key

FIRST_NAME VARCHAR2(25) LAST_NAME VARCHAR2(25) HIRE_DATE DATE

NEW_EMPLOYEES EMPLOYEE_ID NUMBER Primary Key NAME VARCHAR2(60) Which DELETE statement is valid?

A. DELETE FROM employees WHERE employee_id = (SELECT employee_id FROM employees);

B. DELETE * FROM employees WHERE employee_id = (SELECT employee_id FROM new_employees);

C. DELETE FROM employees WHERE employee_id IN (SELECT employee_id FROM new_employees WHERE name ='Carrey');

D. DELETE * FROM employees WHERE employee_id IN (SELECT employee_id FROM new_employees WHERE last_name ='Carrey');

Answer: C

Q 14. Mark for review A SELECT statement can be used to perform these three functions: - Choose rows from a table. - Choose columns from a table. - Bring together data that is stored in different tables by creating a link between them. Which set of keywords describes these capabilities?

A. difference, projection, join

B. selection, projection, join

C. selection, intersection, join

D. intersection, projection, join

E. difference, projection, product

Answer: B

Q 15.Evaluate this SQL statement:

SELECT e.EMPLOYEE_ID,e.LAST_NAME,e.DEPARTMENT_ID, d.DEPARTMENT_NAME FROM EMP e, DEPARTMENT d WHERE e.DEPARTMENT_ID = d.DEPARTMENT_ID; In the statement, which capabilities of a SELECT statement are performed?

A. Selection, projection, join

B. Difference, projection, join

C. Selection, intersection, join

D. Intersection, projection, join

E. Difference, projection, product

Answer: A

Q 16. Mark for review View the image below and examine the data in the EMPLOYEES and DEPARTMENTS tables.

You want to retrieve all employees' last names, along with their managers' last names and their department names. Which query would you use?

A. SELECT last_name, manager_id, department_name FROM employees e FULL OUTER JOIN departments d ON (e.department_id = d.department_id);

B. SELECT e.last_name, m.last_name, department_name FROM employees e LEFT OUTER JOIN employees m on ( e.manager_id = m.employee_id) LEFT OUTER JOIN departments d ON (e.department_id = d.department_id);

C. SELECT e.last_name, m.last_name, department_name FROM employees e RIGHT OUTER JOIN employees m on ( e.manager_id = m.employee_id) LEFT OUTER JOIN departments d ON (e.department_id = d.department_id);

D. SELECT e.last_name, m.last_name, department_name FROM employees e LEFT OUTER JOIN employees m on ( e.manager_id = m.employee_id) RIGHT OUTER JOIN departments d ON (e.department_id = d.department_id);

E. SELECT e.last_name, m.last_name, department_name FROM employees e RIGHT OUTER JOIN employees m on ( e.manager_id = m.employee_id) RIGHT OUTER JOIN departments d ON (e.department_id = d.department_id);

F. SELECT last_name, manager_id, department_name FROM employees e JOIN departments d ON (e.department_id = d.department_id) ;

Answer: B

Q 17. Mark for review Examine the structure of the EMPLOYEES table:

EMPLOYEE_ID NUMBER NOT NULL, Primary Key
EMP_NAME VARCHAR2(30)
JOB_ID NUMBER
SAL NUMBER
MGR_ID NUMBER References EMPLOYEE_ID column
DEPARTMENT_ID NUMBER Foreign key to DEPARTMENT_ID column of the DEPARTMENTS table

You created a sequence called EMP_ID_SEQ in order to populate sequential values for the EMPLOYEE_ID column of the EMPLOYEES table. Which two statements regarding the EMP_ID_SEQ sequence are true? (Choose two.)

A. You cannot use the EMP_ID_SEQ sequence to populate the JOB_ID column.

B. The EMP_ID_SEQ sequence is invalidated when you modify the EMPLOYEE_ID column.

C. The EMP_ID_SEQ sequence is not affected by modifications to the EMPLOYEES table.

D. Any other column of NUMBER data type in your schema can use the EMP_ID_SEQ sequence.

E. The EMP_ID_SEQ sequence is dropped automatically when you drop the EMPLOYEES table. F. The EMP_ID_SEQ sequence is dropped automatically when you drop the EMPLOYEE_ID column.

Answer: C,D

Q 18. Mark for review Examine the structure of the STUDENTS table:

STUDENT_ID NUMBER NOT NULL, Primary Key
STUDENT_NAME VARCHAR2(30)
COURSE_ID VARCHAR2(10) NOT NULL
MARKS NUMBER
START_DATE DATE
FINISH_DATE DATE

You need to create a report of the 10 students who achieved the highest ranking in the course INT_SQL and who completed the course in the year 1999. Which SQL statement accomplishes this task?

A. SELECT student_id, marks, ROWNUM "Rank"FROM students WHERE ROWNUM <= 10 AND finish_date BETWEEN '01-JAN-99' AND '31-DEC-99' AND course_id = 'INT_SQL'ORDER BY marks DESC;

B. SELECT student_id, marks, ROWID "Rank" FROM students WHERE ROWID <= 10 AND finish_date BETWEEN '01-JAN-99' AND '31-DEC-99'AND course_id = 'INT_SQL'ORDER BY marks;

C. SELECT student_id, marks, ROWNUM "Rank" FROM (SELECT student_id, marks FROM students WHERE ROWNUM <= 10 AND finish_date BETWEEN '01-JAN-99' AND '31-DEC-99' AND course_id = 'INT_SQL' ORDER BY marks DESC);

D. SELECT student_id, marks, ROWNUM "Rank" FROM (SELECT student_id, marks FROM students WHERE finish_date BETWEEN '01-JAN-99' AND '31-DEC-99' AND course_id = 'INT_SQL' ORDER BY marks DESC)WHERE ROWNUM <= 10 ;

E. SELECT student_id, marks, ROWNUM "Rank" FROM (SELECT student_id, marks FROM students ORDER BY marks) WHERE ROWNUM <= 10 AND finish_date BETWEEN '01-JAN-99' AND '31-DEC-99'AND course_id = 'INT_SQL';

Answer: D

Q 19. Examine the description of the EMPLOYEES table:

EMP_ID NUMBER(4) NOT NULL
LAST_NAME VARCHAR2(30) NOT NULL
FIRST_NAME VARCHAR2(30)
DEPT_ID NUMBER(2)
JOB_CAT VARCHAR2(30)
SALARY NUMBER(8,2)

Which statement shows the maximum salary paid in each job category of each department?

A. SELECT dept_id, job_cat, MAX (salary) FROM employees WHERE salary > MAX (salary);

B. SELECT dept_id, job_cat, MAX (salary) FROM employees GROUP BY dept_id, job_cat

C. SELECT dept_id, job_cat, MAX(salary) FROM employees;

D. SELECT dept_id, job_cat, MAX (salary) FROM employees GROUP BY dept_id;

E. SELECT dept_id, job_cat, MAX (salary) FROM employees GROUP BY dept_id, job_cat, salary;

Answer: B

Q 20. Management has asked you to calculate the value 12* salary* commission_pct for all the employees in the EMP table.

The EMP table contains these columns:

LAST NAME VARCHAR2(35) NOT NULL
SALARY NUMBER(9,2) NOT NULL
COMMISSION_PCT NUMBER(4,2)

Which statement ensures that a value is displayed in the calculated column for all employees?

A. SELECT last_name, 12 * salary* commission_pct FROM emp;

B. SELECT last_name, 12 * salary* (commission_pct,0) FROM emp;

C. SELECT last_name, 12 * salary* (nvl(commission_pct,0) FROM emp;

D. SELECT last_name, 12 * salary* (decode(commission_pct,0)) FROM emp;

Answer: C 

Get More Questions and Answers with Explanation at Oracle Forums.


Advertisement
Advertisement
Advertisement