Oracle10g New Features

Oracle Database 10g Data Types

Fundamentals of PL/SQL
y Full-featured programming language y Interpreted language y Execute using Oracle 10g utilities y SQL*Plus y Forms Builder y Combines SQL queries with procedural commands y Reserved words


PL/SQL Variables and Data Types
y Variable names must follow the Oracle naming

standard (Example: current_s_id, not $current_s_id) y Strongly typed language
y Explicitly declare each variable including data type

before using variable

y Variable declaration syntax: variable_name data_type_declaration; y Default value always NULL


Scalarsingle value such as number, date, string Variables y Reference
y Data types correspond to Oracle 10g database data types

y PL/SQL has other data types that do not correspond to database data types


Native Floating-Point Data Types
y Two new numeric data types BINARY_FLOAT, BINARY_DOUBLE y Based on the IEEE 754 Standard for binary floating point arithmetic y More efficient than the NUMBER type. Arithmetic operations are implemented in hardware on most platforms. These types may also take up less space in memory/disk. y Seamless support in SQL and PL/SQL

BINARY_FLOAT y BINARY_FLOAT is a 32-bit, single-precision floatingpoint number datatype.
y Each BINARY_FLOAT value requires 5 bytes, including a length byte.

BINARY_DOUBLE y BINARY_DOUBLE is a 64-bit, double-precision floating-point number datatype.
y Each BINARY_DOUBLE value requires 9 bytes, including a length byte.

Native Floating-Point Data Types
y New type conversion functions y Seamless support in SQL, PL/SQL, Java, XML, and


NCHAR Datatype
y The NCHAR datatype is a Unicode-only datatype. y Define the column length in characters. y Define the national character set when creating

database. y Width specifications of character datatype NCHAR refer to the number of characters. y The maximum column size allowed is 2000 bytes. y If we insert a value that is shorter than the column length, then Oracle blank-pads the value to column length. y we cannot insert a CHAR value into an NCHAR column, nor can we insert an NCHAR value into a CHAR column.

Composite Variables
y Data object made up of multiple individual data

elements y Data structure contains multiple scalar variables y Composite variable data types include:
A y RECORD (multiple scalar values similar to a table record) R y TABLE (tabular structure with multiple columns R and rows) A Y y VARRAY (variable-sized array. Tabular structure

that can expand or contract based on data values)


y An array is an ordered set of data elements. y All elements of a given array are of the same datatype. y Each element has an index, which is a number corresponding to the position of the element in the array. y The number of elements in an array is the size of the array. y Oracle arrays are of variable size, which is why they are called varrays.

y we must specify a maximum size when we declare the varray. y When we declare a varray, it does not allocate space. It defines a type, which we can use as: y The datatype of a column of a relational table y An object type attribute y A PL/SQL variable, parameter, or function return type

Nested Tables
y A nested table type models an unordered set of

elements. types. We

y The elements may be built-in types or user-defined y can view a nested table as a single-column table or,

if the nested table is an object type, as a multicolumn table, with a column for each attribute of the object type.

y A nested table definition does not allocate space.

Nested Tables
y It defines a type, which we can use to declare: y The datatype of a column of a relational table y An object type attribute y A PL/SQL variable, parameter, or function return type y When a nested table appears as the type of a column in a relational table or as an attribute of the underlying object type of an object table, Oracle stores all of the nested table data in a single table, which it associates with the enclosing relational or object table. BACK

ANSI Collections Support in Nested Tables
y Equality and Non-Equality Predicates y IN and NOT IN operators y MULTISET, SUBMULTISET, POWERMULTISET,

y y y y


MultiSet Operators

Multiset Operators: EXCEPT
y The multiset operator EXCEPT allow to return all the values

from one nested table that aren't found in a second nested table in a query. For example the y Following query expression returns a nested table of the original value, except for 1. y select num multiset except num_tab_typ(1) num from num_tab;
NUM -------------------------NUM_TAB_TYP(2, 3, 4, 5) NUM_TAB_TYP(3, 5) NUM_TAB_TYP(2, 4, 6)

Multiset Operators: INTERSECT
y The multiset operator INTERSECT allows you to return all the

values which are common between two nested tables. Using a nested table with just the value 1 will return an empty set if 1 doesn't exist, and a nested table with the value 1 if it does exist. y select num multiset intersect num_tab_typ(1) num from num_tab
NUM -------------------------NUM_TAB_TYP(1) NUM_TAB_TYP(1) NUM_TAB_TYP()

Multiset Operators: UNION
y The multiset operator UNION allows you to return all the

values from both nested tables merged into a single nested table. y select num multiset union num_tab_typ(1) num from num_tab;
NUM -------------------------NUM_TAB_TYP(1, 2, 3, 4, 5, 1) NUM_TAB_TYP(1, 3, 5, 1) NUM_TAB_TYP(2, 4, 6, 1)

select num multiset union distinct num_tab_typ(1) num from num_tab;

Varray and Nested Tables Enhancements
‡ Alter VARRAY and Nested Table Limit Size ‡ Varray Columns in temporary tables ‡ALTER TYPE email_list_tab MODIFY ELEMENT TYPE VARCHAR2(40) CASCADE; ‡ALTER TYPE email_varray_typ MODIFY LIMIT 100 INVALIDATE;

Reference Variables
y Directly reference specific database column or row y Assume data type of associated column or row y %TYPE data declaration syntax: variable_name tablename.fieldname%TYPE; y %ROWTYPE data declaration syntax: variable_name tablename%ROWTYPE;

LOB Data Type
Must be manipulated using programs in DBMS_LOB package 22


Large Object (LOB) DatatypesCLOB, and NCLOB y The built-in LOB datatypes BLOB,

(stored internally) can store large and unstructured data such as text, image, video, and spatial data.

y BLOB, CLOB, and NCLOB data can be up to (4 gigabytes -1) * (database block size) in size. y When creating a table, we can optionally specify different tablespace and storage characteristics for LOB columns or LOB object attributes from those specified for the table. y LOB columns contain LOB locators that can refer to inline (in the database) or out-of-line (outside the database) LOB values.

Large Object (LOB) Datatypes
y Selecting a LOB from a table actually returns the LOB locator and not the entire LOB value. y LOBs are similar to LONG and LONG RAW types, but differ in the following ways:
y LOBs can be attributes of an object type (user-defined

datatype). y The LOB locator is stored in the table column, either with or without the actual LOB value. y BLOB, NCLOB, and CLOB values can be stored in separate tablespaces.

y When we access a LOB column, the locator is returned.

Large Object (LOB) Datatypes
y LOBs permit efficient, random, piece-wise access to and manipulation of data. y we can define more than one LOB column in a table. y With the exception of NCLOB, we can define one or more LOB attributes in an object. y we can select LOB columns and LOB attributes. y we can insert a new row or update an existing row that contains one or more LOB columns or an object with one or more LOB attributes.

Large Object (LOB) Datatypes
y In update operations, we can set the internal LOB value to NULL, empty,

or replace the entire LOB with data.

y we can update a LOB row-column intersection or a LOB attribute with

another LOB row-column intersection or LOB attribute. also delete the LOB value.

y we can delete a row containing a LOB column or LOB attribute and thereby y we can access and populate rows of an in-line LOB column (a LOB column

stored in the database) simply by issuing an INSERT or UPDATE statement.

y However, to access and populate a LOB attribute that is part of an object

type, we must first initialize the LOB attribute using the EMPTY_CLOB or EMPTY_BLOB function. DBMS_LOB package or some other appropriate interface.

y we can then select the empty LOB attribute and populate it using the

BLOB Datatype
y The BLOB datatype stores unstructured binary large objects. y BLOB objects can be thought of as bitstreams with no character set


y BLOB objects can store up to (4 gigabytes-1) * (database block size)

of binary data.

y BLOB objects have full transactional support. y Changes made through SQL, the DBMS_LOB package, or the

Oracle Call Interface (OCI) participate fully in the transaction.

y BLOB value manipulations can be committed and rolled back.

CLOB Datatype
y The CLOB datatype stores single-byte and multibyte

character data.
y Both fixed-width and variable-width character sets are

supported, and both use the database character set.
y CLOB objects can store up to (4 gigabytes-1) *

(database block size) of character data.

NCLOB Datatype
y The NCLOB datatype stores Unicode data. y Both fixed-width and variable-width character sets

are supported, and both use the national character set. (database block size) of character text data.

y NCLOB objects can store up to (4 gigabytes-1) * y NCLOB objects have full transactional support.

BFILE Datatype
y The BFILE datatype enables access to binary file LOBs that are stored in file systems outside Oracle Database. y A BFILE column or attribute stores a BFILE locator, which serves as a pointer to a binary file on the server file system. y The locator maintains the directory name and the filename. y we can change the filename and path of a BFILE without affecting the base table by using the BFILENAME function.

BFILE Datatype
y Binary file LOBs do not participate in transactions and are not recoverable. y Rather, the underlying operating system provides file integrity and durability. y The maximum file size supported is 4 gigabytes. y The database administrator must ensure that the external file exists and that Oracle processes have operating system read permissions on the file. y The BFILE datatype enables read-only support of large binary files. You cannot modify or replicate such a file.

LOB Enhancements
y Performance improvements y Terabyte size LOBs y New DBMS_LOB.GET_STORAGE_LIMIT function y OCI now supports LOBs greater than 4GB