12.07.2015 Views

Oracle SQL Developer

Oracle SQL Developer

Oracle SQL Developer

SHOW MORE
SHOW LESS

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>the constant are allowed. For an example, see avg_days_worked_month inExample 7–3.For example, assume that you want to declare variables for employee data, such asemployee_id to hold 6-digit numbers and active_employee to hold the Booleanvalue TRUE or FALSE. You declare these and related employee variables and constantsas shown in Example 7–3.Note that there is a semi-colon (;) at the end of each line in the declaration section.Also, note the use of the NULL statement which enables you to execute and test thePL/<strong>SQL</strong> block.You can choose any naming convention for variables that is appropriate for yourapplication. For example, you could begin each variable name with the v_ prefix toemphasize that these are variable names.Example 7–3 Declaring Variables in PL/<strong>SQL</strong>DECLARE -- declare the variables in this sectionlast_nameVARCHAR2(30);first_nameVARCHAR2(25);employee_idNUMBER(6);active_employee BOOLEAN;monthly_salaryNUMBER(6);number_of_days_worked NUMBER(2);pay_per_dayNUMBER(6,2);avg_days_worked_month CONSTANT NUMBER(2) := 21; -- a constant variableBEGINNULL; -- NULL statement does nothing, allows this block to executed and testedEND;/7.3.4 Using Identifiers in PL/<strong>SQL</strong>See Also: PL/<strong>SQL</strong> User's Guide and Reference for information on datatypes used with PL/<strong>SQL</strong>, including the PL/<strong>SQL</strong> BOOLEAN and PLS_INTEGER data typesYou use identifiers to name PL/<strong>SQL</strong> program items and units, such as constants,variables, exceptions, and subprograms. An identifier consists of a letter optionallyfollowed by more letters, numerals, dollar signs, underscores, and number signs.The declaration section in Example 7–4 illustrates some valid identifiers. You can seeadditional examples of valid identifiers for variable names in Example 7–2 on page 7-4and Example 7–3 on page 7-5.Example 7–4Valid Identifiers for VariablesDECLARE -- all declarations use valid identifiersxNUMBER;t2NUMBER;phone#VARCHAR2(12);credit_limit NUMBER;oracle$number NUMBER;money$$$tree NUMBER;SN##VARCHAR2(9);try_againBOOLEAN;BEGINNULL;END;/PL/<strong>SQL</strong>: Usage Information 7-5

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!