1 Oracle Developer Data Types Essentials m1 Slides
1 Oracle Developer Data Types Essentials m1 Slides
David Berry
http://buildingbettersoftware.blogspot.com/
Why data types matter
Views,
Tables and
Data Types Synonyms
Indexes
and Triggers
Why Data Types Matter
Ease of Use
Built in Functionality
• Take advantage of what Oracle offers
Everything is a VARCHAR
SELECT
state_name,
DUMP(state_name),
date_of_statehood,
DUMP(date_of_statehood, 16)
FROM states;
Character Data Types
David Berry
http://buildingbettersoftware.blogspot.com/
Module Introduction
Character sets,
Oracle RAW data
VARCHAR2 and
type
NVARCHAR2 types
Character Data Types in Oracle
Default
CHAR VARCHAR2
character set
Unicode
NCHAR NVARCHAR2
character set
Column Specifications
CHAR,
2000 bytes
NCHAR
4000 bytes
VARCHAR2,
NVARCHAR2 32,767 bytes
(Oracle 12c - MAX_STRING_SIZE=EXTENDED)
Attempt to insert/update
Oracle will throw an error
column with value longer
(data is not auto-truncated)
than column size
CHAR vs. VARCHAR2
I D A H O
5 bytes of data
I D A H O
16 bytes of data
Problems With Space Padded Data
SELECT *
FROM nls_database_parameters
WHERE parameter IN
('NLS_CHARACTERSET', 'NLS_NCHAR_CHARACTERSET');
PARAMETER VALUE
------------------------- --------------------
NLS_CHARACTERSET WE8MSWIN1252
NLS_NCHAR_CHARACTERSET AL16UTF16
Character Set Properties
2000 bytes
Maximum Size 32,767 bytes
(Oracle 12c - MAX_STRING_SIZE=EXTENDED)
RAW Data Type
David Berry
http://buildingbettersoftware.blogspot.com/
Module Introduction
Negative scale can be used to round to the left of the decimal place
Software Exact
data type precision
Native Numeric Data Types
Option Definition
START WITH <value> Controls the initial value to use for the
identity column
http://bit.ly/Ora12cCreateSequence
Using Date Time Data Types
Basic syntax
Examples
GRANT select ON courses TO students_web, faculty_web;
Basic syntax
Examples
REVOKE update ON students FROM students_web, faculty_web;
Privilege Description
ALTER Change the table definition using ALTER TABLE
DEBUG Debug the PL/SQL in a trigger on the table
DELETE Remove rows on the table via a DELETE statement
INDEX Create an index on the table
INSERT Add new rows to the table via an INSERT statement
READ Allows queries from the table but not a SELECT … FOR
UPDATE statement (pessimistic locking)
REFERENCES Allows a foreign key constraint to the table (can only be
granted to a user, not a role)
SELECT Allows reads from the table including SELECT … FOR
UPDATE statements
UPDATE Modify rows in the table via an UPDATE statement
View Privileges
Privilege Description
DEBUG Debug the PL/SQL in a trigger on the view
DELETE Remove rows on the view via a DELETE statement
INSERT Add new rows to the via via an INSERT statement
READ Allows queries from the view but not a SELECT … FOR
UPDATE statement (pessimistic locking)
REFERENCES Allows a foreign key constraint to the view (can only be
granted to a user, not a role)
SELECT Allows reads from the view including SELECT … FOR
UPDATE statements
UPDATE Modify rows in the view via an UPDATE statement
Column Level Privileges
Column Level
• Not available for the select privileges
Privileges
desc employees;
students schema
execute Procedure:
UpdateGrade()
user
SELECT user_id
FROM users users
WHERE username = ? user_id username password
AND password = ?
Login 101 jason 7c222…
Process 102 chad ff9e4…
103 amanda 1fff8…
function
Login
check_password(
Process
username, password)
users
user_id username password
101 jason 7c222…
Access restricted to
102 chad ff9e4…
one use case
103 amanda 1fff8…
Grant EXECUTE privilege to allow users to run
Defense in Depth
Use multiple mechanisms to secure access to your data
Some Good Practices