PL - SQL Data Types - Oracle Data Types
PL - SQL Data Types - Oracle Data Types
(https://way2tutorial.com/)
Scalar types
Scalar data type haven't internal components. It is like a linear data type. Scales data type divides into four different
types character, numeric, boolean or date/time type.
https://way2tutorial.com/plsql/plsql-data-types.php 1/7
9/12/2019 PL/SQL Data Types - Oracle Data Types
DEC 38 digits
DECIMAL 38 digits
NUMERIC 38 digits
NATURAL NATURAL/POSITIVE data type prevent to store negative value, allow only
positive values.
POSITIVE
POSITIVEN
SPONSORED SEARCHES
https://way2tutorial.com/plsql/plsql-data-types.php 2/7
9/12/2019 PL/SQL Data Types - Oracle Data Types
Character Data types used to store an alphabetic/alphanumeric character. Following are some character data types
in PL/SQL,
CHAR CHAR data type used to store character data within a predefined 32767 bytes
length.
CHARACTER CHARACTER data type same as CHAR data type. It is another name of 32767 bytes
CHAR data type.
VARCHAR2 VARCHAR2 data type used to store variable strings data within a 32767 bytes
predefined length.
VARCHAR2 Subtypes: the Following subtype defines the same length
value.
VARCHAR
NCHAR NCHAR data type used to store national character data within a 32767 bytes
predefined length.
NVARCHAR2 NVARCHAR2 data type used to store Unicode string data within a 32767 bytes
predefined length.
RAW The RAW data type used to store binary data such as images, 32767 bytes
graphics, etc.
LONG LONG data type used to store variable string data within a predefined 32760 bytes
length, This data type used for backward compatibility. Please use
LONG data to the CLOB type.
LONG RAW LONG RAW data type same as LONG type used to store variable 32760 bytes
string data within a predefined length, This data type used for
backward compatibility.
Use LONG RAW data type for storing BLOB type data.
ROWID The ROWID data type represents the actual storage address of a row. And table index
identities as a logical rowid. This data type used to storing backward compatibility. We
strongly recommended to use UROWID data type.
UROWID[(size)] The UROWID data type identifies as universal rowid, same as ROWID 4000 bytes
data type. Use UROWID data type for developing newer applications.
Optional, You can also specify the size of UROWID column type.
Datatype Description
Boolean Boolean data type stores logical values. Boolean data types doesn't take any parameters.
Boolean data type store, either TRUE or FALSE. Also, store NULL, Oracle treats NULL as an
unassigned boolean variable.
You can not fetch boolean column value from another table.
https://way2tutorial.com/plsql/plsql-data-types.php 3/7
9/12/2019 PL/SQL Data Types - Oracle Data Types
Date/Time Datatypes
A variable that has date/time data type hold value call datetimes. Oracle SQL automatically converts character value
into default date format ('DD-MON-YY') TO_DATE values. Following are Date/Time data types in Oracle SQL.
DATE DATE data type to store valid date-time format with a fixed length. Starting Jan 1, 4712 BC to
date from Jan 1, 4712 BC to Dec 31, 9999 AD. Dec 31, 9999 AD
TIMESTAMP TIMESTAMP data type to store valid date (year, month, day) with time (hour, minute, second).
Datatype Description
INTERVAL YEAR TO INTERVAL YEAR TO MONTH data type is used to store and manipulate intervals of year and
MONTH month. Syntax: INTERVAL YEAR [ (precision) ] TO MONTH
Note: precision specifies the number of digits in the year's field range from 0 to 4 and
default is 2.
Example: following example declares variable data type INTERVAL YEAR TO MONTH and
assign interval 45 years and 7 months.
1 DECLARE
2 inter INTERVAL YEAR(2) TO MONTH;
3 BEGIN
4 inter := INTERVAL '45-7' YEAR TO MONTH;
5 inter := '45-7'; -- assign from character type (implicit conversion)
6 inter := INTERVAL '7' MONTH; -- Specify Months
7 inter := INTERVAL '45' YEAR; -- Specify years
8 END;
https://way2tutorial.com/plsql/plsql-data-types.php 4/7
9/12/2019 PL/SQL Data Types - Oracle Data Types
INTERVAL DAY TO INTERVAL DAY TO SECOND data type is used to store and manipulate intervals of days,
SECOND hours, minutes, and seconds.
Syntax: INTERVAL DAY [ (leading_precision ) ] TO
SECOND[(fractional_seconds_precision)]
Note: leading_precision and fractional_seconds_precision specifies number of digits in
days field range from 0 to 9. The defaults are 2 and 6.
Example: following example declare variable data type INTERVAL DAY TO SECOND.
1 DECLARE
2 inter INTERVAL DAY(3) TO SECOND(3);
3 BEGIN
4 IF inter > INTERVAL '6' DAY ...
5 ...
6 END;
In PL/SQL datetime data type or interval data type fields values show the valid values for each field.
MONTH 01 to 12 0 to 11
HOUR 00 to 23 0 to 23
MINUTE 00 to 59 0 to 59
SPONSORED SEARCHES
best book for sql and plsql how much is it to rent a blob
BFILE BFILE data type to store a large binary object into Operating System Size: up to 4GB (232 - 1 byte)
file. This data type variable store full file locator's path, which points Directory name: 30 character
to a stored binary object within a server. BFILE data type read-only, File name: 255 characters
you can't modify them.
BLOB BLOB data type same as BFILE data type to store an unstructured Size: 8 TB to 128 TB
binary object into Operating System file. BLOB type fully supported (4GB - 1) * DB_BLOCK_SIZE
transactions are recoverable and replicated.
https://way2tutorial.com/plsql/plsql-data-types.php 5/7
9/12/2019 PL/SQL Data Types - Oracle Data Types
CLOB CLOB data type to store large blocks of character data into Database. Size: 8 TB to 128 TB
Store single byte and multi-byte character data. CLOB type fully (4GB - 1) * DB_BLOCK_SIZE
supported transactions are recoverable and replicated.
NCLOB NCLOB data type to store large blocks of NCHAR data into Database. Size: 8 TB to 128 TB
Store single byte and multi-byte character data. NCLOB type fully (4GB - 1) * DB_BLOCK_SIZE
supported transactions are recoverable and replicated.
Datatype Description
%Type This data type is used to store value unknown data type column in a table. The column is
identified by %type data type.
Eg. emp.eno%type
emp name is a table,
eno is an unknown data type column and
%Type is data type to hold the value.
%RowType This data type is used to store values unknown data type in all columns in a table. All
columns are identified by %RowType datatype.
Eg. emp%rowtype
emp name is a table,
all column type is %rowtype.
User-Defined Subtypes
PL/SQL gives you the control to create your own sub data type that inherited from a predefined base type. Subtypes
can increase reliability and provide compatibility with ANSI/ISO type. Several predefined subtypes are in a STANDARD
package.
https://way2tutorial.com/plsql/plsql-data-types.php 6/7
9/12/2019 PL/SQL Data Types - Oracle Data Types
Defining Subtypes
You can define your own subtypes in the declarative part of PL/SQL block using the following syntax,
adidas R.Y.V.
collection
adidas
Following the example, predefined data type inherits from CHARACTER and INTEGER data type to make a new sub
type,
Example
1 DECLARE
2 SUBTYPE message IS varchar2(25);
3 SUBTYPE age IS INTEGER(2,0);
4 description message;
5 ages age;
6 BEGIN
7 description := 'Web Developer';
8 ages := 22;
9 dbms_output.put_line('I am ' || description || ' and I am ' || ages || ' years Old.');
10 END;
11 /
Result
(https://play.google.com/store/apps/details?id=com.way2tutorial.app) (https://www.facebook.com/way2tutorial)
(https://twitter.com/way2tutorial) (https://plus.google.com/u/0/+Way2tutorial)
(https://www.pinterest.com/way2tutorial) (https://instagram.com/way2tutorial)
https://way2tutorial.com/plsql/plsql-data-types.php 7/7