01.09.2016 Views

Beginning Oracle Database 11g Administration From Novice to Professional

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 2 SQL AND PL/SQL 37<br />

Listing 2-18. A Check Constraint<br />

<br />

<br />

<br />

<br />

<br />

<br />

In the preceding scenario, how many records are retrieved by the SQL query in<br />

Listing 2-19?<br />

Listing 2-19. An SQL Query with Counterintuitive Results<br />

<br />

<br />

<br />

Intuitively, we expect <strong>to</strong> retrieve all rows in the table, because the only valid values of<br />

are and and because that rule is enforced by a check constraint. However,<br />

<strong>Oracle</strong> will nevertheless retrieve only two rows. This is not a sensible result.<br />

Counterintuitively, the queries in Listing 2-20 also retrieve only two data records.<br />

Listing 2-20. Two More Examples of SQL Queries with Counterintuitive Results<br />

<br />

<br />

<br />

<br />

<br />

<br />

The reasoning offered for these counterintuitive results is that the status of TOOL<br />

TIME, INC. is unknown and, therefore, the answer <strong>to</strong> every question involving the status<br />

of TOOL TIME, INC. is also unknown. To retrieve the third record, you need <strong>to</strong> add the<br />

clause <strong>to</strong> the preceding SQL queries; you can find more information<br />

on the problems created by nullable data items in any good book on SQL.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!