TAILIEUCHUNG - Oracle XSQL- P14

Oracle XSQL- P14Welcome to the exciting world of eXtended Structured Query Language (XSQL) development! What’s so exciting? Efficiency and ease of use. XSQL isn’t some razzle-dazzle technology to wow your users. It also isn’t the latest X standard du jour that no one can stop talking about until you ask, “But what does it do for me today?” The problem with all of the great stuff out there is that no one technology does it all. | 240 Chapter 9 The WHILE LOOP moves the EXIT condition to the top of the loop SET SERVEROUTPUT ON DECLARE dummy_var NUMBER 2 BEGIN dummy_var 1 WHILE dummy_var 15 LOOP dummy_var dummy_var dummy_var dummy_var 1 END LOOP END The FOR LOOP is most convenient for this kind of loop. It handles the counting for you. You are also guaranteed that the FOR LOOP will exit PL SQL won t let you assign to the counter while the loop is in progress. SET SERVEROUTPUT ON BEGIN FOR dummy_var IN LOOP dummy_var dummy_var END LOOP END Sequential Control Structures The sequential control structures are the GOTO and the NULL statements. You shouldn t use GOTO statements in your code even if it is really complicated. Instead you should try to simplify your code and probably write some subroutines. If you really really have to write a GOTO here is how you do it statement statement GOTO goto_target statement statement statement goto_target statement you want to go to The NULL statement does nothing. It is convenient as a placeholder and generally should be removed after development. During development you might need it PL SQL 241 because of PL SQL s requirement that each block have at least one valid statement. If you have constructed a complicated series of IF-THEN-ELSE statements you might find that you don t want a particular block to do anything. However your PL SQL won t execute without a valid statement. Instead of disturbing the overall structure of your code you can just throw in a NULL statement. In this way you meet both goals The code will run and the problem block won t do anything. Here s an example IF a b THEN NULL END IF Cursors Earlier in this chapter in the section entitled Declaring Variables you got your first glimpse of cursors. Now you get to see them in action. A cursor allows you to programmatically move through the results of a SQL query. Here is an example SET SERVEROUTPUT ON DECLARE CURSOR emp_cursor IS SELECT FROM emp .

TỪ KHÓA LIÊN QUAN
TÀI LIỆU HOT