Oracle Sumarry Chapters 4,6,7 and 8
Oracle Sumarry Chapters 4,6,7 and 8
Summary
Describe the Set Operators
❑ INTERSECT returns only the rows common to the result of two queries.
❑ MINUS returns the rows from the first query that do not exist in the second query.
Use a Set Operator to Combine Multiple Queries into a Single Query
❑ The queries in the compound query must return the same number of columns.
❑ The set operators have equal precedence and will be applied in the order they are
specified.
Control the Order of Rows Returned
❑ It is not possible to use ORDER BY in the individual queries that make a compound
query.
❑ The rows returned by a UNION ALL will be in the order they occur in the two source
queries.
❑ The rows returned by a UNION will be sorted across all their columns, left to right.
1. Which of these set operators will not sort the rows? (Choose the best answer.)
A. INTERSECT
B. MINUS
C. UNION
D. UNION ALL
2. Which of these operators will remove duplicate rows from the final result? (Choose all that
apply.)
A. INTERSECT
B. MINUS
C. UNION
D. UNION ALL
3. If a compound query contains both a MINUS and an INTERSECT operator, which will be
applied first? (Choose the best answer.)
A. The INTERSECT, because INTERSECT has higher precedence than MINUS.
B. The MINUS, because MINUS has a higher precedence than INTERSECT.
C. The precedence is determined by the order in which they are specified.
D. It is not possible for a compound query to include both MINUS and INTERSECT.
4. There are four rows in the REGIONS table. Consider the following statements and choose
how many rows will be returned for each: 0, 4, 8, or 16.
A. SELECT * FROM regions UNION SELECT * FROM regions;
B. SELECT * FROM regions UNION ALL SELECT * FROM regions;
C. SELECT * FROM regions MINUS SELECT * FROM regions;
D. SELECT * FROM regions INTERSECT SELECT * FROM regions;
5. Consider this compound query: SELECT empno, hired FROM emp UNION ALL SELECT
emp_id,hired,fired FROM ex_emp; The columns EMP.EMPNO and EX_EMP.EMP_ID are
integer; the column EMP.HIRED is timestamp; the columns EX_EMP.HIRED and EX_EMP.FIRED
are date. Why will the statement fail? (Choose the best answer.)
A. Because the columns EMPNO and EMP_ID have different names
B. Because the columns EMP.HIRED and EX_EMP.HIRED are different data types
C. Because there are two columns in the first query and three columns in the second
query
D. For all the reasons above
E. The query will succeed.
6. Which line of this statement will cause it to fail? (Choose the best answer.)
A. SELECT ename, hired FROM current_staff
B. ORDER BY ename
C. MINUS
D. SELECT ename, hired FROM current staff
E. WHERE deptno=10
F. ORDER BY ename;
7. Study this statement: SELECT ename FROM emp UNION ALL SELECT ename FROM ex_emp;
In what order will the rows be returned? (Choose the best answer.)
A. The rows from each table will be grouped and within each group will be sorted on
ENAME.
B. The rows from each table will be grouped but not sorted.
C. The rows will not be grouped but will all be sorted on ENAME.
D. The rows will be neither grouped nor sorted
❑ Group functions are also known as multiple row, aggregate, or summary functions.
They execute once for each group of data and aggregate the data from multiple rows
into a single result for each group.
❑ The COUNT of a function returns an integer value representing the number of rows
in a group.
❑ The SUM function returns an aggregated total of all the nonnull numeric expression
values in a group. ❑ The AVG function divides the sum of a column or expression by the
number of nonnull rows in a group.
❑ The MAX and MIN functions operate on NUMBER, DATE, CHAR, and VARCHAR2 data
types. They return a value that is either the largest or smallest item in the group.
❑ The GROUP BY clause specifies the grouping attribute rows must have in common for
them to be clustered together.
❑ The GROUP BY clause facilitates the creation of groups within a selected set of data
and appears after the WHERE clause but before the ORDER BY clause.
❑ Any item on the SELECT list that is not a group function must be a grouping attribute.
❑ Datasets may be partitioned into groups and further divided into subgroups based on
multiple grouping attributes.
Include or Exclude Grouped Rows Using the HAVING Clause
❑ Clustering rows using a common grouping attribute with the GROUP BY clause and
applying an aggregate function to each of these groups returns group-level results.
❑ The HAVING clause provides the language to limit the group-level results returned.
❑ The HAVING clause may only be specified if there is a GROUP BY clause present.
❑ All grouping is performed and group functions are executed prior to evaluating the
HAVING clause
❑ Character items are explicitly transformed into date values using the TO_DATE
conversion function.
❑ Character items are changed into number values using the TO_NUMBER
conversion function.
Use the TO_CHAR, TO_NUMBER, and TO_DATE Conversion Functions
❑ The format masks available when TO_CHAR is used to convert character items
to date include day, week, month, quarter, year, and century.
❑ Character terms, such as month and day names extracted from dates with the
TO_CHAR function, are automatically padded with spaces that may be trimmed
by prefixing the format mask with the fm modifier.
❑ The TO_DATE function has an fx modifier that specifies an exact match for the
character string to be converted and the date format mask.
Apply Conditional Expressions in a SELECT Statement
❑ Nesting functions use the output from one function as the input to another.
❑ The NVL function either returns the original item unchanged or an alternative
item if the initial term is null.
❑ The NVL2 function returns a new if-null item if the original item is null or an
alternative if-not-null item if the original term is not null.
❑ The NULLIF function tests two terms for equality. If they are equal, the
function returns null, else it returns the first of the two terms tested.
❑ The COALESCE function returns the first nonnull value from its parameter list.
If all its parameters are null, then a null value is returned.
❑ There are two variants of the CASE expression used to facilitate if-then-else
conditional logic: the simple CASE and searched CASE expressions.
Multiple Choice Questions
1. What type of conversion is performed by the following statement? (Choose the best
answer.) SELECT LENGTH (3.14285) FROM DUAL;
A. Explicit conversion
B. Implicit conversion
C. 7
D. None of the above
2. Choose any incorrect statements regarding conversion functions. (Choose all that apply.)
A. TO_CHAR may convert date items to character items.
B. TO_DATE may convert character items to date items.
C. TO_CHAR may convert numbers to character items.
D. TO_DATE may convert date items to character items.
3. What value is returned after executing the following statement? (Choose the best answer.)
SELECT TO_NUMBER (1234.49, 999999.9) FROM DUAL;
A. 1234.49
B. 001234.5
C. 1234.5
D. None of the above
4. What value is returned after executing the following statement? (Choose the best answer.)
SELECT TO_CHAR (1234.49, '999999.9') FROM DUAL;
A. 1234.49
B. 001234.5
C. 1234.5
D. None of the above
5. If SYSDATE returns 12-JUL-2009, what is returned by the following statement? (Choose the
best answer.) SELECT TO_CHAR (SYSDATE, 'fmMONTH, YEAR') FROM DUAL;
A. JUL, 2009
B. JULY, TWO THOUSAND NINE
C. JUL-09
D. None of the above
6. If SYSDATE returns 12-JUL-2009, what is returned by the following statement? (Choose the
best answer.) SELECT TO_CHAR (SYSDATE, 'fmDDth MONTH') FROM DUAL;
A. 12TH JULY
B. 12th July
C. TWELFTH JULY
D. None of the above
7. If SYSDATE returns 12-JUL-2009, what is returned by the following statement? (Choose the
best answer.) SELECT TO_CHAR(TO_DATE(TO_CHAR(SYSDATE,'DD'),'DD'),'YEAR') FROM DUAL;
A. 2009
B. TWO THOUSAND NINE
C. 12-JUL-2009
D. None of the above
8. What value is returned after executing the following statement? (Choose the best answer.)
SELECT NVL2(NULLIF('CODA','SID'),'SPANIEL','TERRIER') FROM DUAL;
A. SPANIEL
B. TERRIER
C. NULL
D. None of the above
9. What value is returned after executing the following statement? (Choose the best answer.)
SELECT NVL (SUBSTR ('AM I NULL',10),'YES I AM') FROM DUAL;
A. NO
B. NULL
C. YES, I AM
D. None of the above
10. If SYSDATE returns 12-JUL-2009, what is returned by the following statement? (Choose
the best answer.) SELECT DECODE(TO_CHAR(SYSDATE,'MM'),'02','TAX DUE','PARTY') FROM
DUAL;
A. TAX DUE
B. PARTY
C. 02
D. None of the above
❑ Even though TRUNCATE is not DML, it does remove all rows in a table.
Insert Rows into a Table