Anda di halaman 1dari 7

1. View the Exhibit and examine the structure of the EMP and SALGRADE tables.

You want to
display the names of all employees whose salaries belong to GRADE 5. Which SQL statements give
the required output? (Choose all that apply)
A. SELECT ename
FROM emp JOIN salgrade
USING (sal BETWEEN losal AND hisal) AND grade = 5;

B. SELECT ename
FROM emp e JOIN salgrade s
ON (e.sal BETWEEN s.losal AND s.hisal AND s.grade = 5);

C. SELECT ename
FROM emp e JOIN salgrade s
ON (e.sal BETWEEN s.losal AND s.hisal) AND s.grade = 5;

D. SELECT ename
FROM emp e JOIN salgrade s
ON (e.sal BETWEEN s.losal AND s.hisal) WHERE s.grade=5;

SELECT ename
E.
FROM emp e JOIN salgrade s
WHERE e.sal BETWEEN s.losal AND s.hisal AND s.grade = 5;

1a "Exhibit"

EMP
Name Null? Type

EMPNO NOT NULL NUMBER(4)


ENAME VARCHAR2(10)
JOB VARCHAR2(9)
HIREDATE DATE
SAL NUMBER(7,2)
DEPTNO NUMBER(2)

SALGRADE

Name Null? Type

GRADE NUMBER
LOSAL NUMBER
HISAL NUMBER
2. View the Exhibit and examine the structure of the DEPARTMENTS and LOCATIONS tables. You
want to display all the cities and the corresponding departments in them, if any. Which query would
give you the required output?
A. SELECT location_id LOC, city, department_id DEPT
FROM locations LEFT OUTER JOIN departments
USING (location_id);
B. SELECT location_id LOC, city, department_id DEPT
FROM locations RIGHT OUTER JOIN departments
USING (location_id);

C. SELECT l.location_id LOC, l.city, d.department_id DEPT


FROM locations l LEFT OUTER JOIN departments d
USING (location_id);

SELECT l.location_id LOC, l.city, d.department_id DEPT


D.
FROM locations l FULL OUTER JOIN departments d
USING (location_id);

2a "Exhibit"

DEPARTMENTS
Name Null? Type

DEPARTMENT_ID NOT NULL NUMBER(4)


DEPARTMENT_NAME NOT NULL VARCHAR2(30)
MANAGER_ID NUMBER(6)
LOCATION_ID NUMBER(4)

LOCATIONS

Name Null? Type

LOCATION_ID NUMBER(4)
STREET_ADDRESS NOT NULL VARCHAR2(40)
POSTAL_CODE VARCHAR2(12)
CITY VARCHAR2(30)
STATE_PROVINCE NOT NULL VARCHAR2(25)
COUNTRY_ID CHAR(2)
> 3. View the Exhibit and examine the structure of the EMPLOYEES and DEPARTMENTS tables. You
want to display the last names and hire dates of all latest hires in their respective departments in the
location ID 1700. You issue the following query:

SQL>SELECT last_name, hire_date


FROM employees
WHERE (department_id, hire_date) IN
(SELECT department_id, MAX(hire_date)
FROM employees JOIN departments
USING(department_id)
WHERE location_id = 1700
GROUP BY department_id);

What is the outcome?


A. It executes but does not give the correct result

B. It executes successfully and gives the correct result

C. It generates an error because of the pairwise comparison

It generates an error because the GROUP BY clause cannot be used with table joins in a
D.
subquery
3a "Exhibit"

EMPLOYEES
Name Null? Type

EMPLOYEE_ID NOT NULL NUMBER(6)


FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8, 2)
DEPARTMENT_ID NUMBER(4)

DEPARTMENTS

Name Null? Type

DEPARTMENT_ID NOT NULL NUMBER(4)


DEPARTMENT_NAME NOT NULL VARCHAR2(30)
MANAGER_ID NUMBER(6)
LOCATION_ID NUMBER(4)
4. View the Exhibit and examine the structure of the LOCATIONS and DEPARTMENTS tables. You
need to display all those cities that have only one department. Which query gives the correct
output?
A. SELECT location_id, city
FROM locations l
WHERE 1 = (SELECT COUNT(*)
FROM departments
WHERE location_id = l.location_id);

B. SELECT location_id, city


FROM locations WHERE EXISTS (SELECT COUNT(*)
FROM departments
GROUP BY location_id HAVING COUNT(*) = 1);

C. SELECT location_id, city


FROM locations WHERE
1 = (SELECT COUNT(*) FROM departments
GROUP BY location_id);

SELECT l.location_id, city


D.
FROM locations l JOIN departments d ON (l.location_id = d.location_id)
WHERE EXISTS (SELECT COUNT(*)
FROM departments d
WHERE l.location_id =d.location_id);

4a "Exhibit"

LOCATIONS
Name Null? Type

LOCATION_ID NOT NULL NUMBER(4)


STREET_ADDRESS VARCHAR2(40)
POSTAL_CODE VARCHAR2(12)
CITY VARCHAR2(30)
STATE_PROVINCE VARCHAR2(25)
COUNTRY_ID CHAR(2)

DEPARTMENTS

Name Null? Type

DEPARTMENT_ID NOT NULL NUMBER(4)


DEPARTMENT_NAME NOT NULL VARCHAR2(30)
MANAGER_ID NUMBER(6)
LOCATION_ID NUMBER(4)
5. View the Exhibit and examine the structure of the EMP table. You want to display the names and
salaries of only those employees who earn the highest salaries in their departments. Which two SQL
statements give the required output? (Choose two.)
A. SELECT ename, sal
FROM emp e
WHERE sal = (SELECT MAX(sal)
FROM emp
WHERE deptno = e.deptno);

B. SELECT ename, sal


FROM emp
WHERE sal = ALL (SELECT MAX(sal)
FROM emp
GROUP BY deptno);

C. SELECT ename, sal


FROM emp e
WHERE EXISTS (SELECT MAX(sal)
FROM emp WHERE deptno = e.deptno);

D. SELECT ename, sal


FROM emp
NATURAL JOIN (SELECT deptno, MAX(sal) sal
FROM emp
GROUP BY deptno);

6. Evaluate the following SQL statement:


(Note that the numbers 2,3 etc in the SQL statement are line numbers and not part of the syntax)

SQL> CREATE TABLE product


2 (prod_id NUMBER(3),
3 prod_name VARCHAR2(25),
4 qty NUMBER(7,2),
5 price NUMBER(10,2),
6 CONSTRAINT prod_id_pk PRIMARY KEY(prod_id),
7 CONSTRAINT prod_name_uq UNIQUE (prod_name),
8 CONSTRAINT price_nn NOT NULL (price));
What is the outcome of executing this command?
A. It generates an error at line 6.

B. It generates an error at line 7.

C. It generates an error at line 8.

D. It executes successfully and creates the PRODUCTS table.

7. Examine the structure of the DEPT table:

Name Null? Type

DEPTNO NOT NULL NUMBER(2)


DNAME VARCHAR2(14)
LOC VARCHAR2(13)

You successfully execute the following SQL statement:

SQL>CREATE TABLE emp


(emp_no NUMBER(3) PRIMARY KEY,
emp_name VARCHAR2(25) UNIQUE,
job_id VARCHAR2(10) NOT NULL,
deptno NUMBER(2) REFERENCES dept(deptno),
salary NUMBER(10,2) CHECK (salary > 0));

For which columns would an index be generated automatically? (Choose all that apply)
A. EMP_NO

B. SALARY

C. JOB_ID

D. DEPT_NO

E. EMP_NAME

8. View the Exhibit and examine the structure of the EMP table belonging to the user SCOTT. The
EMP table contains the details of all the current employees in your organization.
EMPNO is the PRIMARY KEY.
User SCOTT has created an ENAME_IDX index on the ENAME column and an EMP_VW view that
displays the ENAME and SALARY columns.
The recyclebin is enabled in the database. SCOTT executes the following command:
SQL> DROP TABLE emp;
Which details would be stored in the recycle bin? (Choose all that apply)
A. EMP_VW

B. ENAME_IDX

C. The PRIMARY KEY constraint

D. Only the structure of the EMP table

Structure and data of the EMP table


E.

8a "Exhibit”
EMP
Name Null? Type

EMPNO NOT NULL NUMBER(4)


ENAME VARCHAR2(10)
HIREDATE DATE
SAL NUMBER(7,2)
DEPTNO NUMBER(2)

9. Examine the data in the DOCNO column of the DOC_DETAILS table:

DOCNO

123-456-7890
233-67-90876
45-789-23456

You need to extract the digits between the hyphens as follows:

SUBSTR
456
67
789

Which SQL statement gives the required result?


A. SELECT REGEXP_SUBSTR(docno,'-[^-]+') "SUBSTR" FROM doc_details;

B. SELECT REGEXP_SUBSTR(docno,'^-[^-]+-')"SUBSTR"
FROM doc_details;

C. SELECT REGEXP_SUBSTR(docno,'-[^-]+',2) "SUBSTR"


FROM doc_details;

D. SELECT REGEXP_SUBSTR(docno, '[^-]+',1,2) "SUBSTR"


FROM doc_details;

10. View the Exhibit and examine a sample of the data existing in the STORES table.
You need to generate a report that shows the following details:

1) The total QTY_SOLD of each product in each region of each country.


2) The total QTY_SOLD of all products in each region of each country.
3) The total QTY_SOLD of all products in each country.

Which SQL statement gives the required output?


A. SELECT country_id, region, prod_no, SUM(qty_sold)
FROM stores
GROUP BY CUBE(country_id,region,prod_no);

B. SELECT country_id, region, prod_no, SUM(qty_sold)


FROM stores
GROUP BY ROLLUP(country_id,region,prod_no);
C. SELECT country, region, prod_no, SUM(qty_sold)
FROM stores
GROUP BY GROUPING SETS(country_id,region),prod_no);

D. SELECT country, region, prod_no, SUM(qty_sold), GROUPING(country_id) G1,


GROUPING(region) G2, GROUPING(prod_no)
FROM stores
GROUP BY CUBE (country_id,region,prod_no);

Answers

1. BCD

2. A

3. B

4. A

5. AD

6. C

7. AE

8. BCE

9. D

10. B

Anda mungkin juga menyukai