Beruflich Dokumente
Kultur Dokumente
Objectives
After completing this lesson, you should be able to: Implement the sequence calls to NEXTVAL and CURRVAL without using a SQL statement to retrieve the values Use the new CONTINUE statement to control the next loop iteration or to leave a loop Use both named and mixed notation calls to functions from a SQL statement Use the ALTER TABLE statement to change tables to readonly status
6-2
Lesson Agenda
Changes to sequence calls The new CONTINUE statement
6-3
5 4
6-4
5 4
6-5
6-6
6-7
Lesson Agenda
Changes to sequence calls The new CONTINUE statement
6-8
Benefits:
Eases the programming process May see a small performance improvement over the previous programming workarounds to simulate the CONTINUE statement
6-9
6 - 10
DECLARE v_total SIMPLE_INTEGER := 0; BEGIN FOR i IN 1..10 LOOP v_total := v_total + i; 1 dbms_output.put_line ('Total is: '|| v_total); CONTINUE WHEN i > 5; v_total := v_total + i; dbms_output.put_line 2 ('End of Loop Total is: '|| v_total); END LOOP; END; /
is:
is:
is:
is:
6 - 11
CREATE OR REPLACE PROCEDURE two_loop IS v_total NUMBER := 0; BEGIN <<BeforeTopLoop>> FOR i IN 1..10 LOOP v_total := v_total + 1; dbms_output.put_line ('Total is: ' || v_total); FOR j IN 1..10 LOOP CONTINUE BeforeTopLoop WHEN i + j > 5; v_total := v_total + 1; END LOOP; END LOOP; END two_loop; Procedure created.
--RESULTS:
EXECUTE two_loop
Total Total Total Total Total Total Total Total Total Total is: is: is: is: is: is: is: is: is: is: 1 6 10 13 15 16 17 18 19 20
6 - 12
6 - 13
Lesson Agenda
Changes to sequence calls The new CONTINUE statement
6 - 14
Benefits:
For long parameter lists, with most having default values, you can omit values from the optional parameters. You can avoid duplicating the default value of the optional parameter at each call site.
6 - 15
CREATE OR REPLACE FUNCTION f ( p1 IN NUMBER DEFAULT 1, p5 IN NUMBER DEFAULT 5) RETURN NUMBER IS v number; BEGIN v:= p1 + (p5 * 2); RETURN v; END f; / Function created.
SELECT f(p5 => 10) FROM DUAL; F(P5=>10) ---------21
6 - 16
Lesson Agenda
Changes to sequence calls The new CONTINUE statement
6 - 17
Read-Only Tables
Use the ALTER TABLE syntax to put a table into read-only mode: Prevents DDL or DML changes during table maintenance Changes it back into read/write mode
ALTER TABLE customers READ ONLY; -- perform table maintenance and then -- return table back to read/write mode ALTER TABLE customers READ WRITE;
6 - 18
Summary
In this lesson, you should have learned how to: Implement the sequence calls to NEXTVAL and CURRVAL without using a SQL statement to retrieve the values. Use the new CONTINUE statement to control the next loop iteration or to leave a loop. Use both named and mixed notation calls to functions from a SQL statement. Use the ALTER TABLE statement to change tables to readonly status.
6 - 19
Practice 6 Overview: Using the New SQL and PL/SQL Usability Features
This practice covers the following topics: Trying the new syntax for sequences Controlling loop iteration with the CONTINUE statement Using the named and mixed notation calls to functions from a SQL statement Changing the status of a table to read-only
6 - 20