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>Example 7–6 Using LiteralsDECLARE -- declare and assign variablesnumber1 PLS_INTEGER := 32000; -- numeric literalnumber2 NUMBER(8,3);char1 VARCHAR2(1) := 'x'; -- character literalchar2 VARCHAR2(1000);boolean BOOLEAN := TRUE; -- BOOLEAN literaldate1 DATE := '11-AUG-2005'; -- DATE literaltime1 TIMESTAMP;time2 TIMESTAMP WITH TIME ZONE;BEGINnumber2 := 3.125346e3; -- numeric literalnumber2 := -8300.00; -- numeric literalnumber2 := -14; -- numeric literalchar2 := q'!I'm writing an example string.!'; -- string literalchar2 := 'I''m writing an example string.'; -- need two single quotes heretime1 := '11-AUG-2005 11:01:01 PM'; -- TIMESTAMP literaltime2 := '11-AUG-2005 09:26:56.66 PM +02:00';END;/See Also:■■■<strong>Oracle</strong> Database <strong>SQL</strong> Reference for information on the syntax forliterals and the date and time types.<strong>Oracle</strong> Database Application <strong>Developer</strong>'s Guide - Fundamentals forexamples of performing date and time arithmetic.PL/<strong>SQL</strong> User's Guide and Reference for information on using literalswith PL/<strong>SQL</strong>.7.3.7 Declaring and Assigning Variables With DEFAULT or NOT NULLYou can use the keyword DEFAULT instead of the assignment operator to initializevariables. Use DEFAULT for variables that have a typical value. Use the assignmentoperator for variables (such as counters and accumulators) that have no typical value.You can also use DEFAULT to initialize subprogram parameters, cursor parameters,and fields in a user-defined record.Besides assigning an initial value, declarations can impose the NOT NULL constraint sothat assigning a NULL raises an error. The NOT NULL constraint must be followed by aninitialization clause.In Example 7–7 the declaration for avg_days_worked_month uses the DEFAULT toassign a value of 21 and the declarations for active_employee and monthly_salary use the NOT NULL constraint.Example 7–7Using DEFAULT and NOT NULLDECLARE -- declare and assign variableslast_nameVARCHAR2(30);first_nameVARCHAR2(25);employee_idNUMBER(6);active_employee BOOLEAN NOT NULL := TRUE; -- value cannot be NULLmonthly_salaryNUMBER(6) NOT NULL := 2000; -- value cannot be NULLnumber_of_days_worked NUMBER(2);pay_per_dayNUMBER(6,2);employee_count NUMBER(6) := 0;avg_days_worked_month NUMBER(2) DEFAULT 21; -- assign a default valueBEGIN7-8 <strong>SQL</strong> <strong>Developer</strong> Online Help

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

Saved successfully!

Ooh no, something went wrong!