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

Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
Tony Wong
 
Indexing the MySQL Index: Key to performance tuning
Indexing the MySQL Index: Key to performance tuningIndexing the MySQL Index: Key to performance tuning
Indexing the MySQL Index: Key to performance tuning
OSSCube
 

What's hot (20)

Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
 
Sql server 2016: System Databases, data types, DML, json, and built-in functions
Sql server 2016: System Databases, data types, DML, json, and built-in functionsSql server 2016: System Databases, data types, DML, json, and built-in functions
Sql server 2016: System Databases, data types, DML, json, and built-in functions
 
SQL
SQLSQL
SQL
 
Introduction to sql
Introduction to sqlIntroduction to sql
Introduction to sql
 
Three steps to untangle data traffic jams
Three steps to untangle data traffic jamsThree steps to untangle data traffic jams
Three steps to untangle data traffic jams
 
Dbms
DbmsDbms
Dbms
 
esProc introduction
esProc introductionesProc introduction
esProc introduction
 
SQL SERVER Training in Pune Slides
SQL SERVER Training in Pune SlidesSQL SERVER Training in Pune Slides
SQL SERVER Training in Pune Slides
 
PostgreSQL - Object Relational Database
PostgreSQL - Object Relational DatabasePostgreSQL - Object Relational Database
PostgreSQL - Object Relational Database
 
PostgreSQL Advanced Queries
PostgreSQL Advanced QueriesPostgreSQL Advanced Queries
PostgreSQL Advanced Queries
 
Normalizing Data for Migrations
Normalizing Data for MigrationsNormalizing Data for Migrations
Normalizing Data for Migrations
 
MySQL Indexing
MySQL IndexingMySQL Indexing
MySQL Indexing
 
Sql material
Sql materialSql material
Sql material
 
User Group3009
User Group3009User Group3009
User Group3009
 
Sql Server Basics
Sql Server BasicsSql Server Basics
Sql Server Basics
 
Java JDBC
Java JDBCJava JDBC
Java JDBC
 
Physical architecture of sql server
Physical architecture of sql serverPhysical architecture of sql server
Physical architecture of sql server
 
Mysql Indexing
Mysql IndexingMysql Indexing
Mysql Indexing
 
Indexing the MySQL Index: Key to performance tuning
Indexing the MySQL Index: Key to performance tuningIndexing the MySQL Index: Key to performance tuning
Indexing the MySQL Index: Key to performance tuning
 

Similar to Basic datatypes - deep understanding

Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
Axmed Mo.
 
Sqlmaterial 120414024230-phpapp01
Sqlmaterial 120414024230-phpapp01Sqlmaterial 120414024230-phpapp01
Sqlmaterial 120414024230-phpapp01
Lalit009kumar
 
SQL, Oracle, Joins
SQL, Oracle, JoinsSQL, Oracle, Joins
SQL, Oracle, Joins
Gaurish Goel
 
Plsql quick guide
Plsql quick guidePlsql quick guide
Plsql quick guide
1bi08me024
 
2011 06-sq lite-forensics
2011 06-sq lite-forensics2011 06-sq lite-forensics
2011 06-sq lite-forensics
viaForensics
 

Similar to Basic datatypes - deep understanding (20)

Database Sizing
Database SizingDatabase Sizing
Database Sizing
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
SQL
SQLSQL
SQL
 
Oracle sql tutorial
Oracle sql tutorialOracle sql tutorial
Oracle sql tutorial
 
Structured Query Language (SQL) _ Edu4Sure Training.pptx
Structured Query Language (SQL) _ Edu4Sure Training.pptxStructured Query Language (SQL) _ Edu4Sure Training.pptx
Structured Query Language (SQL) _ Edu4Sure Training.pptx
 
Sqlmaterial 120414024230-phpapp01
Sqlmaterial 120414024230-phpapp01Sqlmaterial 120414024230-phpapp01
Sqlmaterial 120414024230-phpapp01
 
Deep Dive: Amazon DynamoDB
Deep Dive: Amazon DynamoDBDeep Dive: Amazon DynamoDB
Deep Dive: Amazon DynamoDB
 
P9 speed of-light faceted search via oracle in-memory option by alexander tok...
P9 speed of-light faceted search via oracle in-memory option by alexander tok...P9 speed of-light faceted search via oracle in-memory option by alexander tok...
P9 speed of-light faceted search via oracle in-memory option by alexander tok...
 
Deep Dive on Amazon DynamoDB
Deep Dive on Amazon DynamoDBDeep Dive on Amazon DynamoDB
Deep Dive on Amazon DynamoDB
 
Deep Dive into DynamoDB
Deep Dive into DynamoDBDeep Dive into DynamoDB
Deep Dive into DynamoDB
 
SQL, Oracle, Joins
SQL, Oracle, JoinsSQL, Oracle, Joins
SQL, Oracle, Joins
 
In memory databases presentation
In memory databases presentationIn memory databases presentation
In memory databases presentation
 
MariaDB ColumnStore
MariaDB ColumnStoreMariaDB ColumnStore
MariaDB ColumnStore
 
SQL Training Institute in Ambala ! Batra Computer Centre
SQL Training Institute in Ambala ! Batra Computer CentreSQL Training Institute in Ambala ! Batra Computer Centre
SQL Training Institute in Ambala ! Batra Computer Centre
 
Plsql quick guide
Plsql quick guidePlsql quick guide
Plsql quick guide
 
SPL_ALL_EN.pptx
SPL_ALL_EN.pptxSPL_ALL_EN.pptx
SPL_ALL_EN.pptx
 
23 October 2013 - AWS 201 - A Walk through the AWS Cloud: Introduction to Ama...
23 October 2013 - AWS 201 - A Walk through the AWS Cloud: Introduction to Ama...23 October 2013 - AWS 201 - A Walk through the AWS Cloud: Introduction to Ama...
23 October 2013 - AWS 201 - A Walk through the AWS Cloud: Introduction to Ama...
 
2011 06-sq lite-forensics
2011 06-sq lite-forensics2011 06-sq lite-forensics
2011 06-sq lite-forensics
 
Amazon DynamoDB 深入探討
Amazon DynamoDB 深入探討Amazon DynamoDB 深入探討
Amazon DynamoDB 深入探討
 

Recently uploaded

Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 

Recently uploaded (20)

Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT Professionals
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 

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