13.3.1 Oracle Data Types Char

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

13.3.

1 Oracle Data Types

CHAR

The CHAR data type stores fixed-length character strings. The length of string variable is (in
bytes or characters) between 1 and 2000 bytes. The default size is 1 byte.

 If a shorter value is given, then the value is blank-padded to the fixed length.
 If a value is too large, Oracle Database returns an error.

VARCHAR2

The VARCHAR2 data type stores variable-length character strings. Any variable declares as
Varchar2 () can have a maximum length of 4000 bytes. For each row, Oracle Database stores
each value in the column as a variable-length field unless a value exceeds the column's
maximum length, in which case Oracle Database returns an error. Using VARCHAR2 and
VARCHAR saves on space used by the table.

For example, a column Name VARCHAR2 (50) declaration, if only 10 characters are given for
the name, the column in the row will occupy only the 10 characters (10 bytes), not 50.

NUMBER

The NUMBER data type stores fixed and floating-point numbers. Numbers of virtually any
magnitude can be stored and are depends the systems operating Oracle Database, up to 38 digits
of precision.

The following numbers can be stored in a NUMBER column:

 Positive numbers in the range 1 x 10-130 to 9.99...9 x 10125 with up to 38 significant digits
 Negative numbers from -1 x 10-130 to 9.99...99 x 10125 with up to 38 significant digits
 Zero
 Positive and negative infinity (generated only by importing from an Oracle Database,
Version 5)

For numeric columns, you can specify the column as:

<column_name> NUMBER

Optionally, it is also specifying a precision (total number of digits) and scale (number of digits to
the right of the decimal point):

<column_name> NUMBER (precision, scale)

If a precision is not specified, the column stores values as given. If no scale is specified, the scale
is one. Oracle guarantees portability of numbers with a precision equal to or less than 38 digits.
DATE

The DATE data type stores point-in-time values (dates and times) in a table. The DATE data
type stores the year (including the century), the month, the day, the hours, the minutes, and the
seconds (after midnight). Oracle can store dates in the Julian era, ranging from January 1, 4712
BCE through December 31, 9999 CE (Common Era, or 'AD'). Unless BCE ('BC' in the format
mask) is specifically used, CE date entries are the default. Oracle uses its own internal format to
store dates. Date data is stored in fixed-length fields of seven bytes each, corresponding to
century, year, month, day, hour, minute, and second.

For input and output of dates, the standard Oracle date format is dd-mon-yy, as follows,

'13-NOV-92'

LOB

The LOB data types for character data are CLOB and NCLOB. They can store up to 8 terabytes
of character data (CLOB) or national character set data (NCLOB).

The LOB data types BLOB, CLOB, NCLOB, and BFILE enable to store and manipulate large
blocks of unstructured data (such as text, graphic images, video clips, and sound waveforms) in
binary or character format. They provide efficient, random, piece-wise access to the data. Oracle
recommends that you always use LOB data types over LONG data types.

LOB data types differ from LONG and LONG RAW data types in several ways. For example:

 A table can contain multiple LOB columns but only one LONG column.

 A table containing one or more LOB columns can be partitioned, but a table containing a
LONG column cannot be partitioned.

 The maximum size of a LOB is 128 terabytes depending on database block size, and the
maximum size of a LONG is only 2 gigabytes.

 LOBs support random access to data, but LONGs support only sequential access.

 LOB data types (except NCLOB) can be attributes of a user-defined object type but
LONG data types cannot.

 Tables with LOB columns can be replicated, but tables with LONG columns cannot.

 RAW is a variable-length data type like the VARCHAR2 character data type, except
Oracle Net Services (which connects user sessions to the instance) and the Import and
Export utilities do not perform character conversion when transmitting RAW or LONG
RAW data. In contrast, Oracle Net Services and Import/Export automatically convert
CHAR, VARCHAR2, and LONG data between the database character set and the user
session character set, if the two character sets are different.

 LONG RAW data cannot be indexed, but RAW data can be indexed.

adOpenForwardOnly (0) – This is the default cursor type, which uses the forward-only cursor.
Identical to a static cursor, except that you can only scroll forward through records. This
improves performance when you need to make only one pass through a Recordset.

adOpenKeyset (1) - Uses a keyset cursor. Like a dynamic cursor, except that user can't see record
that other users add, although records that other user delete are inaccessible from your Recordset.
Data changes by other users are still visible.

adOpenDynamic (2) - Uses a dynamic cursor. Additions, changes, and deletions by other users
are visible, and all types of movement through the Recordset are allowed, except for bookmarks,
if the provider doesn't support them.

adOpenStatic (3) - Uses a static cursor. Additions, changes, or deletions by other users are not
visible.

Command Object

The ADO Command object is used to execute a single query against a database. The query can
perform actions like creating, adding, retrieving, deleting and updating records. If the query is
used to retrieve data, the data will be returned as a RecordSet object. This means that the
retrieved data can be manipulated by properties, collections, methods, and events of the
Recordset object. The major feature of the Command object is the ability to use stored queries
and procedures with parameters.

Lock Types

While cursor locations and cursor types specify how our data is going to be handled, the lock
type property specifies how we are going to lock the underlying data to protect any changes we
make and ensure they are processed. There are four different lock types, and the lock type is set
in the recordset object as part of the open method (it can also be set using the LockType property
of the recordset object). The four lock types are: adLockReadOnly (default), adLockOptimistic,
adLockPessimistic, and adLockBatchOptimistic. All four lock types are available to a server-side
cursor; the adLockPessimistic locktype is unavailable to a client-side cursor.

adLockReadOnly

The default lock type is adLockReadOnly. A read-only lock is the most efficient when accessing
data, as there is no checking for data changes and therefore no extra traffic between the client
and server while loading records. As the name implies, using a read-only lock will block you
from making any changes to the table that is it possible see the content of the table alone.

adLockOptimistic

An optimistic lock is used for modifications that either happens in a low-concurrency


environment, or where having multiple users making changes to the same records is not a major
concern. With an optimistic lock, the table or row locks will occur when the update method of
the recordset object is called. This will ensure the change is successfully made, but will not
prevent other users from changing the underlying data while you are modifying it in VB.

The adLockOptimistic lock type is typically the best choice when deciding on a table lock for a
non-read-only situation.

adLockBatchOptimistic

When using the adBatchOptimistic lock type, changes will be cached locally until the recordset's
UpdateBatch method is called. When UpdateBatch is called, all changes will be pushed to the
server in a group. This can make the bulk insert of a large number of records more efficient.

adLockPessimistic

In a situation of high concurrency, with multiple users modifying the same data, it may need a
pessimistic lock type. With asLockPessimistic, the underlying rows (or table) will be locked as
soon as you begin making changes to the current record, and will not be unlocked until the
Update method is called.

You might also like