SlideShare a Scribd company logo
liron@gotodba.com
@amitzil
https://gotodba.com
Liron Amitzi
 Liron Amitzi
 Oracle DBA since 1998 (and Oracle 7)
 Database consultant since 2002
 Oracle ACE
 An independent senior DB consultant
 Recently moved to Vancouver, BC
 BCOUG president
3 Membership Tiers
• Oracle ACE Director
• Oracle ACE
• Oracle ACE Associate
bit.ly/OracleACEProgram
500+ Technical
Experts Helping
Peers Globally
Connect:
Nominate yourself or someone you know: acenomination.oracle.com
@oracleace
Facebook.com/oracleaces
oracle-ace_ww@oracle.com
Basic datatypes are the standard datatypes we use for table
columns:
 CHAR
 VARCHAR2
 NUMBER
 DATE
In this session we will get to know them better, much
better…
 Fixed datatypes
◦ CHAR (1-2000 bytes)
◦ DATE (7 byte)
◦ TIMESTAMP (7-11 bytes) WITH TIME ZONE (13 bytes)
◦ ROWID (10 bytes)
 Variable datatypes
◦ NUMBER (1-22 bytes)
◦ VARCHAR2 (1-4000 bytes, 1-32767 bytes in 12c with
MAX_STRING_SIZE=EXTENDED)
 The physical structure of every value consists of three
parts:
• Type number – One byte that represents the type of the value (for
example, 1 is VARCHAR2, 2 is NUMBER and 96 is CHAR)
◦ Length – One or two bytes that represent the size of the value
◦ Value data – The data itself
To check the real structure of datatypes we will use:
 Vsize – returns the real size the value takes (excluding
length bytes)
select vsize('abc') from dual => 3
 Dump – returns the real binary value of the data
(converted to decimal)
select dump('abc') from dual =>
Typ=96 Len=3: 97,98,99
 “Variable size” – takes the actual space needed
 VARCHAR2(x) means the value is limited to x (bytes or
characters)
 VARCHAR is currently a synonym for VARCHAR2 but
might be scheduled to be used for different purposes
 Maximum size is 4000 bytes (<12c)
 New since 12c
 STANDARD
◦ Limit of 4000 for VARCHAR2 and NVARCHAR2
◦ Limit of 2000 for RAW
 EXTENDED - cannot be changed back
◦ Limit VARCHAR2, NVARCHAR2 and RAW to 32767
 When exceeds 4000 bytes, it is stored out of line (LOB)
 "Fixed size” - CHAR(x): value will take x (bytes or chars)
 Padded with spaces
 Can be queried without spaces
 2000 bytes max (regardless MAX_STRING_SIZE)
 Internally identical to VARCHAR2
 Oracle still saves the length bytes - any ideas why?
 No performance improvements over VARCHAR2
"The only time I personally use a
CHAR type is for CHAR(1).
And that is only because its faster
to type char(1) then varchar2(1).
It offers no advantages."
Tom Kyte on AskTom
Demo - char.sql
 Single character set - multiple languages and symbols
 Up to 3 bytes per character in UTF8
 Up to 4 bytes per character in AL32UTF8 or AL16UTF16
 The hard limits are:
◦ VARCHAR2 (MAX_STRING_SIZE=STANDARD or <12c): 4000 bytes
◦ VARCHAR2 (MAX_STRING_SIZE=EXTENDED): 32767 bytes
◦ CHAR: 2000 bytes
 More on Unicode character sets in note 260893.1
 Relevant for multi-byte character sets
 Default text length limitation
 Value can be BYTE or CHAR (default is BYTE)
 Can limit max column size when creating a table:
CREATE TABLE mytab (
f1 CHAR(4 byte), -- > max of 4 bytes (1-4 characters)
f2 CHAR(4 char), -- > max of 4 chars (1-16 bytes)
f3 CHAR(4)) -- > depends on NLS_LENGTH_SEMANTICS
Demo - unicode.sql
 “Fixed size” datatype, takes 7 bytes:
◦ 1st and 2nd bytes are century and year (excess 100 notation)
◦ 3rd and 4th bytes are month and day
◦ 5th – 7th bytes are hours, minutes and seconds, excess 1 notation
 If no year, month, or day entered, the default is the first
day of the current month
 If no hour, minutes, seconds entered, the default is zero
 All arithmetic operations on dates are in days
 More about representation of DATE in note 69028.1
Demo - date.sql
 Variable size datatype
 NOT programing language number types
 The first bit in the first byte is the sign, the other 7 are
the exponent (excess 64)
 All other bytes are the number in base 100 format (every
2 digits are a single byte), excess 1
 Trailing zeros do not consume space
 Range is 1.0 x 10-130 to but not including 1.0 x 10126
 More about representation of NUMBER in note 1031902.6
Demo - number.sql
 NUMBER datatype is NOT native to the hardware
 Is it faster than CHAR/VARCHAR2? NO
 Needs processing as well
 In most cases, NUMBER columns will not be sorted much
quicker than VARCHAR2 columns
Demo - sort.sql
If we have time
 When using PL/SQL we have the PLS_INTEGER
datatype
 PLS_INTEGER is native to the hardware
 In SQL and database tables, PLS_INTEGER is converted
to regular NUMBER
 Using PLS_INTEGER for variables that need many
calculations can improve performance
Demo - PLSQL.sql
Liron Amitzi
liron@gotodba.com
@amitzil
https://gotodba.com

More Related Content

PPTX
Real Life SQL Tuning - From 4 minutes to 8 seconds
PDF
Better design than sorry - let's design our DB schema
PPT
PO WER - Piotr Mariat - Sql
PPTX
Sql Basics And Advanced
PPSX
MS SQL Server
PPTX
Tk2323 lecture 7 sql
PPTX
Introduction to (sql)
PPT
Optimizing Data Accessin Sq Lserver2005
Real Life SQL Tuning - From 4 minutes to 8 seconds
Better design than sorry - let's design our DB schema
PO WER - Piotr Mariat - Sql
Sql Basics And Advanced
MS SQL Server
Tk2323 lecture 7 sql
Introduction to (sql)
Optimizing Data Accessin Sq Lserver2005

What's hot (20)

PDF
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
PDF
Database Architecture and Basic Concepts
PDF
Sql server 2016: System Databases, data types, DML, json, and built-in functions
PPT
PPT
Introduction to sql
PDF
Three steps to untangle data traffic jams
PPT
PDF
esProc introduction
PPTX
SQL SERVER Training in Pune Slides
PPTX
PostgreSQL - Object Relational Database
PDF
PostgreSQL Advanced Queries
PPTX
Normalizing Data for Migrations
PDF
MySQL Indexing
DOC
PPTX
User Group3009
PPT
Sql Server Basics
PPTX
Java JDBC
PPTX
Physical architecture of sql server
PPT
Mysql Indexing
PPTX
Indexing the MySQL Index: Key to performance tuning
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Database Architecture and Basic Concepts
Sql server 2016: System Databases, data types, DML, json, and built-in functions
Introduction to sql
Three steps to untangle data traffic jams
esProc introduction
SQL SERVER Training in Pune Slides
PostgreSQL - Object Relational Database
PostgreSQL Advanced Queries
Normalizing Data for Migrations
MySQL Indexing
User Group3009
Sql Server Basics
Java JDBC
Physical architecture of sql server
Mysql Indexing
Indexing the MySQL Index: Key to performance tuning
Ad

Similar to Basic datatypes - deep understanding (20)

PPTX
DOCX
Sql data types for various d bs by naveen kumar veligeti
PPTX
2.0 sql data types for my sql, sql server
PDF
UNIT 3 SQL 10.pdf ORACEL DATABASE QUERY OPTIMIZATION
PPTX
PPTX
Sql fundamentals
PPTX
PPT CREATEIVEhahhahahahhahahahahahaha.pptx
PPTX
429cf300-0dc7-4c2e-9280-d918d69e3cb4.pptx
PPTX
429cf300-0dc7-4c2e-9280-d918d69e3cb4.pptx
PPT
Intro to tsql unit 5
PPT
Intro To TSQL - Unit 5
PDF
Oracle sql in 7 days by suesh.n v 1.0
PPTX
Do not delete!
PPTX
GPREC DBMS Notes 1
PPTX
ADBMS DATATYPES
PPTX
Adbms datatypes
PPTX
Learn Database Design with MySQL - Chapter 4 - Data types
Sql data types for various d bs by naveen kumar veligeti
2.0 sql data types for my sql, sql server
UNIT 3 SQL 10.pdf ORACEL DATABASE QUERY OPTIMIZATION
Sql fundamentals
PPT CREATEIVEhahhahahahhahahahahahaha.pptx
429cf300-0dc7-4c2e-9280-d918d69e3cb4.pptx
429cf300-0dc7-4c2e-9280-d918d69e3cb4.pptx
Intro to tsql unit 5
Intro To TSQL - Unit 5
Oracle sql in 7 days by suesh.n v 1.0
Do not delete!
GPREC DBMS Notes 1
ADBMS DATATYPES
Adbms datatypes
Learn Database Design with MySQL - Chapter 4 - Data types
Ad

Recently uploaded (20)

PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Cloud computing and distributed systems.
PPTX
Spectroscopy.pptx food analysis technology
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Encapsulation_ Review paper, used for researhc scholars
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Electronic commerce courselecture one. Pdf
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Machine Learning_overview_presentation.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
A Presentation on Artificial Intelligence
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Unlocking AI with Model Context Protocol (MCP)
Spectral efficient network and resource selection model in 5G networks
Reach Out and Touch Someone: Haptics and Empathic Computing
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Cloud computing and distributed systems.
Spectroscopy.pptx food analysis technology
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Encapsulation_ Review paper, used for researhc scholars
The AUB Centre for AI in Media Proposal.docx
Electronic commerce courselecture one. Pdf
gpt5_lecture_notes_comprehensive_20250812015547.pdf
A comparative analysis of optical character recognition models for extracting...
Network Security Unit 5.pdf for BCA BBA.
Machine Learning_overview_presentation.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Assigned Numbers - 2025 - Bluetooth® Document
A Presentation on Artificial Intelligence
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton

Basic datatypes - deep understanding

  • 2.  Liron Amitzi  Oracle DBA since 1998 (and Oracle 7)  Database consultant since 2002  Oracle ACE  An independent senior DB consultant  Recently moved to Vancouver, BC  BCOUG president
  • 3. 3 Membership Tiers • Oracle ACE Director • Oracle ACE • Oracle ACE Associate bit.ly/OracleACEProgram 500+ Technical Experts Helping Peers Globally Connect: Nominate yourself or someone you know: acenomination.oracle.com @oracleace Facebook.com/oracleaces oracle-ace_ww@oracle.com
  • 4. Basic datatypes are the standard datatypes we use for table columns:  CHAR  VARCHAR2  NUMBER  DATE In this session we will get to know them better, much better…
  • 5.  Fixed datatypes ◦ CHAR (1-2000 bytes) ◦ DATE (7 byte) ◦ TIMESTAMP (7-11 bytes) WITH TIME ZONE (13 bytes) ◦ ROWID (10 bytes)  Variable datatypes ◦ NUMBER (1-22 bytes) ◦ VARCHAR2 (1-4000 bytes, 1-32767 bytes in 12c with MAX_STRING_SIZE=EXTENDED)
  • 6.  The physical structure of every value consists of three parts: • Type number – One byte that represents the type of the value (for example, 1 is VARCHAR2, 2 is NUMBER and 96 is CHAR) ◦ Length – One or two bytes that represent the size of the value ◦ Value data – The data itself
  • 7. To check the real structure of datatypes we will use:  Vsize – returns the real size the value takes (excluding length bytes) select vsize('abc') from dual => 3  Dump – returns the real binary value of the data (converted to decimal) select dump('abc') from dual => Typ=96 Len=3: 97,98,99
  • 8.  “Variable size” – takes the actual space needed  VARCHAR2(x) means the value is limited to x (bytes or characters)  VARCHAR is currently a synonym for VARCHAR2 but might be scheduled to be used for different purposes  Maximum size is 4000 bytes (<12c)
  • 9.  New since 12c  STANDARD ◦ Limit of 4000 for VARCHAR2 and NVARCHAR2 ◦ Limit of 2000 for RAW  EXTENDED - cannot be changed back ◦ Limit VARCHAR2, NVARCHAR2 and RAW to 32767  When exceeds 4000 bytes, it is stored out of line (LOB)
  • 10.  "Fixed size” - CHAR(x): value will take x (bytes or chars)  Padded with spaces  Can be queried without spaces  2000 bytes max (regardless MAX_STRING_SIZE)  Internally identical to VARCHAR2  Oracle still saves the length bytes - any ideas why?  No performance improvements over VARCHAR2
  • 11. "The only time I personally use a CHAR type is for CHAR(1). And that is only because its faster to type char(1) then varchar2(1). It offers no advantages." Tom Kyte on AskTom Demo - char.sql
  • 12.  Single character set - multiple languages and symbols  Up to 3 bytes per character in UTF8  Up to 4 bytes per character in AL32UTF8 or AL16UTF16  The hard limits are: ◦ VARCHAR2 (MAX_STRING_SIZE=STANDARD or <12c): 4000 bytes ◦ VARCHAR2 (MAX_STRING_SIZE=EXTENDED): 32767 bytes ◦ CHAR: 2000 bytes  More on Unicode character sets in note 260893.1
  • 13.  Relevant for multi-byte character sets  Default text length limitation  Value can be BYTE or CHAR (default is BYTE)  Can limit max column size when creating a table: CREATE TABLE mytab ( f1 CHAR(4 byte), -- > max of 4 bytes (1-4 characters) f2 CHAR(4 char), -- > max of 4 chars (1-16 bytes) f3 CHAR(4)) -- > depends on NLS_LENGTH_SEMANTICS Demo - unicode.sql
  • 14.  “Fixed size” datatype, takes 7 bytes: ◦ 1st and 2nd bytes are century and year (excess 100 notation) ◦ 3rd and 4th bytes are month and day ◦ 5th – 7th bytes are hours, minutes and seconds, excess 1 notation
  • 15.  If no year, month, or day entered, the default is the first day of the current month  If no hour, minutes, seconds entered, the default is zero  All arithmetic operations on dates are in days  More about representation of DATE in note 69028.1 Demo - date.sql
  • 16.  Variable size datatype  NOT programing language number types  The first bit in the first byte is the sign, the other 7 are the exponent (excess 64)  All other bytes are the number in base 100 format (every 2 digits are a single byte), excess 1
  • 17.  Trailing zeros do not consume space  Range is 1.0 x 10-130 to but not including 1.0 x 10126  More about representation of NUMBER in note 1031902.6 Demo - number.sql
  • 18.  NUMBER datatype is NOT native to the hardware  Is it faster than CHAR/VARCHAR2? NO  Needs processing as well  In most cases, NUMBER columns will not be sorted much quicker than VARCHAR2 columns Demo - sort.sql
  • 19. If we have time
  • 20.  When using PL/SQL we have the PLS_INTEGER datatype  PLS_INTEGER is native to the hardware  In SQL and database tables, PLS_INTEGER is converted to regular NUMBER  Using PLS_INTEGER for variables that need many calculations can improve performance Demo - PLSQL.sql