Assign a value to a variable numage NUMBER3 20 Assign value to variable

Assign a value to a variable numage number3 20 assign

This preview shows page 15 - 17 out of 28 pages.

-- Assign a value to a variable. num_age NUMBER(3) := 20; -- Assign value to variable Multiple line comments begin denoted by use of the "/*" symbols at the beginning of the first 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 TYPES Table 11.4 lists the standard PL/SQL data types. These are the same data types used with SQL and are summarized here for your ease of reference. Table 11.4 Data Type Usage Sample Declaration VARCHAR2 and NVARCHAR2 Variable-length character strings FirstName VARCHAR2(30); CHAR and NCHAR Fixed-length character strings StudentGender CHAR(1); NUMBER Floating, fixed-point, or integer numbers Salary NUMBER(6); PLS_INTEGER (BINARY_INTEGER) Integers StudentID PLS_INTEGER; DATE Dates TodaysDate DATE; BOOLEAN TRUE / FALSE / NULL values OrderFlag BOOLEAN; LOB (It has four data types: BFILE, BLOB, CLOB and NCLOB) Large Objects Message CLOB; %TYPE Assumes the data type of the database field CustAddress customer.cadd %TYPE; Revised: 11-7-07 11 - 15
Image of page 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?
Image of page 16
Image of page 17

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture