Lab 5. Data Types
Lab 5. Data Types
a. CHAR (Size)
Example: Name Char(25)
• This data type is used to store character string values of fixed length.
• The size in brackets determines the number of characters the cell can hold.
• The maximum number of characters (that is the size) this data type can hold is 255 characters.
• Default size is 1.
• ORACLE compares char values using blank-padded comparison semantics, if a value that is inserted in a
cell of CHAR data type is shorter than the size defined for then it will be padded with spaces on the right.
• The data held is right padded with spaces to whatever length specified.
• For example, in case of Name Char(25), if the data held in the variable Name is only 5 characters in length,
then the entry will be padded with 20 characters worth of spaces.
And at run time value is given as ‘Amita’, that is 5 character data. Then remaining 20 characters are padded
with blank spaces.
Name Char(25)
A m i t a
b. VARCHAR2 (Size):
Example: Name varchar2(25)
NUMBER (P, S)
Example: Price Number (10, 2)
• The NUMBER data type is used to store numbers (fixed or floating point).
• Numbers of virtually any magnitude maybe stored upto 38 digits of precision.
• Valid values are 0, and positive and negative numbers with magnitude 1.0E-130 to 9.9…E125.
• Numbers may be expressed in two ways; first with the numbers 0 to 9, the signs + and -, and a decimal
point(.); second, in scientific notation, such as, 1.85E3 for 1850.
• The precision P determines the maximum length of the data.
• The scale S determines the number of places to the right of the decimal.
• If scale is omitted then the default is zero.
• If precision is omitted, values are stored with their original precision upto the maximum of 38 digits.
P S
Price Number (10, 2)
VARCHAR(Size)
• It is used to specify a variable length string that can contain numbers, letters, and special characters.
• Its size can be from 0 to 65535 characters.
FLOAT(size, d)
• It is used to specify a floating point number.
• Its size parameter specifies the total number of digits.
• The number of digits after the decimal point is specified by d parameter.
DOUBLE(size, d)
• It is a normal size floating point number. Its size parameter specifies the total number of digits.
• The number of digits after the decimal is specified by d parameter.
DECIMAL(size, d)
• It is used to specify a fixed point number. Its size parameter specifies the total number of digits.
• The number of digits after the decimal parameter is specified by d parameter.
• The maximum value for the size is 65, and the default value is 10.
• The maximum value for d is 30, and the default value is 0.
DATETIME
• A date and time combination in YYYY-MM-DD HH:MM:SS format, between 1000-01-01 00:00:00 and
9999-12-31 23:59:59.
• For example, 3:30 in the afternoon on December 30th, 1973 would be stored as 1973-12-30 15:30:00.