Oracle SQL Developer
Oracle SQL Developer
Oracle SQL Developer
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Utilizing the Main Features of PL/<strong>SQL</strong>END;/7.3.2 Using CommentsFor another example of PL/<strong>SQL</strong> block structure, see Example 7–8 on page 7-9.The PL/<strong>SQL</strong> compiler ignores comments, but you should not. Adding comments toyour program promotes readability and help others understand your code. Generally,you use comments to describe the purpose and use of each code segment. PL/<strong>SQL</strong>supports single-line and multi-line comment styles.Single-line comments begin with a double hyphen (--) anywhere on a line and extendto the end of the line. Multi-line comments begin with a slash-asterisk (/*), end withan asterisk-slash (*/), and can span multiple lines. See Example 7–2.Example 7–2Using CommentsDECLARE -- Declare variables here.monthly_salaryNUMBER(6); -- This is the monthly salary.number_of_days_worked NUMBER(2); -- This is the days in one month.pay_per_dayNUMBER(6,2); -- Calculate this value.BEGIN-- First assign values to the variables.monthly_salary := 2290;number_of_days_worked := 21;-- Now calculate the value on the following line.pay_per_day := monthly_salary/number_of_days_worked;-- the following displays output from the PL/<strong>SQL</strong> blockDBMS_OUTPUT.PUT_LINE('The pay per day is ' || TO_CHAR(pay_per_day));EXCEPTION/* This is a simple example of an exeception handler to trap division by zero.In actual practice, it would be best to check whether a variable iszero before using it as a divisor. */WHEN ZERO_DIVIDE THENpay_per_day := 0; -- set to 0 if divisor equals 0END;/While testing or debugging a program, you might want to disable a line of code. Thefollowing example shows how you can disable a single line by making it a comment:-- pay_per_day := monthly_salary/number_of_days_worked;You can use multi-line comment delimiters to comment-out large sections of code.7.3.3 Declaring Variables and ConstantsVariables can have any <strong>SQL</strong> data type, such as VARCHAR2, DATE, or NUMBER, or aPL/<strong>SQL</strong>-only data type, such as BOOLEAN or PLS_INTEGER. You can also declarenested tables, variable-size arrays (varrays for short), and records using the TABLE,VARRAY, and RECORD composite data types. See "Working With PL/<strong>SQL</strong> DataStructures" on page 7-17.Declaring a constant is like declaring a variable except that you must add the keywordCONSTANT and immediately assign a value to the constant. No further assignments to7-4 <strong>SQL</strong> <strong>Developer</strong> Online Help