![]() ![]() [ The Perl Journal ]
|
This summary document was originally published in "Programming the Perl DBI"
The driver author is Tim Bunce. He can be contacted via the
dbi-users mailing list.
The
Building for Oracle 8 defaults to use the new Oracle 8 OCI interface, which
enables use of some Oracle 8 features including LOBs and ``INSERT ...
RETURNING ...''.
An emulation module for the old Perl4 oraperl software is supplied with
For further information about Oracle, refer to:
The
Some other less common formats also work if supported by the Oracle client
version being used.
There are no significant driver specific attributes for the
Oracle only has one flexible underlying numeric type, NUMBER. But Oracle
does support several ANSI standard and IBM data type names as aliases,
including:
The NUMBER datatype stores positive and negative fixed and floating-point
numbers with magnitudes between 1.0 x 10-130 and 9.9...9 x 10125 (38 nines
followed by 88 zeroes), with 38 digits of precision.
You can specify a fixed-point number using the following form:
You can specify an integer using
You can specify a floating-point number using NUMBER. This is a
floating-point number with decimal precision 38. A scale value is not
applicable for floating-point numbers.
Oracle supports the following string data types:
The RAW type is presented as hexadecimal characters. The contents are
treated as non-character binary data and thus are never ``translated'' by
character set conversions or gateway interfaces.
CHAR types and the RAW type have a limit of 2000 bytes. For VARCHAR types
the limit is 2000 bytes in Oracle 7 and 4000 in Oracle 8.
The NVARCHAR2 and NCHAR variants hold string values of a defined national
character set (Oracle 8 only). For those types the maximum number of
characters stored may be lower when using multibyte character sets.
The CHAR and NCHAR types are fixed length and blank padded.
Oracle automatically converts character data between the character set of
the database defined when the database was created and the character set of
the client, defined by the NLS_LANG parameter for the CHAR and VARCHAR2
types or the NLS_NCHAR parameter for the NCHAR and NVARCHAR2 types.
CONVERT(string, dest_char_set, source_char_set) can be used to convert strings between character sets. Oracle 8 supports
180 storage character sets. UTF-8 is supported. See the National Language
Support section of the Oracle Reference manual for more details on
character set issues.
Strings can be concatenated using either the
Oracle supports one flexible date/time data type: DATE. A DATE can have any
value from January 1, 4712 BC to December 31, 4712 AD with a one second
resolution.
Oracle supports a very wide range of date formats and can use one of
several calendars (Arabic Hijrah, English Hijrah, Gregorian, Japanese
Imperial, Persian, ROC Official (Republic of China) and Thai Buddha). We'll
only consider the Gregorian calendar here.
The default output format for the DATE type is defined by the
NLS_DATE_FORMAT configuration parameter, but it's typically
If you specify a DATE value without a time component, the default time is
00:00:00 (midnight). If you specify a DATE value without a date, the
default date is the first day of the current month. If a date format that
has a two digit year, such as the
The default date format is specified either explicitly with the
initialization parameter NLS_DATE_FORMAT or implicitly with the
initialization parameter NLS_TERRITORY. For information on these
parameters, see Oracle8 Referencee.
You can change the default date format for your session with the ``ALTER
SESSION'' command. For example:
The
The
The current datetime is returned by the
You can add numbers to DATE values. The number is interpreted as numbers of
days; for example,
Oracle provides a wide range of date functions including
The following SQL expression can be used to convert an integer ``seconds
since 1-jan-1970'' value to the corresponding database date time:
To do the reverse you can use:
Oracle does no automatic time zone adjustments. However it does provide a
Oracle supports these LONG/BLOB data types:
The LONG types can hold upto 2 gigabytes. The other types (LOB and FILE)
can hold upto 4 gigabytes. The LOB and FILE types are only available when
using Oracle 8 OCI.
The LONG RAW, and RAW, types are passed to and from the database as strings
consisting of pairs of hex digits.
The LongReadLen and LongTruncOk attributes work as defined. However, the LongReadLen attribute seems to be
limited to 65535 bytes on most platforms when using Oracle 7. Building
The maximum length of
The TYPE attribute value SQL_LONGVARCHAR indicates an Oracle LONG type. The
value SQL_LONGVARBINARY indicates an Oracle LONG RAW type. These values are
not always required but their use is strongly recommended.
No other special handling is required for LONG/BLOB data types. They can be
treated just like any other field when fetching or inserting etc.
The
Oracle supports automatic conversions between data types wherever it's
reasonable.
Oracle supports READ COMMITED and SERIALIZABLE isolation levels. The level
be changed once per-transaction by executing a
Oracle also supports transaction-level read consistency. This can be
enabled by issuing a SET TRANSACTION statement with the READ ONLY option.
In Oracle, the default behavior is that a lock never prevents other users
from querying the table. A query never places a lock on a table. Readers
never block writers and writers never block readers.
Rows returned by a SELECT statement can be locked to prevent them from
being changed by another transaction by appending
The
The LIKE operator is case sensitive.
Oracle supports inner joins with the usual syntax:
To write a query that performs an outer join of tables A and B and returns
all rows from A, the Oracle outer join operator (
For all rows in the customers table that have no matching rows in the
orders table, Oracle returns NULL for any select list expressions
containing columns from the orders table.
The names of Oracle identifiers, such as tables and columns, cannot exceed
30 characters in length.
The first character must be a letter, but the rest can be any combination
of letters, numerals, dollar signs (
However, if an Oracle identifier is enclosed by double quotation marks (
Oracle converts all identifiers to upper-case unless enclosed in double
quotation marks. National characters can also be used when identifiers are
quoted.
The Oracle ``row id'' pseudocolumn is called ROWID. Oracle ROWIDs are
alphanumeric case sensitive strings. They can be treated as ordinary
strings and used to rapidly (re)select rows.
Oracle supports ``sequence generators''. Any number of named sequence
generators can be created in a database using the
To get the value just inserted you can use
Oracle does not support automatic key generation such as ``auto increment''
or ``system generated'' keys. However they can be emulated using triggers
and sequence generators. For example:
Oracle8i (8.1.0 and above) supports Universal Unique ID number generation,
per the IETF Internet-Draft, using the new
The ROWNUM pseudocolumn can be used to sequentially number selected rows
(starting at 1). Sadly, however, Oracle's ROWNUM has some frustrating
limitations. Refer to the Oracle SQL documentation.
Oracle does not support positioned updates or deletes.
Parameter binding is directly suported by Oracle. Both the
The
The SQL_CHAR type is bound as a CHAR thus enabling fixed-width blank padded
comparison semantics.
The SQL_BINARY and SQL_VARBINARY types are bound as RAW. SQL_LONGVARBINARY
is bound as LONG RAW and SQL_LONGVARCHAR as LONG.
Unsupported values of the TYPE attribute generate a warning.
Refer to the DBD::Oracle documentation for details of how to bind LOBs and
CURSORs.
Oracle stored procedures are implemented in the Oracle PL/SQL language*.
The
Here's a more complex example that shows a stored procedure being called
with two parameters and returning the return value of the procedure. The
second parameter of the procedure is defined as
The ALL_TABLES view contains detailed information about all tables in the database, one
row per table.
The ALL_TAB_COLUMNS view contains detailed information about all columns of all the tables in
the database, one row per table.
The ALL_INDEXES view contains detailed information about all indexes in the database,
including primary keys, one row per index.
The ALL_IND_COLUMNS view contains information about the columns that make up each index.
(Note that for all these views, fields containing statistics derived from
the actual data in the corresponding table are updated only when the SQL
The following private methods are supported:
Returns error text from the USER_ERRORS table.
Enables the DBMS_OUTPUT package. The DBMS_OUTPUT package is typically used
to receive trace and informational messages from stored procedures.
Gets a single line or all available lines using DBMS_OUTPUT.GET_LINE.
Puts messages using DBMS_OUTPUT.PUT_LINE.
|
![]() [ Related Books ] |
|