-- Assign a value to a variable.num_age NUMBER(3) := 20; -- Assign value to variableMultiple line comments begin denoted by use of the "/*" symbols at the beginning of thefirst comment line and with the "*/" at the end of the last comment line as shown here./* This is a multiple line comment.This is the second line of the comment. */COMMON DATA TYPESTable 11.4 lists the standard PL/SQL data types. These are the same data types used with SQLand are summarized here for your ease of reference. Table 11.4Data TypeUsageSample DeclarationVARCHAR2 and NVARCHAR2Variable-length character stringsFirstName VARCHAR2(30);CHAR and NCHARFixed-length character stringsStudentGender CHAR(1);NUMBERFloating, fixed-point,or integer numbersSalary NUMBER(6);PLS_INTEGER(BINARY_INTEGER)IntegersStudentID PLS_INTEGER;DATEDatesTodaysDate DATE;BOOLEANTRUE / FALSE / NULL valuesOrderFlag BOOLEAN;LOB(It has four data types: BFILE,BLOB, CLOB and NCLOB)Large ObjectsMessage CLOB;%TYPEAssumes the data type of the database fieldCustAddress customer.cadd%TYPE;Revised: 11-7-07 11 - 15
Chapter 11%ROWTYPEAssumes the data type of a database rowCustOrderRecord cust_order%ROWTYPE;VARCHAR2 and NVARCHAR2The VARCHAR2data type stores variable-length string data up to a maximum length of32,767 bytes. In fact, when you declare a VARCHAR2 variable, you can specify whether youwant space allocated for bytes or characters because some database character sets forinternational languages require more than a single byte to store a character. The syntax withexamples is:VARCHAR2(size [CHAR | BYTE])VARCHAR2(15)VARCHAR2(50 CHAR)The size must be a numeric integer; a variable name cannot be used. If you do notspecify the CHAR or BYTE keywords, then BYTE is the default. Although a VARCHAR2variable can store a large number of characters, a maximum of 4,000 bytes can be inserted into aVARCHAR2 database column. You must take care not to confuse these limitations on this datatype. If you need to store a very large value from a VARCHAR2 variable to a database column,the database column needs to be declared as a LONG column data type. A LONG databasecolumn can store any size VARCHAR2 value, but only 32,767 bytes can be retrieved from aLONG database column into a VARCHAR2 variable.We know that a VARCHAR2 database column of size 50, for example, will allocate only4 bytes to the storage of the name 'Doug' for the Roman alphabet because the data is stored invariable lengths. What about a VARCHAR2 variable?