Oracle® Call Interface Programmer's Guide 10g Release 1 (10.1) Part Number B10779-01 |
|
|
View PDF |
This section describes the statement functions.
This call associates an application request with a server.
sword OCIStmtExecute ( OCISvcCtx *svchp, OCIStmt *stmtp, OCIError *errhp, ub4 iters, ub4 rowoff, CONST OCISnapshot *snap_in, OCISnapshot *snap_out, ub4 mode );
Service context handle.
An statement handle. It defines the statement and the associated data to be executed at the server. It is invalid to pass in a statement handle that has bind of datatypes only supported in release 8.x or later when svchp
points to an Oracle7 server.
An error handle you can pass to OCIErrorGet()
for diagnostic information in the event of an error.
For non-SELECT
statements, the number of times this statement is executed is equal to iters
- rowoff
.
For SELECT
statements, if iters
is nonzero, then defines must have been done for the statement handle. The execution fetches iters
rows into these predefined buffers and prefetches more rows depending upon the prefetch row count. If you do not know how many rows the SELECT
statement will retrieve, set iters
to zero.
This function returns an error if iters
=0 for non-SELECT
statements.
The starting index from which the data in an array bind is relevant for this multiple row execution.
This parameter is optional. if supplied, must point to a snapshot descriptor of type OCI_DTYPE_SNAP. The contents of this descriptor must be obtained from the snap_out
parameter of a previous call. The descriptor is ignored if the SQL is not a SELECT
. This facility allows multiple service contexts to ORACLE to see the same consistent snapshot of the database's committed data. However, uncommitted data in one context is not visible to another context even using the same snapshot.
This parameter optional. if supplied, must point to a descriptor of type OCI_DTYPE_SNAP. This descriptor is filled in with an opaque representation which is the current ORACLE "system change number" suitable as a snap_in
input to a subsequent call to OCIStmtExecute()
. This descriptor should not be used longer than necessary in order to avoid "snapshot too old" errors.
The modes are:
OCIStmtExecute()
in this mode executes the statement. It also implicitly returns describe information about the select-list.OCIStmtExecute()
in this mode does not execute the statement, but it does return the select-list description. To maximize performance, it is recommended that applications execute the statement in default mode and use the implicit describe which accompanies the execution.The modes are not mutually exclusive and can be used together, except for OCI_STMT_SCROLLABLE_READONLY.
This function is used to execute a prepared SQL statement. Using an execute call, the application associates a request with a server.
If a SELECT
statement is executed, the description of the select-list is available implicitly as a response. This description is buffered on the client side for describes, fetches and define type conversions. Hence it is optimal to describe a select list only after an execute.
Also for SELECT
statements, some results are available implicitly. Rows will be received and buffered at the end of the execute. For queries with small row count, a prefetch causes memory to be released in the server if the end of fetch is reached, an optimization that may result in memory usage reduction. Set attribute call has been defined to set the number of rows to be prefetched for each result set.
For SELECT
statements, at the end of the execute, the statement handle implicitly maintains a reference to the service context on which it is executed. It is the user's responsibility to maintain the integrity of the service context. The implicit reference is maintained until the statement handle is freed or the fetch is cancelled or an end of fetch condition is reached.
Fetches rows from a query. Users are encouraged to use the new fetch call OCIStmtFetch2()
. This call is deprecated.
sword OCIStmtFetch ( OCIStmt *stmtp, OCIError *errhp, ub4 nrows, ub2 orientation, ub4 mode );
A statement (application request) handle.
An error handle you can pass to OCIErrorGet()
for diagnostic information in the event of an error.
Number of rows to be fetched from the current position.
Prior to release 9.0, the only acceptable value is OCI_FETCH_NEXT, which is also the default value.
Pass as OCI_DEFAULT.
The fetch call is a local call, if prefetched rows suffice. However, this is transparent to the application.
If LOB columns are being read, LOB locators are fetched for subsequent LOB operations to be performed on these locators. Prefetching is turned off if LONG
columns are involved.
This function can return OCI_NO_DATA on EOF and OCI_SUCCESS_WITH_INFO when one of the following errors occur:
NULL
fetch error occurredNULL
column in an aggregate functionIf you call OCIStmtFetch()
with the nrows
parameter set to 0, this cancels the cursor.
Use OCI_ATTR_ROWS_FETCHED to find the number of rows that were successfully fetched into the user's buffers in the last fetch call.
This fetches a row from the (scrollable) result set. You are encouraged to use this fetch call instead of the deprecated call OCIStmtFetch()
.
sword OCIStmtFetch2 ( OCIStmt *stmthp, OCIError *errhp, ub4 nrows, ub2 orientation, sb4 fetchOffset, ub4 mode );
This is the statement handle of the (scrollable) result set.
An error handle you can pass to OCIErrorGet()
for diagnostic information in event of an error.
Number of rows to be fetched from the current position.
The acceptable values are:
fetchOffset
parameter) in the result set using absolute positioning.fetchOffset
parameter) in the result set using relative positioning.The offset to be used with the orientation parameter for changing the current row position.
Pass in OCI_DEFAULT.
The fetch call works similarly to the OCIStmtFetch()
call with the addition of the fetchOffset
parameter. It can be used on any statement handle, whether it is scrollable or not. For a non-scrollable statement handle, the only acceptable value of orientation
is OCI_FETCH_NEXT, and the fetchOffset
parameter will be ignored.
For new applications you are encouraged to use this new call, OCIStmtFetch2()
.
A fetchOffset
with orientation
set to OCI_FETCH_RELATIVE is equivalent to all of the following:
fetchOffset
equal to 0,fetchOffset
equal to 1,fetchOffset
equal to -1.OCI_ATTR_ROW_COUNT contains the highest absolute row value that was fetched.
All other orientation modes besides OCI_FETCH_ABSOLUTE and OCI_FETCH_RELATIVE will ignore the fetchOffset
value.
This call can also be used to find out the number of rows in the result set by using OCI_FETCH_LAST, and then calling OCIAttrGet()
on OCI_ATTR_CURRENT_POSITION. But the response time of this call can be high.
The return codes are the same as for OCIStmtFetch()
, except that OER(1403) with return code OCI_NO_DATA will be returned every time a fetch on a scrollable statement handle (or execute) is made and not all rows requested by the application could be fetched.
If you call OCIStmtFetch2()
with the nrows
parameter set to 0, this cancels the cursor.
The scrollable statement handle will need to be explicitly cancelled (that is, fetch with 0 rows) or freed in order to release server-side resources for the scrollable cursor. A non-scrollable statement handle is implicitly cancelled on receiving the OER(1403).
Use OCI_ATTR_ROWS_FETCHED to find the number of rows that were successfully fetched into the user's buffers in the last fetch call.
See Also:
"Scrollable Cursors in OCI" for more information on this topic |
OCIStmtExecute(), OCIBindByPos()
Returns piece information for a piecewise operation.
sword OCIStmtGetPieceInfo( CONST OCIStmt *stmtp, OCIError *errhp, dvoid **hndlpp, ub4 *typep, ub1 *in_outp, ub4 *iterp, ub4 *idxp, ub1 *piecep );
The statement when executed returned OCI_NEED_DATA.
An error handle you can pass to OCIErrorGet()
for diagnostic information in the event of an error.
Returns a pointer to the bind or define handle of the bind or define whose runtime data is required or is being provided.
The type of the handle pointed to by hndlpp
: OCI_HTYPE_BIND (for a bind handle) or OCI_HTYPE_DEFINE (for a define handle).
Returns OCI_PARAM_IN if the data is required for an IN bind value. Returns OCI_PARAM_OUT if the data is available as an OUT bind variable or a define position value.
Returns the row number of a multiple row operation.
The index of an array element of a PL/SQL array bind operation.
Returns one of the following defined values OCI_ONE_PIECE, OCI_FIRST_PIECE, OCI_NEXT_PIECE and OCI_LAST_PIECE.
When an execute or fetch call returns OCI_NEED_DATA to get or return a dynamic bind or define value or piece, OCIStmtGetPieceInfo()
returns the relevant information: bind or define handle, iteration, index number and which piece.
See Also:
See the section "Runtime Data Allocation and Piecewise Operations in OCI" for more information about using |
OCIAttrGet(), OCIAttrSet(), OCIStmtExecute(), OCIStmtFetch(), OCIStmtSetPieceInfo()
This call prepares a SQL or PL/SQL statement for execution.
sword OCIStmtPrepare ( OCIStmt *stmtp, OCIError *errhp, CONST text *stmt, ub4 stmt_len, ub4 language, ub4 mode );
A statement handle associated with the statement to be executed. By default, it contains the encoding setting in the environment handle from which it is derived. A statement can be prepared in UTF-16 encoding only in a UTF-16 environment.
An error handle you can pass to OCIErrorGet()
for diagnostic information in the event of an error.
SQL or PL/SQL statement to be executed. Must be a NULL
-terminated string. That is, the ending character is a number of NULL bytes, depending on the encoding. The statement must be in the encoding specified by the charset
parameter of a previous call to OCIEnvNlsCreate()
.
Always cast the parameter to (text *)
. After a statement has been prepared in UTF-16, the character set for the bind and define buffers will default to UTF-16. The pointer to the text of the statement must be available as long as the statement is executed, or data is fetched from it.
Length of the statement in characters or in number of bytes, depending on the encoding. Must not be zero.
Specifies V7, or native syntax. Possible values are:
Similar to the mode
in the OCIEnvCreate()
call, but this one has higher priority because it can override the "naturally" inherited mode setting.
The only possible value is:
stmtp
uses whatever is specified by its parent environment handle.An OCI application uses this call to prepare a SQL or PL/SQL statement for execution. The OCIStmtPrepare()
call defines an application request.
The mode
parameter determines whether the statement content is encoded as UTF-16 or not. The statement length is in number of codepoints or in number of bytes, depending on the encoding.
While the statement handle inherits the encoding setting from the parent environment handle, the mode
for this call can also change the encoding setting for the statement handle itself.
Data values for this statement initialized in subsequent bind calls will be stored in a bind handle which use settings in this statement handle as default.
This call does not create an association between this statement handle and any particular server.
See Also:
See the section "Preparing Statements" for more information about using this call. |
OCIAttrGet(), OCIStmtExecute()
This call prepares a SQL or PL/SQL statement for execution. The user has the option of using the statement cache, if it has been enabled.
sword OCIStmtPrepare2 ( OCISvcCtx *svchp, OCIStmt **stmthp, OCIError *errhp, CONST OraText *stmttext, ub4 stmt_len, CONST OraText *key, ub4 keylen, ub4 language, ub4 mode );
The service context to be associated with the statement.
A pointer to the error handle for diagnostics.
Pointer to the statement handle returned.
The statement text. The semantics of the stmttext
are same as that of OCIStmtPrepare, i.e, the string should be NULL
-terminated.
The statement text length.
For statement caching only. The key to the returned statement in the cache. This can be used for future calls to OCIStmtPrepare2()
, in which case there is no need to pass in the statement text and related parameters. If the key is passed in, then the statement text and other parameters are ignored and the search is solely based on the key.
For statement caching only. The length of the key.
Specifies V7, or native syntax. Possible values are:
This function can be used with and without statement caching. This is determined at the time of connection or session pool creation. If caching is enabled for a session, then all statements in the session will have caching enabled, and if caching is not enabled, then all statements will not be cached.
The valid modes are:
NULL
. OCI_SUCCESS will be returned.stmthp
will be NULL
. OCI_ERROR will be returned.NULL
. OCI_SUCCESS_WITH_INFO will be returned, as the returned statement differs from the requested statement in that the tag is NULL
.Releases the statement handle obtained by a call to OCIStmtPrepare2()
.
sword OCIStmtRelease ( OCIStmt *stmthp, OCIError *errhp, CONST OraText *key, ub4 keylen, ub4 mode );
The statement handle returned by OCIStmtPrepare2()
The error handle used for diagnostics.
Only valid for statement caching. The key to be associated with the statement in the cache. This can be the key returned by OCIStmtPrepare2()
or can be a new key. If a NULL
key is passed in the statement will not be tagged.
Only valid for statement caching. The length of the key.
The valid modes are
Sets piece information for a piecewise operation.
sword OCIStmtSetPieceInfo ( dvoid *hndlp, ub4 type, OCIError *errhp, CONST dvoid *bufp, ub4 *alenp, ub1 piece, CONST dvoid *indp, ub2 *rcodep );
The bind/define handle.
Type of the handle.
An error handle you can pass to OCIErrorGet()
for diagnostic information in the event of an error.
A pointer to a storage containing the data value or the piece when it is an IN bind variable, otherwise bufp
is a pointer to storage for getting a piece or a value for OUT binds and define variables. For named datatypes or REF
s, a pointer to the object or REF
is returned.
The length of the piece or the value. Do not change this parameter between executions of the same SQL statement.
The piece parameter. Valid values:
This parameter is used for IN bind variables only.
Indicator. A pointer to a sb2
value or pointer to an indicator structure for named datatypes (SQLT_NTY) and REF
s (SQLT_REF), that is, *indp
is either an sb2
or a dvoid
* depending upon the datatype.
Return code.
When an execute call returns OCI_NEED_DATA to get a dynamic IN/OUT bind value or piece, OCIStmtSetPieceInfo()
sets the piece information: the buffer, the length, which piece is currently being processed, the indicator, and the return code for this column.
See Also:
For more information about using |
OCIAttrGet(), OCIAttrSet(), OCIStmtExecute(), OCIStmtFetch(), OCIStmtGetPieceInfo()