Data Types in Oracle SQL with examples
List of Data Types in oracle SQL
- Character Data types
- Numerical data types
- long objects
- Date and time data types
Character Data Types
- CHAR
- VARCHAR
- VARCHAR2
CHAR
- Char means Character, it is a data type that used in string of any variables or objects.
- It is a static data type, so the size of the data type is fixed
- Performance : Char data type is speed when compared to the VARCHAR2 data type, but memory wise it will consume more.
VARCHAR
- Varchar is also a Character data type used for string of any variables or objects.
- It is a variable data type, so the size of the data type is not fixed. So this data type is dynamic.
- Performance : Varchar data type is less speed when compared to the CHAR data type, but memory wise it will consume less.
VARCHAR2
- VARCHAR2 is also a Character data type used for string of any variable or objects.
- It is very similar to VARCHAR.
Difference between CHAR and VARCHAR 2 in oracle SQL
Difference between VARCHAR and VARCHAR2 in oracle SQL
Numerical Data type
- In Number Data type, we no need to mention the size.
- we can't able to insert decimal values in the number data type instead use VARCHAR2
- The value which contains only 0 - 9 only.
- Other than that NULL can be inserted in the NUMBER data type. While Inserting NULL value no need to use literal (' ') in any of the data's.
Long Objects Data Type
Before ORACLE Database 8
After ORACLE Database 8
Some Important Data type used in SQL and PL/SQL
1, Scalar Data type
NUMBER, PLS_INTEGER, BINARY_FLOAT
CHAR, VARCHAR2, NCHAR, NVARCHAR2
RAW
BOOLEAN
BLOB, CLOB, NCLOB
DATE, TIMESTAMP
2, Composite Data type
RECORD
%ROWTYPE
%TYPE
COLLECTION
VARRAY
NESTED TABLE
Associative Array.
3, Reference Data type
Refcursor data type.
EXAMPLE
TABLE: customers
COLUMNS: id, name, age,
V_custom_Detail customers%ROWTYPE;
V_name customers.name%type;
DATE
Date is a datatype which is used whenever we a column contains any date format means it will be comes under this data type it is like a string, we need to use literals (‘) while creating a column for the particular table.
Timestamp
It is similar like a date data type it contains current time that is running in the server time or system time in the time format is called timestamp Ex: HH:MM: SS
COLLECTION DATA TYPE
We can be able to store only single values in a variable in order to store multiple values in a variable we will go for collection data type so with the help of that we can able to retrieve many values using single variable and so the performance wise also it will be good to use it.
And this collection data type can be used in three different ways such as
Associative array
Nested Table
Varray
This collection is covered in separate session in PLSQL.
Example:
CREATE TABLE customers (id NUMBER
, Name VARCHAR2(50)
, Address CHAR (200)
, due_date DATE
, due_time TIMESTAMP
);
INSERT INTO customers VALUES (1, ‘Kavi’, ‘Chennai’, ’23-JUL-21’, ’11:24:30’) ;
Comments
Post a Comment
Thanks for commenting, we will always respond your comment.