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

What's hot (20)

PDF
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Beat Signer
 
PDF
Database Architecture and Basic Concepts
Tony Wong
 
PDF
Sql server 2016: System Databases, data types, DML, json, and built-in functions
Seyed Ibrahim
 
PPT
SQL
princy75
 
PPT
Introduction to sql
VARSHAKUMARI49
 
PDF
Three steps to untangle data traffic jams
Bol.com Techlab
 
PPT
Dbms
philipsinter
 
PDF
esProc introduction
ssuser9671cc
 
PPTX
SQL SERVER Training in Pune Slides
enosislearningcom
 
PPTX
PostgreSQL - Object Relational Database
Mubashar Iqbal
 
PDF
PostgreSQL Advanced Queries
Nur Hidayat
 
PPTX
Normalizing Data for Migrations
Kyle Banerjee
 
PDF
MySQL Indexing
BADR
 
DOC
Sql material
Madhusudhanareddy Katta
 
PPTX
User Group3009
sqlserver.co.il
 
PPT
Sql Server Basics
rainynovember12
 
PPTX
Java JDBC
DeeptiJava
 
PPTX
Physical architecture of sql server
Divya Sharma
 
PPT
Mysql Indexing
Tasawr Interactive
 
PPTX
Indexing the MySQL Index: Key to performance tuning
OSSCube
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Beat Signer
 
Database Architecture and Basic Concepts
Tony Wong
 
Sql server 2016: System Databases, data types, DML, json, and built-in functions
Seyed Ibrahim
 
Introduction to sql
VARSHAKUMARI49
 
Three steps to untangle data traffic jams
Bol.com Techlab
 
esProc introduction
ssuser9671cc
 
SQL SERVER Training in Pune Slides
enosislearningcom
 
PostgreSQL - Object Relational Database
Mubashar Iqbal
 
PostgreSQL Advanced Queries
Nur Hidayat
 
Normalizing Data for Migrations
Kyle Banerjee
 
MySQL Indexing
BADR
 
User Group3009
sqlserver.co.il
 
Sql Server Basics
rainynovember12
 
Java JDBC
DeeptiJava
 
Physical architecture of sql server
Divya Sharma
 
Mysql Indexing
Tasawr Interactive
 
Indexing the MySQL Index: Key to performance tuning
OSSCube
 

Similar to Basic datatypes - deep understanding (20)

PPT
Database Sizing
Amin Chowdhury
 
PDF
Sql tutorial
Axmed Mo.
 
PDF
Sql tutorial
togather111
 
PDF
SQL
kaushal123
 
PDF
Oracle sql tutorial
Mohd Tousif
 
PPTX
Structured Query Language (SQL) _ Edu4Sure Training.pptx
Edu4Sure
 
DOC
Sqlmaterial 120414024230-phpapp01
Lalit009kumar
 
PPTX
P9 speed of-light faceted search via oracle in-memory option by alexander tok...
Alexander Tokarev
 
PDF
Deep Dive into DynamoDB
AWS Germany
 
DOCX
SQL, Oracle, Joins
Gaurish Goel
 
PPTX
In memory databases presentation
Michael Keane
 
PDF
MariaDB ColumnStore
MariaDB plc
 
PPTX
HPD SQL Training - Beginner - 20220916.pptx
PatriceRochon1
 
PPTX
SQL Training Institute in Ambala ! Batra Computer Centre
jatin batra
 
PDF
Plsql quick guide
1bi08me024
 
PPTX
SPL_ALL_EN.pptx
政宏 张
 
PDF
2011 06-sq lite-forensics
viaForensics
 
ODT
Sql and mysql database concepts
Selamawit Feleke
 
PDF
SQLServer Database Structures
Antonios Chatzipavlis
 
PDF
UNIT 3 SQL 10.pdf ORACEL DATABASE QUERY OPTIMIZATION
saranyaksr92
 
Database Sizing
Amin Chowdhury
 
Sql tutorial
Axmed Mo.
 
Sql tutorial
togather111
 
Oracle sql tutorial
Mohd Tousif
 
Structured Query Language (SQL) _ Edu4Sure Training.pptx
Edu4Sure
 
Sqlmaterial 120414024230-phpapp01
Lalit009kumar
 
P9 speed of-light faceted search via oracle in-memory option by alexander tok...
Alexander Tokarev
 
Deep Dive into DynamoDB
AWS Germany
 
SQL, Oracle, Joins
Gaurish Goel
 
In memory databases presentation
Michael Keane
 
MariaDB ColumnStore
MariaDB plc
 
HPD SQL Training - Beginner - 20220916.pptx
PatriceRochon1
 
SQL Training Institute in Ambala ! Batra Computer Centre
jatin batra
 
Plsql quick guide
1bi08me024
 
SPL_ALL_EN.pptx
政宏 张
 
2011 06-sq lite-forensics
viaForensics
 
Sql and mysql database concepts
Selamawit Feleke
 
SQLServer Database Structures
Antonios Chatzipavlis
 
UNIT 3 SQL 10.pdf ORACEL DATABASE QUERY OPTIMIZATION
saranyaksr92
 
Ad

Recently uploaded (20)

PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PDF
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
PDF
Researching The Best Chat SDK Providers in 2025
Ray Fields
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PPTX
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PPTX
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
Researching The Best Chat SDK Providers in 2025
Ray Fields
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Ad

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 [email protected]
  • 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