Introduction to Oracle Data Types
Data type in Oracle database can be defined as fixed set of properties which is associated with every value of every column which in broader sense means that every value has a data type, which is associated with a specific kind of storage or memory properties like memory space, a specific range to which a value associated with that particular data type can extend, a specific set of constraints associated with it and it is specified for each column present in a table in a database.
List of Oracle Data Types
Given below is the list of oracle data types:
1. Character Data Type
Given below are the different character data types.
- char(size): It is used to store fixed length character string. It has a maximum size of 2000 bytes.
- varchar2(size): It is used to store variable length character string. It has a maximum size from 1byte to 4KB.
- nvarchar2(size): It is used to store variable length Unicode character string. The upper limit is 4000 bytes.
- long: It is also used to store variable length string and it is backward compatible. It can be used to store up to 2 gigabytes.
- raw: It is variable length binary strings. It has a maximum size of 2000 bytes.
- long raw: It is variable length binary strings and it is backward compatible. It has a maximum size of 2GB.
Example:
In this example we are going to create a table t1 with three columns each column having a different character data type and then insert a row of data into these columns. Once after we have done that we will use DUMP() function to find the details of each column.
Code:
Creating table:
CREATE TABLE t1 (
x CHAR(10),
b VARCHAR2(10),
z raw(10)
);
Inserting values into table:
INSERT INTO t1(x, b, z )
VALUES('Nil', 'Nil', '');
Selecting table:
SELECT
x,
DUMP(x),
b,
DUMP(b),
z,
DUMP(z)
FROM
t1;
Let us execute the queries in SQL developer and check the result.
Output:
As we can see in the above screen shot the DUMP function returns the detailed information of x, b and z columns.
2. Numeric Data Type
Given below are the different numeric data types present in Oracle:
- number(p, s): This is a numeric data type which has to arguments ’p’ is for precision and ‘s’ is scale. For example if number(8, 3) which means it has five digits before decimal and three digits after decimal. The precision range from 1 to 38 and scale is from range -84 and 127.
- dec(p, s): It is a float type numeric data type where ‘p’ is precision and ‘s’ is scale. The precision ranges from 1 to 38. Here also dec(3, 1) means 2 digits before decimal and one digit after decimal.
Example:
In this example we are going to create a table named number_example with two columns x and y which is of data type number and dec. Once the table is created we are going to insert some data and then check the contents of the table by using a SELECT command.
Code:
Creating table:
CREATE TABLE number_example (
x NUMBER(6, 2), y dec(6,2)
);
Inserting values into table:
INSERT INTO number_example
VALUES(100.99, 101.99);
INSERT INTO number_example
VALUES(80.552, 11.552);
Selecting table:
select * from number_example;
Let us run the queries in SQL developer and check the result.
Output:
As we can see in the screen shot that the size was declared (6, 2) so the second row contents were rounded to two digits after decimal.

4.5 (8,980 ratings)
View Course
3. Date Data Type
We are going to declare about the Date data types.
- date: As the name suggest it is used to store date type string values.
- timestamp: It gives fractional seconds precision and it will be a number between 0 and 9.
Example:
In this example we will create a table data_example with columns x and y having data types as DATE and TIMESTAMP respectively. We will then insert a row with values for both columns and then use SELECT statement to see the contents of the table.
Code:
Creating table:
CREATE TABLE date_example (
x DATE, y TIMESTAMP(2)
);
Inserting values into table:
INSERT INTO date_example
VALUES(sysdate, LOCALTIMESTAMP(2));
Selecting table:
select * from date_example;
Let us execute the queries in SQL Developer and check the result.
Output:
As we can see the column with TIMESTAMP data type gives us more accurate fractional time as compared to Date type.
4. Large Object Data Type
This type of data types are also known as LOB data types.
- blob: It is a type of data type which stores unstructured binary large objects and it can store up to 4 GB of binary data.
- clob: It is used to store single-byte and multi-byte character data and it can also store up to 4 GB of character data.
- nclob: It is used to store Unicode data. It can store up to 4 GB of character text data.
- ROWID data types: Rowid is a fixed length binary data and the format is BBBBBBB.RRRR.FFFFF where BBBBBBB is the block in the database file, RRRR is the row in the block and FFFFF is the database file.
Example:
Each row in an oracle database has an address. In this example we will try to get the row address by querying the pseudo column rowid which is of type ROWID.
Code:
select rowid , name from employee where employee_id ='AD001';
Let us now execute the query in SQL developer and check result.
Output:
Recommended Articles
This is a guide to Oracle Data Types. Here we discuss the introduction to Oracle Data Types along with the list of data types respectively. You may also have a look at the following articles to learn more –