Module Interface

cx_Oracle.__future__

Special object which contains attributes which control the behavior of cx_Oracle, allowing for opting in for new features. No attributes are currently supported so all attributes will silently ignore being set and will always appear to have the value None.

Note

This method is an extension to the DB API definition.

New in version 6.2.

cx_Oracle.Binary(string)

Construct an object holding a binary (long) string value.

cx_Oracle.clientversion()

Return the version of the client library being used as a 5-tuple. The five values are the major version, minor version, update number, patch number and port update number.

Note

This method is an extension to the DB API definition.

cx_Oracle.Connection(user=None, password=None, dsn=None, mode=None, handle=None, pool=None, threaded=False, events=False, cclass=None, purity=None, newpassword=None, encoding=None, nencoding=None, edition=None, appcontext=[], tag=None, matchanytag=False, shardingkey=[], supershardingkey=[])
cx_Oracle.connect(user=None, password=None, dsn=None, mode=None, handle=None, pool=None, threaded=False, events=False, cclass=None, purity=None, newpassword=None, encoding=None, nencoding=None, edition=None, appcontext=[], tag=None, matchanytag=None, shardingkey=[], supershardingkey=[])

Constructor for creating a connection to the database. Return a connection object. All parameters are optional and can be specified as keyword parameters.

The dsn (data source name) is the TNS entry (from the Oracle names server or tnsnames.ora file) or is a string like the one returned from makedsn(). If only one parameter is passed, a connect string is assumed which is to be of the format user/password@dsn, the same format accepted by Oracle applications such as SQL*Plus.

If the mode is specified, it must be one of SYSDBA, SYSASM, SYSOPER, SYSBKP, SYSDGD, SYSKMT or SYSRAC which are defined at the module level; otherwise, it defaults to the normal mode of connecting.

If the handle is specified, it must be of type OCISvcCtx* and is only of use when embedding Python in an application (like PowerBuilder) which has already made the connection.

The pool parameter is expected to be a session pool object and the use of this parameter is the equivalent of calling SessionPool.acquire(). Parameters not acecpted by that method are ignored.

The threaded parameter is expected to be a boolean expression which indicates whether or not Oracle should wrap accesses to connections with a mutex. Doing so in single threaded applications imposes a performance penalty of about 10-15% which is why the default is False.

The events parameter is expected to be a boolean expression which indicates whether or not to initialize Oracle in events mode. This is required for continuous query notification and high availablity event notifications.

The cclass parameter is expected to be a string and defines the connection class for database resident connection pooling (DRCP).

The purity parameter is expected to be one of ATTR_PURITY_NEW, ATTR_PURITY_SELF, or ATTR_PURITY_DEFAULT.

The newpassword parameter is expected to be a string if specified and sets the password for the logon during the connection process.

The encoding parameter is expected to be one of the Python standard encodings such as ‘UTF-8’, if specified, and sets the encoding to use for regular database strings. If not specified, the Oracle environment variable NLS_LANG is used and the Oracle character set is translated to one of the standard encodings, if possible. If the Oracle environment variable NLS_LANG is not set, ASCII is used.

The nencoding parameter is expected to be one of the Python standard encodings such as ‘UTF-8’, if specified, and sets the encoding to use for national character set database strings. If not specified, the Oracle environment variable NLS_NCHAR is used and the Oracle character set is translated to one of the standard encodings, if possible. If the Oracle environment variable NLS_NCHAR is not used, the Oracle environment variable NLS_LANG is used instead, and if the Oracle environment variable NLS_LANG is not set, ASCII is used.

The edition parameter is expected to be a string if specified and sets the edition to use for the session. It is only relevant if both the client and the database are at least Oracle Database 11.2. If this parameter is used with the cclass parameter the exception “DPI-1058: edition not supported with connection class” will be raised.

The appcontext parameter is expected to be a list of 3-tuples, if specified, and sets the application context for the connection. Application context is available in the database by using the sys_context() PL/SQL method and can be used within a logon trigger as well as any other PL/SQL procedures. Each entry in the list is expected to contain three strings: the namespace, the name and the value.

The tag parameter, if specified, is expected to be a string and will limit the sessions that can be returned from a session pool unless the matchanytag parameter is set to True. In that case sessions with the specified tag will be preferred over others, but if no such sessions are available a session with a different tag may be returned instead. In any case, untagged sessions will always be returned if no sessions with the specified tag are available. Sessions are tagged when they are released back to the pool.

The shardingkey and supershardingkey parameters, if specified, are expected to be a sequence of values which will be used to identify the database shard to connect to. Currently only strings are supported for the key values.

cx_Oracle.Cursor(connection)

Constructor for creating a cursor. Return a new cursor object using the connection.

Note

This method is an extension to the DB API definition.

cx_Oracle.Date(year, month, day)

Construct an object holding a date value.

cx_Oracle.DateFromTicks(ticks)

Construct an object holding a date value from the given ticks value (number of seconds since the epoch; see the documentation of the standard Python time module for details).

cx_Oracle.makedsn(host, port, sid=None, service_name=None, region=None, sharding_key=None, super_sharding_key=None)

Return a string suitable for use as the dsn parameter for connect(). This string is identical to the strings that are defined by the Oracle names server or defined in the tnsnames.ora file.

Note

This method is an extension to the DB API definition.

cx_Oracle.SessionPool(user=None, password=None, dsn=None, min=1, max=2, increment=1, connectiontype=cx_Oracle.Connection, threaded=False, getmode=cx_Oracle.SPOOL_ATTRVAL_NOWAIT, events=False, homogeneous=True, externalauth=False, encoding=None, nencoding=None, edition=None, timeout=0, waitTimeout=0, maxLifetimeSession=0, sessionCallback=None)

Create and return a session pool object. This allows for very fast connections to the database and is of primary use in a server where the same connection is being made multiple times in rapid succession (a web server, for example).

If the connection type is specified, all calls to acquire() will create connection objects of that type, rather than the base type defined at the module level.

The threaded parameter is expected to be a boolean expression which indicates whether Oracle should wrap accesses to connections with a mutex. Doing so in single threaded applications imposes a performance penalty of about 10-15% which is why the default is False.

The events parameter is expected to be a boolean expression which indicates whether or not to initialize Oracle in events mode. This is required for continuous query notification and high availability event notifications.

The homogeneous parameter is expected to be a boolean expression which indicates whether or not to create a homogeneous pool. A homogeneous pool requires that all connections in the pool use the same credentials. As such proxy authentication and external authentication is not possible with a homogeneous pool.

The externalauth parameter is expected to be a boolean expression which indicates whether or not external authentication should be used. External authentication implies that something other than the database is authenticating the user to the database. This includes the use of operating system authentication and Oracle wallets.

The encoding parameter is expected to be one of the Python standard encodings such as ‘UTF-8’, if specified, and sets the encoding to use for regular database strings. If not specified, the Oracle environment variable NLS_LANG is used and the Oracle character set is translated to one of the standard encodings, if possible. If the Oracle environment variable NLS_LANG is not set, ASCII is used.

The nencoding parameter is expected to be one of the Python standard encodings such as ‘UTF-8’, if specified, and sets the encoding to use for national character set database strings. If not specified, the Oracle environment variable NLS_NCHAR is used and the Oracle character set is translated to one of the standard encodings, if possible. If the Oracle environment variable NLS_NCHAR is not used, the Oracle environment variable NLS_LANG is used instead, and if the Oracle environment variable NLS_LANG is not set, ASCII is used.

The edition parameter is expected to be a string, if specified, and sets the edition to use for the sessions in the pool. It is only relevant if both the client and the server are at least Oracle Database 11.2.

The timeout parameter is expected to be an integer, if specified, and sets the length of time (in seconds) after which idle sessions in the pool are terminated. Note that termination only occurs when the pool is accessed. The default value of 0 means that no idle sessions are terminated.

The waitTimeout parameter is expected to be an integer, if specified, and sets the length of time (in milliseconds) that the caller should wait for a session to become available in the pool before returning with an error. This value is only used if the getmode parameter is set to the value cx_Oracle.SPOOL_ATTRVAL_TIMEDWAIT.

The maxLifetimeSession parameter is expected to be an integer, if specified, and sets the maximum length of time (in seconds) a pooled session may exist. Sessions that are in use will not be closed. They become candidates for termination only when they are released back to the pool and have existed for longer than maxLifetimeSession seconds. Note that termination only occurs when the pool is accessed. The default value is 0 which means that there is no maximum length of time that a pooled session may exist.

The sessionCallback parameter is expected to be either a string or a callable. If the parameter is a string, this refers to a PL/SQL procedure that will be called when SessionPool.acquire() requests a tag and that tag does not match the connection’s actual tag. Support for the PL/SQL procedure requires Oracle Client libraries 12.2 or later. See the OCI documentation for more information. If the sessionCallback parameter is a callable, however, it will be called when a newly created connection is returned from the pool or when a tag is requested and that tag does not match the connection’s actual tag. The callable will be invoked with the connection and the requested tag as its only parameters.

Note

This method is an extension to the DB API definition.

cx_Oracle.Time(hour, minute, second)

Construct an object holding a time value.

Note

The time only data type is not supported by Oracle. Calling this function will raise a NotSupportedError exception.

cx_Oracle.TimeFromTicks(ticks)

Construct an object holding a time value from the given ticks value (number of seconds since the epoch; see the documentation of the standard Python time module for details).

Note

The time only data type is not supported by Oracle. Calling this function will raise a NotSupportedError exception.

cx_Oracle.Timestamp(year, month, day, hour, minute, second)

Construct an object holding a time stamp value.

cx_Oracle.TimestampFromTicks(ticks)

Construct an object holding a time stamp value from the given ticks value (number of seconds since the epoch; see the documentation of the standard Python time module for details).

Constants

General

cx_Oracle.apilevel

String constant stating the supported DB API level. Currently ‘2.0’.

cx_Oracle.buildtime

String constant stating the time when the binary was built.

Note

This constant is an extension to the DB API definition.

cx_Oracle.paramstyle

String constant stating the type of parameter marker formatting expected by the interface. Currently ‘named’ as in ‘where name = :name’.

cx_Oracle.threadsafety

Integer constant stating the level of thread safety that the interface supports. Currently 2, which means that threads may share the module and connections, but not cursors. Sharing means that a thread may use a resource without wrapping it using a mutex semaphore to implement resource locking.

Note that in order to make use of multiple threads in a program which intends to connect and disconnect in different threads, the threaded parameter to connect() or SessionPool() must be true.

cx_Oracle.version
cx_Oracle.__version__

String constant stating the version of the module. Currently ‘7.1.3’.

Note

This attribute is an extension to the DB API definition.

Advanced Queuing: Delivery Modes

These constants are extensions to the DB API definition. They are possible values for the deliverymode attribute of the dequeue options object passed as the options parameter to the Connection.deq() method as well as the deliverymode attribute of the enqueue options object passed as the options parameter to the Connection.enq() method. They are also possible values for the deliverymode attribute of the message properties object passed as the msgproperties parameter to the Connection.deq() and Connection.enq() methods.

cx_Oracle.MSG_BUFFERED

This constant is used to specify that enqueue/dequeue operations should enqueue or dequeue buffered messages.

cx_Oracle.MSG_PERSISTENT

This constant is used to specify that enqueue/dequeue operations should enqueue or dequeue persistent messages. This is the default value.

cx_Oracle.MSG_PERSISTENT_OR_BUFFERED

This constant is used to specify that dequeue operations should dequeue either persistent or buffered messages.

Advanced Queuing: Dequeue Modes

These constants are extensions to the DB API definition. They are possible values for the mode attribute of the dequeue options object. This object is the options parameter for the Connection.deq() method.

cx_Oracle.DEQ_BROWSE

This constant is used to specify that dequeue should read the message without acquiring any lock on the message (eqivalent to a select statement).

cx_Oracle.DEQ_LOCKED

This constant is used to specify that dequeue should read and obtain a write lock on the message for the duration of the transaction (equivalent to a select for update statement).

cx_Oracle.DEQ_REMOVE

This constant is used to specify that dequeue should read the message and update or delete it. This is the default value.

cx_Oracle.DEQ_REMOVE_NODATA

This constant is used to specify that dequeue should confirm receipt of the message but not deliver the actual message content.

Advanced Queuing: Dequeue Navigation Modes

These constants are extensions to the DB API definition. They are possible values for the navigation attribute of the dequeue options object. This object is the options parameter for the Connection.deq() method.

cx_Oracle.DEQ_FIRST_MSG

This constant is used to specify that dequeue should retrieve the first available message that matches the search criteria. This resets the position to the beginning of the queue.

cx_Oracle.DEQ_NEXT_MSG

This constant is used to specify that dequeue should retrieve the next available message that matches the search criteria. If the previous message belongs to a message group, AQ retrieves the next available message that matches the search criteria and belongs to the message group. This is the default.

cx_Oracle.DEQ_NEXT_TRANSACTION

This constant is used to specify that dequeue should skip the remainder of the transaction group and retrieve the first message of the next transaction group. This option can only be used if message grouping is enabled for the current queue.

Advanced Queuing: Dequeue Visibility Modes

These constants are extensions to the DB API definition. They are possible values for the visibility attribute of the dequeue options object. This object is the options parameter for the Connection.deq() method.

cx_Oracle.DEQ_IMMEDIATE

This constant is used to specify that dequeue should perform its work as part of an independent transaction.

cx_Oracle.DEQ_ON_COMMIT

This constant is used to specify that dequeue should be part of the current transaction. This is the default value.

Advanced Queuing: Dequeue Wait Modes

These constants are extensions to the DB API definition. They are possible values for the wait attribute of the dequeue options object. This object is the options parameter for the Connection.deq() method.

cx_Oracle.DEQ_NO_WAIT

This constant is used to specify that dequeue not wait for messages to be available for dequeuing.

cx_Oracle.DEQ_WAIT_FOREVER

This constant is used to specify that dequeue should wait forever for messages to be available for dequeuing. This is the default value.

Advanced Queuing: Enqueue Visibility Modes

These constants are extensions to the DB API definition. They are possible values for the visibility attribute of the enqueue options object. This object is the options parameter for the Connection.enq() method.

cx_Oracle.ENQ_IMMEDIATE

This constant is used to specify that enqueue should perform its work as part of an independent transaction.

cx_Oracle.ENQ_ON_COMMIT

This constant is used to specify that enqueue should be part of the current transaction. This is the default value.

Advanced Queuing: Message States

These constants are extensions to the DB API definition. They are possible values for the state attribute of the message properties object. This object is the msgproperties parameter for the Connection.deq() and Connection.enq() methods.

cx_Oracle.MSG_EXPIRED

This constant is used to specify that the message has been moved to the exception queue.

cx_Oracle.MSG_PROCESSED

This constant is used to specify that the message has been processed and has been retained.

cx_Oracle.MSG_READY

This constant is used to specify that the message is ready to be processed.

cx_Oracle.MSG_WAITING

This constant is used to specify that the message delay has not yet been reached.

Advanced Queuing: Other

These constants are extensions to the DB API definition. They are special constants used in advanced queuing.

cx_Oracle.MSG_NO_DELAY

This constant is a possible value for the delay attribute of the message properties object passed as the msgproperties parameter to the Connection.deq() and Connection.enq() methods. It specifies that no delay should be imposed and the message should be immediately available for dequeuing. This is also the default value.

cx_Oracle.MSG_NO_EXPIRATION

This constant is a possible value for the expiration attribute of the message properties object passed as the msgproperties parameter to the Connection.deq() and Connection.enq() methods. It specifies that the message never expires. This is also the default value.

Connection Authorization Modes

These constants are extensions to the DB API definition. They are possible values for the mode parameter of the connect() method.

cx_Oracle.PRELIM_AUTH

This constant is used to specify that preliminary authentication is to be used. This is needed for performing database startup and shutdown.

cx_Oracle.SYSASM

This constant is used to specify that SYSASM access is to be acquired.

cx_Oracle.SYSBKP

This constant is used to specify that SYSBACKUP access is to be acquired.

cx_Oracle.SYSDBA

This constant is used to specify that SYSDBA access is to be acquired.

cx_Oracle.SYSDGD

This constant is used to specify that SYSDG access is to be acquired.

cx_Oracle.SYSKMT

This constant is used to specify that SYSKM access is to be acquired.

cx_Oracle.SYSOPER

This constant is used to specify that SYSOPER access is to be acquired.

cx_Oracle.SYSRAC

This constant is used to specify that SYSRAC access is to be acquired.

Database Shutdown Modes

These constants are extensions to the DB API definition. They are possible values for the mode parameter of the Connection.shutdown() method.

cx_Oracle.DBSHUTDOWN_ABORT

This constant is used to specify that the caller should not wait for current processing to complete or for users to disconnect from the database. This should only be used in unusual circumstances since database recovery may be necessary upon next startup.

cx_Oracle.DBSHUTDOWN_FINAL

This constant is used to specify that the instance can be truly halted. This should only be done after the database has been shutdown with one of the other modes (except abort) and the database has been closed and dismounted using the appropriate SQL commands.

cx_Oracle.DBSHUTDOWN_IMMEDIATE

This constant is used to specify that all uncommitted transactions should be rolled back and any connected users should be disconnected.

cx_Oracle.DBSHUTDOWN_TRANSACTIONAL

This constant is used to specify that further connections to the database should be prohibited and no new transactions should be allowed. It then waits for all active transactions to complete.

cx_Oracle.DBSHUTDOWN_TRANSACTIONAL_LOCAL

This constant is used to specify that further connections to the database should be prohibited and no new transactions should be allowed. It then waits for only local active transactions to complete.

Event Types

These constants are extensions to the DB API definition. They are possible values for the Message.type attribute of the messages that are sent for subscriptions created by the Connection.subscribe() method.

cx_Oracle.EVENT_AQ

This constant is used to specify that one or more messages are available for dequeuing on the queue specified when the subscription was created.

cx_Oracle.EVENT_DEREG

This constant is used to specify that the subscription has been deregistered and no further notifications will be sent.

cx_Oracle.EVENT_NONE

This constant is used to specify no information is available about the event.

cx_Oracle.EVENT_OBJCHANGE

This constant is used to specify that a database change has taken place on a table registered with the Subscription.registerquery() method.

cx_Oracle.EVENT_QUERYCHANGE

This constant is used to specify that the result set of a query registered with the Subscription.registerquery() method has been changed.

cx_Oracle.EVENT_SHUTDOWN

This constant is used to specify that the instance is in the process of being shut down.

cx_Oracle.EVENT_SHUTDOWN_ANY

This constant is used to specify that any instance (when running RAC) is in the process of being shut down.

cx_Oracle.EVENT_STARTUP

This constant is used to specify that the instance is in the process of being started up.

Operation Codes

These constants are extensions to the DB API definition. They are possible values for the operations parameter for the Connection.subscribe() method. One or more of these values can be OR’ed together. These values are also used by the MessageTable.operation or MessageQuery.operation attributes of the messages that are sent.

cx_Oracle.OPCODE_ALLOPS

This constant is used to specify that messages should be sent for all operations.

cx_Oracle.OPCODE_ALLROWS

This constant is used to specify that the table or query has been completely invalidated.

cx_Oracle.OPCODE_ALTER

This constant is used to specify that messages should be sent when a registered table has been altered in some fashion by DDL, or that the message identifies a table that has been altered.

cx_Oracle.OPCODE_DELETE

This constant is used to specify that messages should be sent when data is deleted, or that the message identifies a row that has been deleted.

cx_Oracle.OPCODE_DROP

This constant is used to specify that messages should be sent when a registered table has been dropped, or that the message identifies a table that has been dropped.

cx_Oracle.OPCODE_INSERT

This constant is used to specify that messages should be sent when data is inserted, or that the message identifies a row that has been inserted.

cx_Oracle.OPCODE_UPDATE

This constant is used to specify that messages should be sent when data is updated, or that the message identifies a row that has been updated.

Session Pool Get Modes

These constants are extensions to the DB API definition. They are possible values for the getmode parameter of the SessionPool() method.

cx_Oracle.SPOOL_ATTRVAL_FORCEGET

This constant is used to specify that a new connection will be returned if there are no free sessions available in the pool.

cx_Oracle.SPOOL_ATTRVAL_NOWAIT

This constant is used to specify that an exception should be raised if there are no free sessions available in the pool. This is the default value.

cx_Oracle.SPOOL_ATTRVAL_WAIT

This constant is used to specify that the caller should wait until a session is available if there are no free sessions available in the pool.

cx_Oracle.SPOOL_ATTRVAL_TIMEDWAIT

This constant is used to specify that the caller should wait for a period of time (defined by the waitTimeout parameter) for a session to become available before returning with an error.

Session Pool Purity

These constants are extensions to the DB API definition. They are possible values for the purity parameter of the connect() method, which is used in database resident connection pooling (DRCP).

cx_Oracle.ATTR_PURITY_DEFAULT

This constant is used to specify that the purity of the session is the default value identified by Oracle (see Oracle’s documentation for more information). This is the default value.

cx_Oracle.ATTR_PURITY_NEW

This constant is used to specify that the session acquired from the pool should be new and not have any prior session state.

cx_Oracle.ATTR_PURITY_SELF

This constant is used to specify that the session acquired from the pool need not be new and may have prior session state.

Subscription Grouping Classes

These constants are extensions to the DB API definition. They are possible values for the groupingClass parameter of the Connection.subscribe() method.

cx_Oracle.SUBSCR_GROUPING_CLASS_TIME

This constant is used to specify that events are to be grouped by the period of time in which they are received.

Subscription Grouping Types

These constants are extensions to the DB API definition. They are possible values for the groupingType parameter of the Connection.subscribe() method.

cx_Oracle.SUBSCR_GROUPING_TYPE_SUMMARY

This constant is used to specify that when events are grouped a summary of the events should be sent instead of the individual events. This is the default value.

cx_Oracle.SUBSCR_GROUPING_TYPE_LAST

This constant is used to specify that when events are grouped the last event that makes up the group should be sent instead of the individual events.

Subscription Namespaces

These constants are extensions to the DB API definition. They are possible values for the namespace parameter of the Connection.subscribe() method.

cx_Oracle.SUBSCR_NAMESPACE_AQ

This constant is used to specify that notifications should be sent when a queue has messages available to dequeue.

cx_Oracle.SUBSCR_NAMESPACE_DBCHANGE

This constant is used to specify that database change notification or query change notification messages are to be sent. This is the default value.

Subscription Protocols

These constants are extensions to the DB API definition. They are possible values for the protocol parameter of the Connection.subscribe() method.

cx_Oracle.SUBSCR_PROTO_HTTP

This constant is used to specify that notifications will be sent to an HTTP URL when a message is generated. This value is currently not supported.

cx_Oracle.SUBSCR_PROTO_MAIL

This constant is used to specify that notifications will be sent to an e-mail address when a message is generated. This value is currently not supported.

cx_Oracle.SUBSCR_PROTO_OCI

This constant is used to specify that notifications will be sent to the callback routine identified when the subscription was created. It is the default value and the only value currently supported.

cx_Oracle.SUBSCR_PROTO_SERVER

This constant is used to specify that notifications will be sent to a PL/SQL procedure when a message is generated. This value is currently not supported.

Subscription Quality of Service

These constants are extensions to the DB API definition. They are possible values for the qos parameter of the Connection.subscribe() method. One or more of these values can be OR’ed together.

cx_Oracle.SUBSCR_QOS_BEST_EFFORT

This constant is used to specify that best effort filtering for query result set changes is acceptable. False positive notifications may be received. This behaviour may be suitable for caching applications.

cx_Oracle.SUBSCR_QOS_DEREG_NFY

This constant is used to specify that the subscription should be automatically unregistered after the first notification is received.

cx_Oracle.SUBSCR_QOS_QUERY

This constant is used to specify that notifications should be sent if the result set of the registered query changes. By default no false positive notifications will be generated.

cx_Oracle.SUBSCR_QOS_RELIABLE

This constant is used to specify that notifications should not be lost in the event of database failure.

cx_Oracle.SUBSCR_QOS_ROWIDS

This constant is used to specify that the rowids of the inserted, updated or deleted rows should be included in the message objects that are sent.

Types

cx_Oracle.BINARY

This type object is used to describe columns in a database that contain binary data. In Oracle this is RAW columns.

cx_Oracle.BFILE

This type object is used to describe columns in a database that are BFILEs.

Note

This type is an extension to the DB API definition.

cx_Oracle.BLOB

This type object is used to describe columns in a database that are BLOBs.

Note

This type is an extension to the DB API definition.

cx_Oracle.BOOLEAN

This type object is used to represent PL/SQL booleans.

New in version 5.2.1.

Note

This type is an extension to the DB API definition. It is only available in Oracle 12.1 and higher and only within PL/SQL. It cannot be used in columns.

cx_Oracle.CLOB

This type object is used to describe columns in a database that are CLOBs.

Note

This type is an extension to the DB API definition.

cx_Oracle.CURSOR

This type object is used to describe columns in a database that are cursors (in PL/SQL these are known as ref cursors).

Note

This type is an extension to the DB API definition.

cx_Oracle.DATETIME

This type object is used to describe columns in a database that are dates.

cx_Oracle.FIXED_CHAR

This type object is used to describe columns in a database that are fixed length strings (in Oracle these is CHAR columns); these behave differently in Oracle than varchar2 so they are differentiated here even though the DB API does not differentiate them.

Note

This attribute is an extension to the DB API definition.

cx_Oracle.FIXED_NCHAR

This type object is used to describe columns in a database that are NCHAR columns in Oracle; these behave differently in Oracle than nvarchar2 so they are differentiated here even though the DB API does not differentiate them.

Note

This type is an extension to the DB API definition.

cx_Oracle.INTERVAL

This type object is used to describe columns in a database that are of type interval day to second.

Note

This type is an extension to the DB API definition.

cx_Oracle.LOB

This type object is the Python type of BLOB and CLOB data that is returned from cursors.

Note

This type is an extension to the DB API definition.

cx_Oracle.LONG_BINARY

This type object is used to describe columns in a database that are long binary (in Oracle these are LONG RAW columns).

Note

This type is an extension to the DB API definition.

cx_Oracle.LONG_STRING

This type object is used to describe columns in a database that are long strings (in Oracle these are LONG columns).

Note

This type is an extension to the DB API definition.

cx_Oracle.NATIVE_FLOAT

This type object is used to describe columns in a database that are of type binary_double or binary_float.

Note

This type is an extension to the DB API definition.

cx_Oracle.NATIVE_INT

This type object is used to bind integers using Oracle’s native integer support, rather than the standard number support.

New in version 5.3.

Note

This type is an extension to the DB API definition.

cx_Oracle.NCHAR

This type object is used to describe national character strings (NVARCHAR2) in Oracle.

Note

This type is an extension to the DB API definition.

cx_Oracle.NCLOB

This type object is used to describe columns in a database that are NCLOBs.

Note

This type is an extension to the DB API definition.

cx_Oracle.NUMBER

This type object is used to describe columns in a database that are numbers.

cx_Oracle.OBJECT

This type object is used to describe columns in a database that are objects.

Note

This type is an extension to the DB API definition.

cx_Oracle.ROWID

This type object is used to describe the pseudo column “rowid”.

cx_Oracle.STRING

This type object is used to describe columns in a database that are strings (in Oracle this is VARCHAR2 columns).

cx_Oracle.TIMESTAMP

This type object is used to describe columns in a database that are timestamps.

Note

This attribute is an extension to the DB API definition.

Exceptions

exception cx_Oracle.Warning

Exception raised for important warnings and defined by the DB API but not actually used by cx_Oracle.

exception cx_Oracle.Error

Exception that is the base class of all other exceptions defined by cx_Oracle and is a subclass of the Python StandardError exception (defined in the module exceptions).

exception cx_Oracle.InterfaceError

Exception raised for errors that are related to the database interface rather than the database itself. It is a subclass of Error.

exception cx_Oracle.DatabaseError

Exception raised for errors that are related to the database. It is a subclass of Error.

exception cx_Oracle.DataError

Exception raised for errors that are due to problems with the processed data. It is a subclass of DatabaseError.

exception cx_Oracle.OperationalError

Exception raised for errors that are related to the operation of the database but are not necessarily under the control of the progammer. It is a subclass of DatabaseError.

exception cx_Oracle.IntegrityError

Exception raised when the relational integrity of the database is affected. It is a subclass of DatabaseError.

exception cx_Oracle.InternalError

Exception raised when the database encounters an internal error. It is a subclass of DatabaseError.

exception cx_Oracle.ProgrammingError

Exception raised for programming errors. It is a subclass of DatabaseError.

exception cx_Oracle.NotSupportedError

Exception raised when a method or database API was used which is not supported by the database. It is a subclass of DatabaseError.

Exception handling

Note

PEP 249 (Python Database API Specification v2.0) says the following about exception values:

[…] The values of these exceptions are not defined. They should give the user a fairly good idea of what went wrong, though. […]

With cx_Oracle every exception object has exactly one argument in the args tuple. This argument is a cx_Oracle._Error object which has the following five read-only attributes.

_Error.code

Integer attribute representing the Oracle error number (ORA-XXXXX).

_Error.offset

Integer attribute representing the error offset when applicable.

_Error.message

String attribute representing the Oracle message of the error. This message is localized by the environment of the Oracle connection.

_Error.context

String attribute representing the context in which the exception was raised.

_Error.isrecoverable

Boolean attribute representing whether the error is recoverable or not. This is False in all cases unless Oracle Database 12.1 is being used on both the server and the client.

New in version 5.3.

This allows you to use the exceptions for example in the following way:

from __future__ import print_function

import cx_Oracle

connection = cx_Oracle.connect("cx_Oracle/dev@localhost/orclpdb")
cursor = connection.cursor()

try:
    cursor.execute("select 1 / 0 from dual")
except cx_Oracle.DatabaseError as exc:
    error, = exc.args
    print("Oracle-Error-Code:", error.code)
    print("Oracle-Error-Message:", error.message)