这章的语义单元是个非常重要的概念。
Review Section
This section has described the following points about character and lexical units:
1. Lexical units are the basic building blocks in programming languages, and they can be delimiters, identifiers, literals, or comments.
2. You can develop lexical units by combining valid characters and symbols.
3. Lexical delimiters are symbols or symbol sets that identify string literals and provide assignment, association, concatenation, comparison, math, and statement controls.
4. The STANDARD package provides predefined identifiers.
5. You can create user-defined identifies, such as data type and variable names, that don't conflict with keywords or reserved words.
6. You can create quoted identifiers by using double quotes to delimit words that may duplicate keywords and reserved words.
7. You can create single- and multiple-line comments.
Review Section
This section has described the following points about variables and data types:
1. Anonymous blocks use the DECLARE keyword to start the declaration block, while named blocks use the function or procedure header.
2. The BEGIN keyword starts the execution block and ends any declaration block.
3. The EXCEPTION keyword starts the exception block and the END keyword terminates the program unit.
4. You can define data types in local anonymous (unnamed) or named blocks, as well as in nested anonymous blocks.
5. You can declare scalar and composite variables in the declaration block.
6. Scalar variables hold only one thing, such as a number, string, or date.
8. You can create subtypes of standard scalar variables in PL/SQL.
9. Composite variables hold two or more things, and they can be a record structure of one row and many columns (fields), a collection, or a hybrid collection known as a system reference cursor.
10. Some scalar variables implicitly cast while others require programmer intervention with SQL built-in functions.
11. SQL composite variables work in both SQL and PL/SQL contexts, while PL/SQL composite variables work only in the PL/SQL context.
The mastery check is a series of true-or-false and multiple-choice questions that let you confirm
how well you understand the material in the chapter. You may check Appendix I for answers to
these questions.
True or False:
1. A declaration block begins with the function or procedure header, specification, or signature in a named block.
True. A declaration block immediately follows the function or procedure header.
2. An execution block can contain a local named block.
False. An execution block can’t contain a local named block; local named blocks must be defined in the declaration block.
3. A declaration block can’t contain an anonymous block.
False. A declaration block can contain an anonymous block if the anonymous block is embedded in a named block.
4. An identifier is a lexical unit.
True. An identifier is a lexical unit.
5. The colon and equal sign set (:=) is the only assignment operator in PL/SQL.
False. The := operator is the only right-to-left assignment operator in PL/SQL, but you can use the SELECT-INTO statement or BULK COLLECT INTO statement to perform left-toright assignments, as covered in Chapter 3.
6. The equal sign and greater than symbol set (=>) is an association operator.
True. The equal sign and greater than symbol set (=>) is an association operator, and it’s used for named notation.
7. PL/SQL lets you create subtypes of standard scalar variables.
True. You can create subtypes of standard scalar variables with PL/SQL.
8. A record data type is a SQL data type.
False. A record data type is a PL/SQL data type.
9. A system reference cursor is a PL/SQL-only data type.
True. A system reference cursor is a PL/SQL-only data type.
10. The PL/SQL programming language supports arrays and lists as composite data types.
True. PL/SQL supports array (varray) and list (table) collections, which are composite type variables.
Multiple Choice:
11. Lexical units are the basic building blocks in programming languages, and they can perform which of the following? (Multiple answers possible)
A. A delimiter
B. An identifier
C. A literal
D. A comment
E. An anonymous block
A, B, C, and D are correct. Delimiters, identifiers, literals, and comments are lexical units.
12. Which of the following are valid symbol sets in PL/SQL? (Multiple answers possible)
A. A colon and equal sign set (:=) assignment operator
B. A guillemets or double angle bracket set (<< >>) as delimiters for labels
C. A less than symbol and greater than symbol set (<>) as a comparison operator
D. An exclamation mark and equal sign set (!=) as a comparison operator
E. A opening curly brace and closing curly brace symbol set ({}) as delimiters for an anonymous block
A, B, C, and D are correct. The colon and equal sign set (:=) performs an assignment; the guillemets or double angle bracket set (<< >>) is a label target for a GOTO statement;
the less than symbol and greater than symbol set (<>) is a not equal comparison operator;
and an exclamation mark and equal sign set (!=) is a not-equal comparison operator.
13. Which of the following are valid scalar data types in PL/SQL? (Multiple answers possible)
A. A TEXT data type
B. A VARCHAR2 data type
C. A NCHAR data type
D. A CHAR data type
E. A DATE data type
B, C, D, and E are correct. The TEXT data type isn’t a valid data type in PL/SQL, but it is a valid data type in MySQL.
14. Which of the following data types are best suited for scientific calculations in PL/SQL?
(Multiple answers possible)
A. A NUMBER data type
B. A PLS_INTEGER data type
C. A BINARY_DOUBLE data type
D. A BINARY_FLOAT data type
E. A BINARY_INTEGER data type
C and D are correct. Only the IEEE-754 variables BINARY_DOUBLE and BINARY_FLOAT are considered scientific computing data types.
15. Which of the following are reasons for using a system reference cursor?
A. A system reference cursor mimics a table collection
B. An alternative when you want to query data in one program and use it in another
C. A PL/SQL-only solution with the results of composite data type
D. A SQL or PL/SQL solution with the results of a system reference cursor
E. None of the above
B and C are correct. You use a system reference cursor when you want to query data
in one program and use it in another. System reference cursors are also PL/SQL-only
solutions with one exception that was covered in Chapter 2, and that’s using an Implicit
Record Set (IRS).