Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Data Types ORACLE/MySQL

Every table consists of columns and rows.


Columns/Attributes have data types.
Data types are used to mention the type of value that a column can hold.

Oracle/MySQL data types can be categorized into three broad categories:


1. Character
2. Numeric, and
3. Date

1. Oracle Character data types:


Character data types are of two types:
a. Char,
b. Varchar2

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.

Let the column Name is defined as Char(25).


Name Char(25)

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

Padded with blank spaces

b. VARCHAR2 (Size):
Example: Name varchar2(25)

• This data type is used to store variable length alphanumeric data.


• It is a more flexible form of the CHAR data type.
• This data type can hold maximum 4000 characters.
• It is different from CHAR data type as in VARCHAR2 the inserted values will not be padded with spaces.
• It is slower that CHAR.
2. Oracle Numeric Data Types

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)

Precision (P) 10 denotes maximum length Scale (S) 2 denotes maximum


of Price can be of 10 digits including length after decimal point can be
before decimal place digits (8 digits) and 2.
after decimal digits (2 digits).
That is, 12345678.98, means 8 digits before decimal point and 2 digits after decimal point.

3. Oracle Date Data type:


DATE
• This date type is used to represent date and time.
• The standard format is DD-MON-YY, for example- 28-AUG-20.
• Date has fix format, so there is no need to mention size.
• Default date for a date field is the first day of the current month.
• Default time is 12:00:00 am.
• Valid date ranges from January 1, 4712 B.C. to December 31, 4712 A.D.

MySQL String Data Types


CHAR(Size)
• It is used to specify a fixed length string that can contain numbers, letters, and special characters.
• Its size can be 0 to 255 characters.
• Default is 1.

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.

MySQL Numeric Data Types


INT(size)
• It is used for the integer value.
• Its signed range varies from -2147483648 to 2147483647 and unsigned range varies from 0 to 4294967295.
• You can specify a width of up to 11 digits.
INTEGER(size)
It is equal to INT(size).

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.

MySQL Date and Time Data Types


DATE
• It is used to specify date format YYYY-MM-DD.
• Its supported range is from '1000-01-01' to '9999-12-31'.

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.

You might also like