Oracle SQL Expert

Total Page:16

File Type:pdf, Size:1020Kb

Oracle SQL Expert

Oracle SQL Expert

Errata

Table of Contents Oracle SQL Expert...... 1 Page 62...... 2 Page 63...... 3 Page 160...... 4 Page 167...... 5 Page 173...... 6 Page 217...... 8 Page 364...... 9 Page 366...... 10 Page 439...... 12 Practice Exam on the Web...... 13 Question 66...... 13 Page 62

Numeric

Number(n,m) – the text could be more clear here about what happens when both “n” and “m” are omitted. If omitted, both values default to their maximum values. However, if “n” is specified and “m” is omitted, then “m” defaults to zero. Table 2-2 is clear about this, however the text is not. Page 63

The last line of the page has this phrase, which continues to the next page:

For example, '10-NOV-10' is the first of November, 2010."

Clearly "10-NOV-10" is not the first of the month. This is:

'01-NOV-10'.

Thanks to Rafael Ferreira for flagging this one! Page 160

In the two minute drill, the top of the page reads as follows:

 The HAVING clause can be used with GROUP BY to restrict sets of rows in the same fashion that ORDER BY can be used to restrict individual records.

Instead of ORDER BY, it should've said WHERE, as in:

 The HAVING clause can be used with GROUP BY to restrict sets of rows in the same fashion that WHERE can be used to restrict individual records.

Thanks to Dmitriy Yermakov for catching this one! Page 167

The answer to question 8 is correct, but the explanation omits a possible scenario. If the asterisk is qualified with a table name or table alias, then you may include additional columns in the SELECT statement. For example, consider the following SELECT statement:

SELECT PORTS.*, PORT_ID FROM PORTS ORDER BY PORT_NAME;

The use of a qualified asterisk, using a table name or alias, is accepted.

Thanks to Petr Schmidt for catching this one! Page 173

There's a formatting error with Table 5-1. The table begins on page 172, but the error is on the final line of text at the bottom of the table, which occurs about halfway down page 173:

Operator Description <> Not equal ^= Not equal IN Compares one value on the left side of the operator to a set of one or more values on the right side of the operator. The set of values must be enclosed in parentheses. If the values are presented as constants, they are separated by commas, as in ('Maple', 'Elm', 'Main') or (2009, 2010, 2011). A query may also be used, as in (SELECT PORT_NAME FROM PORTS). LIKE Enables wildcard characters. There are two wildcard characters:

_ The underscore is a wildcard character representing a single character.

% The percent sign is a wildcard character representing one or more values.

IS Used with NULL or NOT NULL The corrected text is shown in blue below.

Operator Description <> Not equal ^= Not equal IN Compares one value on the left side of the operator to a set of one or more values on the right side of the operator. The set of values must be enclosed in parentheses. If the values are presented as constants, they are separated by commas, as in ('Maple', 'Elm', 'Main') or (2009, 2010, 2011). A query may also be used, as in (SELECT PORT_NAME FROM PORTS). LIKE Enables wildcard characters. There are two wildcard characters:

_ The underscore is a wildcard character representing a single character.

% The percent sign is a wildcard character representing one or more values. IS Used with NULL or NOT NULL

Thanks to Ravi Raja for catching this! Page 217

The LPAD and RPAD functions are described correctly with this phrase:

Process: Pad the left of character string s1 (LPAD) or right of character string s1 (RPAD) with character string s2, so that s1 is n characters long.

That statement is correct. Also, the example shown at the bottom of the page is correct.

However, this statement about the example is incorrect:

Example: Take a string literal ‘Chapter One—I Am Born’ and pad it to the right with 40 occurrences of a single period.

Not exactly. The RPAD function, which is what is being demonstrated in the example, will not "paid it the right with 40 occurrences of a single period". That sentence would read more accurately to say that it will "pad it to the right so that the resulting string is 40 characters in length." Page 364

In the "On the Job" tip, there's a typo. The last line should read "… such as AVG, MIN, MAX, or SUM. This is unique to COUNT."

It's not MAN, it's MAX.

Thanks to Aaron Soule for catching this! Page 366

The WITH statement is incorrect. Here's the correct statement:

WITH PORT_BOOKINGS AS ( SELECT P.PORT_ID, P.PORT_NAME, COUNT(S.SHIP_ID) CT FROM PORTS P, SHIPS S WHERE P.PORT_ID = S.HOME_PORT_ID GROUP BY P.PORT_ID, P.PORT_NAME ), DENSEST_PORT AS ( SELECT MAX(CT) MAX_CT FROM PORT_BOOKINGS ) SELECT PORT_NAME FROM PORT_BOOKINGS WHERE CT = (SELECT MAX_CT FROM DENSEST_PORT);

Instead of "MAX" it should be "MAX(CT)". What's happening here is this:

- Line 1: you're declaring this a WITH statement - Line 2: you're creating a first named query and naming it PORT_BOOKINGS - Line 8: you're creating a second named query called DENSEST_PORT - Line 9: your second query selects from the first query you created in Line 2. And it selects the MAX of the third column in that named query from line 2. - Line 12: you create a third query, which has no name, and is the entire point of the WITH statement you began on line 1. And it queries the Line 2 query, and includes a subquery of the Line 8 query.

Looking at in with color highlights, here's the correction and why it's needed:

WITH PORT_BOOKINGS AS ( SELECT P.PORT_ID, P.PORT_NAME, COUNT(S.SHIP_ID) CT FROM PORTS P, SHIPS S WHERE P.PORT_ID = S.HOME_PORT_ID GROUP BY P.PORT_ID, P.PORT_NAME ), DENSEST_PORT AS ( SELECT MAX(CT) MAX_CT FROM PORT_BOOKINGS ) SELECT PORT_NAME FROM PORT_BOOKINGS WHERE CT = (SELECT MAX_CT FROM DENSEST_PORT); Thanks to a couple of sharp individuals for catching this: Rob van Merle on June 4, 2011 - thanks Rob! And Aaron Soule on November 26, 2011 - thanks Aaron! Page 439

The fourth line of text should be deleted. It reads as follows:

If you’re creating a NOT NULL constraint, no additional specification is required.

That line doesn't belong here , because this section is describing the ALTER TABLE out-of-line syntax, and you can't use that syntax for creating a NOT NULL constraint anyway. That's a fact that is stated in this section. For example, page 438 correctly states:

The type of constraint: either UNIQUE, PRIMARY KEY, FOREIGN KEY, or CHECK (not the NOT NULL constraint, however)

And again in the middle of page 439 is stated that:

The required keyword indicating the type of constraint, which in this example is CHECK (other types are PRIMARY KEY, UNIQUE, FOREIGN KEY—but not the NOT NULL option, since this is the out-of-line syntax)

So to be clear - you cannot use the ALTER TABLE out-of-line syntax for creating a NOT NULL constraint.

Thanks to Rob van Merle for catching this one, on June 6, 2011 - thanks Rob! Practice Exam on the Web

This is for the practice exam that is not in the book, but is available online via the web.

Question 66

Answer D should not read:

ORDER BY SIBLINGS BY

It should instead read as:

ORDER SIBLINGS BY

Two different individuals caught this: Bryan Post, and also Rufat Abdullayev - thank you both!

Recommended publications