1. 程式人生 > >《Oracle PL/SQL開發指南》學習筆記19——Control Structures(Review Section,Mastery Check)

《Oracle PL/SQL開發指南》學習筆記19——Control Structures(Review Section,Mastery Check)

這章是programming的核心所在。

Conditional Statements

Review Section
This section has described the following points about conditional compilation statements:
1. The PL/SQL language supports single-branching and multiple-branching statements without fall-through, and multiple-branching statements use either the ELSIF or CASE statement.
2. You can use conjunction (AND logic) or inclusion (OR logic) in conditional statements.
3. The PL/SQL language implements three-valued logic with the possibility of true, false, and null.
4. The NVL statement lets you reduce three-valued logic problems to two-valued logic in conditional statements.
5. You need to assign default values to dynamic variables when comparison values may fail because they hold null values.
6. The PL/SQL language supports both simple and searched CASE statements.
7. Searched CASE statements use a default selector of true but can be configured to use false as the selector value.
8. Conditional compilation supports any number of conditional compilation flags, like the $$DEBUG example used in this chapter.
Conditional compilation also supports predefined inquiry directives, like $$PLSQL_LINE and $$PLSQL_UNIT.

Iterative Statements

Review Section
This section has described the following points about iterative statements:
1. Iterative statements are blocks that let you repeat a statement or set of statements.
2. Iterative statements implement an exit guard and a block of repeatable statements.
3. The exit guard compares a loop index or variable against a sentinel value to determine when to exit the loop.
4. Entry guards and exit guards can work to bar entry to or exit from a loop, and they can be intrinsically linked to index counter and sentinel values.
5. To avoid runtime errors, programs should safeguard any dynamic variable values. You do that by checking whether they have null values before your program uses them. This type of checking is necessary because null values don't work properly as index counters because you can't increment them, or as comparison variables because you can't compare them.
6. The CONTINUE, CONTINUE WHEN, and GOTO statements let you skip the balance of iteration through a loop, and they require specialized handling with guard-on-entry loops to avoid infinite loops.
7. The range FOR loop lets you increment or decrement across data by comparing a range of values, and it hides the complexity of its guard-on-entry loop internals.
8. The WHILE loop is a guard-on-entry loop and requires careful attention to avoid infinite loops when skipping iterations inside of its logic.

Cursor Structures

Review Section
This section has described the following points about cursor structures:
1. Cursor structures return row-by-row managed result sets from SQL SELECT statements.
2. Implicit cursors exist for all DML statements, such as the INSERT, UPDATE, DELETE, and MERGE statements.
3. PL/SQL supports the %FOUND, %NOTFOUND, %ISOPEN, and %ROWCOUNT implicit cursor attributes.
4. The SELECT-INTO statement is a single-row implicit cursor.
5. The INSERT, UPDATE, DELETE, and MERGE statements are multiple-row implicit cursors, although you can limit them to a single row.
6. Cursors can be static or dynamic, and dynamic implicit cursors can include placeholders that are references to local variables.
7. SELECT statement cursors can have formal parameters, like functions and procedures.
8. Cursors support nested cursors, which are called subcursors

Bulk Statments

Review Section
This section has described the following points about bulk statements:
1. Bulk processing can work with parallel collections of scalar data types or collections of record data types.
2. The BULK COLLECT statement lets you gather rows from a cursor into a collection, and collections can be single or parallel collections of scalar data types, or collections of records.
3. PL/SQL supports the %BULK_EXCEPTIONS(i) and %BULK_ROWCOUNTS(i) bulk collection attributes.
4. The FORALL statement lets you take a collection and pass it to an INSERT, UPDATE, or DELETE statement.
5. The %ROWCOUNT attribute also works with bulk inserts, updates, and deletes, but in the case of MERGE statements, you're never sure which rows are inserted or updated.
6. Record collections work best when FORALL statements work with INSERT or UPDATE statements.
7. Single scalar collections work best when FORALL statements work with DELETE statements.
8.  By default, Oracle's exception handling stops program logic with a single error, which isn't optimal for bulk processing. The %BULK_EXCEPTION collection attribute lets you override the default exception handling process in a FORALL statement, and lets you capture errors for problem rows while successfully processing those rows without errors.

Mastery Check


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. Conjunctive logic involves determining when two or more things are true at the same time.
True. Conjunctive logic involves two or more comparisons joined by an AND keyword.
Two or all of the comparisons must be true for a conjunctive statement to be true.
2. Inclusion logic involves determining when one or another thing is true at any time.
True. Inclusion logic involves two or more comparisons joined by an OR keyword. At least one item must be found true, and when one is found true, short-circuit logic stops making any remaining comparisons.
3. Short-circuit logic occurs with inclusion logic.
True. Inclusion logic uses short-circuit logic, which stops making comparisons once one item is found true.
4. Databases always rely on two-valued logic.
False. Databases rely on three-valued logic because they must be capable of comparing a null value. That’s why Oracle Database and other databases support the IS [NOT] NULL reference comparison operator.
5. A searched CASE statement may use a string or numeric selector.
True. A searched CASE statement evaluates Boolean logic, or the result of comparison operations.
6. A simple CASE statement can use a numeric selector.
True. A simple CASE statement evaluates a numeric value, and when it finds a match in one of the WHEN clauses, it exits the CASE statement.
7. Conditional compilation supports conditional compilation flags.
True. Conditional compilation supports any number of compilation flags.
8. A CONTINUE statement lets you skip the balance of an iteration through a loop.
True. The CONTINUE statement instructs the program to skip the balance of an iteration cycle and return to the top of the loop.
9. A SELECT-INTO statement is an example of an explicit cursor.
False. A SELECT-INTO statement is an implicit cursor.
10. The FORALL statement lets you perform bulk INSERT statements.
True. The FORLL statement is the key structure for performing bulk INSERT and UPDATE statements.

Multiple Choice:
11. A conditional statement applied against two operands can evaluate which of the following? (Multiple answers possible)
A. The truth of a comparison involving only not-null values
B. The non-truth (or falsity) of a comparison involving only not-null values
C. The truth of a comparison involving one or more null values
D. The non-truth (or falsity) of a comparison involving one or more null values
E. The truth of null values
A is correct. Comparison operations are three-valued logic comparisons unless you’re checking for a null value. Checking for a null value is an evaluation of what a reference points to, not the value that it holds. Comparison operations between two operands only work when both operands hold not-null values.
12. Which of the following are only guard-on-entry loops? (Multiple answers possible)
A. A simple range loop
B. A range FOR loop
C. A WHILE loop
D. A DO-UNTIL loop
E. A DO-WHILE loop
A, B, and C are correct. A simple loop can be coded to guard on entry or exit. A range FOR loop guards on entry and exit, and a WHILE loop guards entry only. DO-UNTIL and DO-WHILE aren’t loop structures in PL/SQL.
13. Which of the following guards entry and exit to the loop in PL/SQL? (Multiple answers possible)
A. A range FOR loop
B. A cursor FOR loop
C. A simple loop
D. A DO-WHILE loop
E. A WHILE loop
A and B are correct. The FOR loop guards entry and exit and manages them implicitly.
14. Which of the following are only guard-on-exit loops? (Multiple answers possible)
A. A simple cursor loop
B. A simple range loop
C. A cursor FOR loop
D. A WHILE loop
E. A range FOR loop
A and B are correct. Only the simple loop allows unfettered access, and allows you to guard on exit. That lets you run the logic once and exit regardless of any conditions before entering the loop.

15. Which of the following collections work best with a bulk delete operation on a welldefined (or normalized) table with a surrogate key for its single-column primary key?
(Multiple answers possible)
A. Parallel scalar collections
B. A single scalar collection
C. A single record collection
D. All of the above
E. None of the above
B and C are correct. Bulk operations only work when there’s one collection to traverse, and that means a single scalar or record collection.

相關推薦

Oracle PL/SQL開發指南學習筆記19——Control StructuresReview SectionMastery Check

這章是programming的核心所在。 Conditional Statements Review Section This section has described the following points about conditional compilation

Oracle PL/SQL開發指南學習筆記1——Oracle PL/SQL程式開發概覽

本章內容: 1. PL/SQL的歷史和背景 2. Oracle開發架構   知識點: 1. SQL和PL/SQL的關係: The SQL language is the interface to the Oracle Database 12c database

Oracle PL/SQL開發指南學習筆記31——原始碼除錯——函式和過程第四部分物件表函式result_cache子句

  建立一個物件表函式有三個步驟: 1. 定義記錄結構為物件型別 2. 定義集合 3. 定義一個函式來展示如何從PL/SQL上下文向SQL上下文返回集合   1. 建立基本的SQL使用者自定義型別(UDT) 注意:發現竟然不能使用distinct關

Oracle PL/SQL開發指南學習筆記31——原始碼除錯——函式和過程第三部分並行查詢及管道函式

  1. PARALLEL_ENABLE子句(啟用並行查詢以提高效能) 首次接觸,學習一下: PARALLEL_ENABLE lets you designate a function to support parallel query capabilities. This

Oracle PL/SQL開發指南學習筆記31——原始碼除錯——函式和過程第二部分函式

  1. 命名塊函式原型 [{EDITIONALBE | NONEDITIONALBE}] FUNCTION function_name ( parameter [IN][OUT] [NOCOPY] sql_datatype | plsql_datatype [, parame

Oracle PL/SQL開發指南學習筆記31——原始碼除錯——函式和過程第一部分函式呼叫表示法

這節很基礎,卻發現了Oracle的可愛之處,一個函式呼叫就提供了這麼多選項,學起來真夠累的!   1. 在PL/SQL中呼叫函式表示法  SQL> /* Formatted on 2018/12/4 0:08:00 (QP5 v5.256.13226.355

Oracle PL/SQL開發指南學習筆記30——原始碼除錯——錯誤管理第四部分utl_call_stack包中的函式

utl_call_stack包中的函式整理如下: Package Function Description backtrace_depth Returns the number of backtrace items in

Oracle PL/SQL開發指南學習筆記26——觸發器Triggers章節回顧、測試第二部分

複合觸發器(Compound Triggers) Review Section This section has described the following points about the Oracle Database 12c compound database

Oracle PL/SQL開發指南學習筆記28——原始碼除錯——PL/SQL基礎知識第三部分

1. 變數賦值時(隱式)強制型別轉換 (讓我想起了將近二十年前學C語言時的場景) SQL> edit Wrote file afiedt.buf 1 DECLARE 2 lv_input INTEGER; 3 BEGIN 4 lv_inp

Oracle PL/SQL開發指南學習筆記27——動態SQLDynamic SQL章節回顧、測試

動態SQL語句是一種強大的技術,通過它可以在程式執行時寫和執行查詢,修改DDL和DML語句。 本地動態SQL(Native Dynamic SQL (NDS)) Review Section This section has described the following

Oracle PL/SQL語句基礎學習筆記(上)

PL/SQL是ORACLE對標準資料庫語言的擴充套件,ORACLE公司已經將PL/SQL整合到ORACLE 伺服器和其他工具中了,近幾年中更多的開發人員和DBA開始使用PL/SQL,本文將講述PL/SQL基礎語法,結構和元件、以及如何設計並執行一個PL/SQL程

Oracle PL/SQL語句基礎學習筆記(下)

遊標 遊標: 遊標(cursor)可以被看作指向結果集(a set of rows)中一行的指標(pointer)。在oracle資料庫中可以使用顯示或隱式兩種遊標。 1、隱式遊標 在執行一個sql語句時,oracle伺服器將自動建立一個隱式遊標,這

Oracle PL SQL專家指南 高級PL/SQL解決方安案的設計與開發

pad tkprof microsoft ext michael 加密 sql腳本 pro 體系結構 下載地址:網盤下載 內容介紹編輯本書所包含的大量信息可將您的編程技術提高到一個新的水平。您將學習編寫動態PL/SQL程序和Oracle數據庫接口、執行復雜計算,以及使用高級

【CTP學習筆記】CTP客戶端開發指南 學習筆記

1、組播行情        使用函式CreateFtdcMdApi 建立CThostFtdcMdApi 的例項。其中第一個引數是本地流檔案生成的目錄。流檔案是行情介面或交易介面在本地生成的流檔案,字尾名為.con。流檔案中記錄著客戶端收到的所有的資料流的數量。第二個引數描述

Oracle PL/SQL開發基礎第三十四彈:RAISE_APPLICATION_ERROR

RAISE_APPLICATION_ERROR在子程式內部使用時,能從儲存子程式中丟擲自定義的錯誤訊息。這樣就能將錯誤報告給應用程式而避免範圍未捕獲異常。 語法如下: RAISE_APPLICATI

Java學習筆記—多線程原子類java.util.concurrent.atomic包轉載

支持 位置 dset 賦值 嵌入 imp ans 匯編指令 sta 原子類 Java從JDK 1.5開始提供了java.util.concurrent.atomic包(以下簡稱Atomic包),這個包中 的原子操作類提供了一種用法簡單、性能高效、線程安全地更新一個變量的方

學習筆記-C語言6指標與動態記憶體分配

1. 指標 指標的引入: 指標是C語言最強大的功能之一,使用指標可以儲存某個變數在記憶體中的地址,並且通過操作指標來對該片記憶體進行靈活的操作,例如改變原變數的值,或者構造複雜的資料結構。指標一般初始化為NULL(0)。& 是取地址運算,* 是間接運算子,通過 * 可以訪問與修改

快學Scala學習筆記及習題解答10-11特質與操作符

本文Scala使用的版本是2.11.8 第10章 特質 10.1 基本使用 特質可以同時擁有抽象方法和具體方法,而類可以實現多個特質。 import java.util.Date trait AbsLogged { // 特質中未被

設計模式C++學習筆記之十一c/c++面試筆試題

一、指標與引用有什麼區別? 1、指標會佔用記憶體,引用不佔用記憶體。 2、引用在定義時必須初始化。 3、沒有空的引用,但是有空的指標。 二、static關鍵的幾個作用 1、函式體內的static變數的作用範圍為該函式體,該變數記憶體只分配一次,因此其值在下次再呼叫該函式時

JDBC學習筆記 MySQL的使用建立表插入查詢以及刪除

1.建立資料庫 create database mydata; 2.連線資料庫 只有連線了才能在這個資料庫下建立表(不然不知道建哪裡去了) use mydata; 3.建立表 create table person( number int(11),