0% found this document useful (0 votes)
46 views15 pages

Oracle Sumarry Chapters 4,6,7 and 8

The document discusses set operators, group functions, and conditional expressions in SQL. It provides examples of using UNION, INTERSECT, MINUS to combine query results, and GROUP BY to aggregate data by groups. It also covers conditional expressions like NVL, DECODE to handle null values and convert data types across queries. Multiple choice questions test the understanding of how to properly structure queries using these functions and operators.

Uploaded by

zakiabdulahi2022
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views15 pages

Oracle Sumarry Chapters 4,6,7 and 8

The document discusses set operators, group functions, and conditional expressions in SQL. It provides examples of using UNION, INTERSECT, MINUS to combine query results, and GROUP BY to aggregate data by groups. It also covers conditional expressions like NVL, DECODE to handle null values and convert data types across queries. Multiple choice questions test the understanding of how to properly structure queries using these functions and operators.

Uploaded by

zakiabdulahi2022
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Chapter 4: Using the Set Operators

Summary
Describe the Set Operators

❑ UNION ALL concatenates the results of two queries.

❑ UNION sorts the results of two queries and removes duplicates.

❑ 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 corresponding columns must be of compatible data type.

❑ 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.

❑ An ORDER BY clause can be appended to the end of 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.

Multiple Choice Questions

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

Chapter 6: Reporting Aggregated Data Using the Group


Functions
Summary
Describe the Group Functions

❑ 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.

❑ Groups may be entire tables or portions of a table grouped together by a common


grouping attribute.
Identify the Available Group Functions

❑ 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.

❑ Group functions may only be nested two levels deep.


Group Data Using the GROUP BY Clause

❑ 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.

❑ Group functions may not be placed in a WHERE clause.

❑ 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

Multiple Choice Questions


1. What result is returned by the following statement? (Choose the best answer.) SELECT
COUNT(*) FROM DUAL;
A. NULL
B. 0
C. 1
D. None of the above
2. Choose one correct statement regarding group functions.
A. Group functions may only be used when a GROUP BY clause is present.
B. Group functions can operate on multiple rows at a time.
C. Group functions only operate on a single row at a time.
D. Group functions can execute multiple times within a single group. Identify the
Available Group Functions
3. What value is returned after executing the following statement? (Choose the best answer.)
SELECT SUM(SALARY) FROM EMPLOYEES; Assume there are ten employee records and each
contains a SALARY value of 100, except for one, which has a null value in the SALARY field.
A. 900
B. 1000
C. NULL
D. None of the above
4. Which values are returned after executing the following statement? (Choose all that
apply.) SELECT COUNT(*), COUNT(SALARY) FROM EMPLOYEES; Assume there are ten
employee records and each contains a SALARY value of 100, except for one, which has a null
value in their SALARY field.
A. 10 and 10
B. 10 and NULL
C. 10 and 9
D. None of the above
5. What value is returned after executing the following statement? (Choose the best answer.)
SELECT AVG(NVL(SALARY,100)) FROM EMPLOYEES; Assume there are ten employee records
and each contains a SALARY value of 100, except for one employee, who has a null value in
the SALARY field.
A. NULL
B. 90
C. 100
D. None of the above
6. What value is returned after executing the following statement? (Choose the best answer.)
SELECT SUM((AVG(LENGTH(NVL(SALARY,0))))) FROM EMPLOYEES GROUP BY SALARY; Assume
there are ten employee records and each contains a SALARY value of 100, except for one,
which has a null value in the SALARY field.
A. An error is returned
B. 3
C. 4
D. None of the above
7. How many records are returned by the following query? (Choose the best answer.) SELECT
SUM(SALARY), DEPARTMENT_ID FROM EMPLOYEES GROUP BY DEPARTMENT_ID; Assume
there are 11 nonnull and 1 null unique DEPARTMENT_ID values. All records have a nonnull
SALARY value.
A. 12
B. 11
C. NULL
D. None of the above
8. What values are returned after executing the following statement? (Choose the best
answer.) SELECT JOB_ID, MAX_SALARY FROM JOBS GROUP BY MAX_SALARY; Assume that
the JOBS table has ten records with the same JOB_ID value of DBA and the same
MAX_SALARY value of 100.
A. One row of output with the values DBA, 100
B. Ten rows of output with the values DBA, 100
C. An error is returned
D. None of the above
9. How many rows of data are returned after executing the following statement? (Choose the
best answer.) SELECT DEPT_ID, SUM(NVL(SALARY,100)) FROM EMP GROUP BY DEPT_ID
HAVING SUM(SALARY) > 400; Assume the EMP table has ten rows and each contains a
SALARY value of 100, except for one, which has a null value in the SALARY field. The first and
second five rows have DEPT_ID values of 10 and 20, respectively.
A. Two rows
B. One row
C. Zero rows
D. None of the above
10. How many rows of data are returned after executing the following statement? (Choose
the best answer.) SELECT DEPT_ID, SUM(SALARY) FROM EMP GROUP BY DEPT_ID HAVING
SUM(NVL(SALARY,100)) > 400; Assume the EMP table has ten rows and each contains a
SALARY value of 100, except for one, which has a null value in the SALARY field. The first and
second five rows have DEPT_ID values of 10 and 20, respectively.
A. Two rows
B. One row
C. Zero rows
D. None of the above

Chapter 7: Using Conversion Functions and


Conditional Expressions
Summary
Describe Various Types of Conversion Functions Available in SQL

❑ When values do not match the defined parameters of functions, Oracle


attempts to convert them into the required data types. This is known as implicit
conversion.

❑ Explicit conversion occurs when a function like TO_CHAR is invoked to change


the data type of a value.

❑ The TO_CHAR function performs date to character and number to character


data type conversions.

❑ 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 TO_CHAR function returns an item of type VARCHAR2.


❑ Format models or masks prescribe patterns that character strings must match
to facilitate accurate and consistent conversion into number or date items.

❑ When the TO_CHAR function performs number to character conversions, the


format mask can specify currency, numeric width, position of decimal operator,
thousands separator, and many other formatting codes.

❑ The format masks available when TO_CHAR is used to convert character items
to date include day, week, month, quarter, year, and century.

❑ Format masks must always be specified enclosed in single quotes.

❑ When performing date to character conversion, the format mask specifies


which date elements are extracted and whether the element should be
described by a long or abbreviated name.

❑ 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.

❑ The DECODE function implements if-then-else conditional logic by testing two


terms for equality and returning the third term if they are equal or, optionally,
some other term if they are not.

❑ 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

Chapter 8: DML, TCL and Index Statements


Summary
Describe Each Data Manipulation Language (DML) Statement

❑ INSERT enters rows into a table.

❑ UPDATE adjusts the values in existing rows.

❑ DELETE removes rows.

❑ MERGE can combine the functions of INSERT, UPDATE, and DELETE.

❑ Even though TRUNCATE is not DML, it does remove all rows in a table.
Insert Rows into a Table

❑ INSERT can add one row or a set of rows.

❑ It is possible for an INSERT to enter rows into multiple tables.

❑ Subqueries can be used to generate the rows to be inserted.

❑ Subqueries and functions can be used to generate column values.

❑ An INSERT is not permanent until it is committed.


Update Rows in a Table

❑ UPDATE can affect one row or a set of rows in one table.

❑ Subqueries can be used to select the rows to be updated.

❑ Subqueries and functions can be used to generate column values.

❑ An UPDATE is not permanent until it is committed.


Delete Rows from a Table
❑ DELETE can remove one row or a set of rows from one table.

❑ A subquery can be used to select the rows to be deleted.

❑ A DELETE is not permanent until it is committed.

❑ TRUNCATE removes every row from a table.

❑ A TRUNCATE is immediately permanent: it cannot be rolled back.


Control Transactions

❑ A transaction is a logical unit of work possibly made up of several DML


statements.

❑ Transactions are invisible to other sessions until committed.

❑ Until committed, transactions can be rolled back.

❑ Once committed, a transaction cannot be reversed.

❑ A SAVEPOINT lets a session roll back part of a transaction.

Multiple Choice Questions

1. Which of the following commands can be rolled back?


A. COMMIT
B. DELETE
C. INSERT
D. MERGE
E. TRUNCATE
F. UPDATE
2. How can you change the primary key value of a row? (Choose the best answer.)
A. You cannot change the primary key value.
B. Change it with a simple UPDATE statement.
C. The row must be removed with a DELETE and reentered with an INSERT.
D. This is only possible if the row is first locked with a SELECT FOR UPDATE.
3. If an UPDATE or DELETE command has a WHERE clause that gives it a scope of several rows,
what will happen if there is an error part way through execution? The command is one of
several in a multistatement transaction. (Choose the best answer.)
A. The command will skip the row that caused the error and continue.
B. The command will stop at the error, and the rows that have been updated or deleted
will remain updated or deleted.
C. Whatever work the command had done before hitting the error will be rolled back,
but work done already by the transaction will remain.
D. The whole transaction will be rolled back.
4. If a table T1 has four numeric columns, C1, C2, C3, and C4, which of these statements will
succeed? (Choose the best answer.)
A. INSERT INTO T1 VALUES (1,2,3, null);
B. INSERT INTO T1 values (‘1’, ‘2’, ‘3’, ‘4’);
C. INSERT INTO T1 SELECT * FROM T1;
D. All the statements (A, B, and C) will succeed.
E. None of the statements (A, B, or C) will succeed.
5. Study the result of this SELECT statement: SELECT * FROM t1; C1 C2 C3 C4 ---------- ---------- --
-------- ---------- 1 2 3 4 5 6 7 8 If you issue this statement: INSERT INTO t1 (c1, c2) VALUES
(SELECT c1, c2 FROM t1); why will it fail? (Choose the best answer.)
A. Because values are not provided for all the table’s columns: there should be NULLs
for C3 and C4.
B. Because the subquery returns multiple rows: it requires a WHERE clause to restrict
the number of rows returned to one.
C. Because the subquery is not scalar: it should use MAX or MIN to generate scalar
values.
D. Because the VALUES keyword is not used with a subquery.
E. It will succeed, inserting two rows with NULLs for C3 and C4.
6. Consider this statement: INSERT INTO regions (region_id,region_name) VALUES ((SELECT
max(region_id)+1 FROM regions), 'Great Britain'); What will the result be? (Choose the best
answer.)
A. The statement will not succeed if the value generated for REGION_ID is not unique,
because REGION_ID is the primary key of the REGIONS table.
B. The statement has a syntax error because you cannot use the VALUES keyword with a
subquery.
C. The statement will execute without error.
D. The statement will fail if the REGIONS table has a third column.
7. You want to insert a row and then update it. What sequence of steps should you follow?
(Choose the best answer.)
A. INSERT, UPDATE, COMMIT
B. INSERT, COMMIT, UPDATE, COMMIT
C. INSERT, SELECT FOR UPDATE, UPDATE, COMMIT
D. INSERT, COMMIT, SELECT FOR UPDATE, UPDATE, COMMIT
8. If you issue this command: UPDATE employees SET salary=salary * 1.1; what will be the
result? (Choose the best answer.)
A. The statement will fail because there is no WHERE clause to restrict the rows
affected.
B. The first row in the table will be updated.
C. There will be an error if any row has its SALARY column NULL.
D. Every row will have SALARY incremented by 10 percent, unless SALARY was NULL.
9. How can you delete the values from one column of every row in a table? (Choose the best
answer.)
A. Use the DELETE COLUMN command.
B. Use the TRUNCATE COLUMN command.
C. Use the UPDATE command.
D. Use the DROP COLUMN command.
10. Which of these commands will remove every row in a table while keeping its structure
intact? (Choose one or more correct answers.)
A. A DELETE command with no WHERE clause
B. A DROP TABLE command
C. A TRUNCATE command
D. An UPDATE command, setting every column to NULL and with no WHERE clause
11. User JOHN updates some rows and asks user ROOPESH to log in and check the changes
before he commits them. Which of the following statements is true? (Choose the best
answer.)
A. ROOPESH can see the changes but cannot alter them because JOHN will have locked
the rows.
B. ROOPESH will not be able to see the changes.
C. JOHN must commit the changes so that ROOPESH can see them and, if necessary, roll
them back.
D. JOHN must commit the changes so that ROOPESH can see them, but only JOHN can
roll them back.
12. User JOHN updates some rows but does not commit the changes. User ROOPESH queries
the rows that JOHN updated. Which of the following statements is true? (Choose the best
answer.)
A. ROOPESH will not be able to see the rows because they will be locked.
B. ROOPESH will be able to see the new values, but only if he logs in as JOHN.
C. ROOPESH will see the old versions of the rows.
D. ROOPESH will see the state of the data as it was when JOHN last created a
SAVEPOINT.
13. Which of these commands will terminate a transaction? (Choose three correct answers.)
A. COMMIT
B. DELETE
C. ROLLBACK
D. ROLLBACK TO SAVEPOINT
E. SAVEPOINT
F. TRUNCATE

You might also like