Oracle Call Interface Programmer's Guide
Release 8.1.5

A67846-01

Library

Product

Contents

Index

Prev Next

17
OCI Datatype Mapping and Manipulation Functions

This chapter describes the OCI datatype mapping and manipulation functions, which is Oracle's external C Language interface to Oracle predefined types. The following sections are included in this chapter:

Introduction

This chapter describes the OCI datatype mapping and manipulation functions in detail.

See Also: For more information about the functions listed in this chapter, refer to Chapter 11, "Object-Relational Datatypes".

The Function Syntax

The entries for each function contain the following information:

Purpose

A brief statement of the purpose of the function.

Syntax

A code snippet showing the syntax for calling the function, including the ordering and types of the parameters.

Comments

Detailed information about the function if available. This may include restrictions on the use of the function, or other information that might be useful when using the function in an application.

Parameters

A description of each of the function's parameters. This includes the parameter's mode. The mode of a parameter has three possible values, as described below:

Mode   Description  

IN  

A parameter that passes data to Oracle  

OUT  

A parameter that receives data from Oracle on this or a subsequent call  

IN/OUT  

A parameter that passes data on the call and receives data on the return from this or a subsequent call.  

Returns

A description of what value is returned by the function if the function returns something other than the standard return codes listed in Table 17-1, "Function Return Values".

Related Functions

A list of related functions.

Datatype Mapping and Manipulation Function Return Values

The OCI datatype mapping and manipulation functions typically return one of the following values:

Table 17-1 Function Return Values
Return Value  Meaning 

OCI_SUCCESS  

The operation succeeded  

OCI_ERROR  

The operation failed. The specific error can be retrieved by calling OCIErrorGet() on the error handle passed to the function.  

OCI_INVALID_HANDLE  

The environment or error handle passed to the function is NULL.  

Function-specific return information follows the description of each function in this chapter. For more information about return codes and error handling, see the section "Error Handling".

Functions Returning Other Values

Some functions return values other than those listed in Table 17-1. When using these function be sure to take into account that they return a value directly from the function call, rather than through an OUT parameter.

Server Roundtrips for Datatype Mapping and Manipulation Functions

For a table showing the number of server roundtrips required for individual OCI datatype mapping and manipulation functions, refer to Appendix C, "OCI Function Server Roundtrips".

Examples

For more information about these functions, including some code examples, refer to Chapter 11, "Object-Relational Datatypes".

OCI Collection and Iterator Functions

This section describes the Collection and Iterator functions.

Table 17-2 OCI Collection and Iterator Functions Quick Reference
Function/Page  Purpose 

OCICollAppend()  

Collection append element  

OCICollAssign()  

Assign collection  

OCICollAssignElem()  

Collection assign element  

OCICollGetElem()  

Get pointer to an element  

OCICollIsLocator()  

Indicates whether a collection is locator-based or not  

OCICollMax()  

Return maximum number of elements in collection  

OCICollSetUpdateStatus()  

Set the update status of a collection  

OCICollSize()  

Get current size of collection (in number of elements)  

OCICollTrim()  

Trim elements from the collection  

OCIIterCreate()  

Create iterator to scan the varray elements  

OCIIterDelete()  

Delete iterator  

OCIIterGetCurrent()  

Get current collection element  

OCIIterInit()  

Initialize iterator to scan the given collection  

OCIIterNext()  

Get next collection element  

OCIIterPrev()  

Get previous collection element,  


OCICollAppend()

Purpose

Appends an element to the end of a collection.

Syntax

sword OCICollAppend ( OCIEnv              *env,
                      OCIError            *err,
                      CONST dvoid         *elem, 
                      CONST dvoid         *elemind,
                      OCIColl             *coll );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

elem (IN)

Pointer to the element which is appended to the end of the given collection.

elemind (IN) [optional]

Pointer to the element's null indicator information. If (elemind == NULL) then the null indicator information of the appended element will be set to non-null.

coll (IN/OUT)

Updated collection.

Comments

Appending an element is equivalent to increasing the size of the collection by 1 element and updating (deep-copying) the last element's data with the given element's data. Note that the pointer to the given element elem is not saved by this function, which means that elem is strictly an input parameter.

This function returns an error if the current size of the collection is equal to the max size (upper-bound) of the collection prior to appending the element. This function also returns an error if any of the input parameters is NULL.

Related Functions

OCIErrorGet()


OCICollAssign()

Purpose

Assigns (deep-copies) one collection to another.

Syntax

sword OCICollAssign ( OCIEnv              *env, 
                      OCIError            *err, 
                      CONST OCIColl       *rhs, 
                      OCIColl             *lhs );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

rhs (IN)

Right-hand side (source) collection to be assigned from.

lhs (OUT)

Left-hand side (target) collection to be assigned to.

Comments

Assigns rhs (source) to lhs (target). The lhs collection may be decreased or increased depending upon the size of rhs. If the lhs contains any elements then the elements will be deleted prior to the assignment. This function performs a deep copy. The memory for the elements comes from the object cache.

An error is returned if the element types of the lhs and rhs collections do not match. Also, an error is returned if the upper-bound of the lhs collection is less than the current number of elements in the rhs collection. An error is also returned if:

Related Functions

OCIErrorGet(), OCICollAssignElem()


OCICollAssignElem()

Purpose

Assigns the given element value elem to the element at coll[index].

Syntax

sword OCICollAssignElem ( OCIEnv           *env, 
                          OCIError         *err, 
                          sb4              index, 
                          CONST dvoid      *elem, 
                          CONST dvoid      *elemind, 
                          OCIColl          *coll );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

index (IN)

Index of the element whose is assigned to.

elem (IN)

Element which is assigned from (source element).

elemind (IN) [optional]

Pointer to the element's null indicator information; if (elemind == NULL) then the null indicator information of the assigned element will be set to non-null.

coll (IN/OUT)

Collection to be updated.

Comments

If the collection is of type nested table, the element at the given index may not exist, as in the case when an element has been deleted. In this case, the given element is inserted at index. Otherwise, the element at index is updated with the value of elem.

Note that the given element is deep-copied and elem is strictly an input parameter.

This function returns an error if any input parameter is NULL or if the given index is beyond the bounds of the given collection.

Related Functions

OCIErrorGet(), OCICollAssign()


OCICollGetElem()

Purpose

Gets a pointer to the element at the given index.

Syntax

sword OCICollGetElem ( OCIEnv           *env, 
                       OCIError         *err, 
                       CONST OCIColl    *coll, 
                       sb4              index, 
                       boolean          *exists, 
                       dvoid            **elem, 
                       dvoid            **elemind );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

coll (IN)

Pointer to the element in this collection is returned.

index (IN)

Index of the element whose pointer is returned.

exists (OUT)

Set to FALSE if the element at the specified index does not exist; otherwise, set to TRUE.

elem (OUT)

Address of the desired element is returned.

elemind (OUT) [optional]

Address of the null indicator information is returned. If (elemind == NULL), then the null indicator information will NOT be returned.

Comments

Gets the address of the element at the given position. Optionally this function also returns the address of the element's null indicator information.

The following table describes for each collection element type what the corresponding element pointer type is. The element pointer is returned with the elem parameter of OCICollGetElem().

Element Type   *elem is set to  

Oracle Number (OCINumber)  

OCINumber*  

Date (OCIDate)  

OCIDate*  

Variable-length string (OCIString*)  

OCIString**  

Variable-length raw (OCIRaw*)  

OCIRaw**  

object reference (OCIRef*)  

OCIRef**  

lob locator (OCILobLocator*)  

OCILobLocator**  

object type (such as person)  

person*  

The element pointer returned by OCICollGetElem() is in a form such that it can not only be used to access the element data but also is in a form that can be used as the target (left-hand-side) of an assignment statement.

For example, assume the user is iterating over the elements of a collection whose element type is object reference (OCIRef*). A call to OCICollGetElem() returns pointer to a reference handle (OCIRef**). After getting, the pointer to the collection element, the user may wish to modify it by assigning a new reference.

This can be accomplished via the ref assignment function as follows:

sword OCIRefAssign( OCIEnv       *env, 
                    OCIError     *err, 
                    CONST OCIRef *source, 
                    OCIRef       **target );

Note that the target parameter of OCIRefAssign() is of type OCIRef**. Hence OCICollGetElem() returns OCIRef**. If *target equals NULL, a new REF will be allocated by OCIRefAssign() and returned via the target parameter.

Similarly, if the collection element was of type string (OCIString*), OCICollGetElem() returns pointer to string handle (i.e. OCIString**). If a new string is assigned, via OCIStringAssign() or OCIStringAssignText() the type of the target must be OCIString **.

If the collection element is of type Oracle number, OCICollGetElem() returns OCINumber*. The prototype of OCINumberAssign() is:

sword OCINumberAssign(OCIError        *err, 
                      CONST OCINumber *from,
                      OCINumber       *to);

This function returns an error if any of the input parameters is NULL.

Related Functions

OCIErrorGet(), OCICollAssignElem()


OCICollIsLocator()

Purpose

Indicates whether a collection is locator-based or not.

Syntax

sword OCICollIsLocator ( OCIEnv *env, 
                         OCIError *err,
                         CONST OCIColl *coll, 
                         boolean *result ); 

Parameters

env (IN)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

coll (IN)

A collection item.

result (OUT)

Returns TRUE if the collection item is locator-based, FALSE otherwise.

Comments

This function tests to see whether or not a collection is locator-based. Returns TRUE in the result parameter if the collection item is locator-based, otherwise it returns FALSE.

Related Functions

OCIErrorGet()


OCICollMax()

Purpose

Gets the maximum size in number of elements of the given collection.

Syntax

sb4 OCICollMax ( OCIEnv           *env,
                 CONST OCIColl    *coll );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

coll (IN)

Collection whose number of elements is returned. coll must point to a valid collection descriptor.

Comments

Returns the maximum number of elements that the given collection can hold. A value of zero indicates that the collection has no upper bound.

Returns

The upper bound of the given collection.

Related Functions

OCIErrorGet(), OCICollSize()


OCICollSetUpdateStatus()

Purpose

Set the update status of a collection.

Syntax

sword OCICollSetUpdateStatus ( OCIEnv *env,
                               OCIError *err, 
                               OCIColl *coll,
                               ub1 status );

Parameters

env (IN)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

coll (IN)

The collection whose update-status is to be set.

status (IN)

The status of the collection:

Comments

This function sets the status of the collection to indicate whether it should be marked updated (dirty) or should be marked as not dirty.

Related Functions

OCIErrorGet()


OCICollSize()

Purpose

Gets the current size in number of elements of the given collection.

Syntax

sword OCICollSize ( OCIEnv           *env,
                    OCIError         *err,
                    CONST OCIColl    *coll 
                    sb4              *size );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

coll (IN)

Collection whose number of elements is returned. Must point to a valid collection descriptor.

size (OUT)

Current number of elements in the collection.

Comments

Returns the current number of elements in the given collection. For the case of nested table, this count will NOT be decremented upon deleting elements. So, this count includes any holes created by deleting elements. A trim operation (OCICollTrim()) will decrement the count by the number of trimmed elements. To get the count minus the deleted elements use OCITableSize().

The following pseudocode shows some examples:

OCICollSize(...); 
// assume 'size' returned is equal to 5
OCITableDelete(...); // delete one element
OCICollSize(...);
// 'size' returned is still 5

To get the count minus the deleted elements use OCITableSize(). Continuing the above example:

OCITableSize(...)
// 'size' returned is equal to 4

A trim operation (OCICollTrim()) decrements the count by the number of trimmed elements. Continuing the above example:

OCICollTrim(..,1..); // trim one element
OCICollSize(...);
// 'size' returned is equal to 4

This function returns an error if an error occurs during the loading of the collection into object cache or if any of the input parameters is null.

Related Functions

OCIErrorGet(), OCICollMax()


OCICollTrim()

Purpose

Trims the given number of elements from the end of the collection.

Syntax

sword OCICollTrim ( OCIEnv         *env, 
                    OCIError       *err, 
                    sb4            trim_num, 
                    OCIColl        *coll );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

trim_num (IN)

Number of elements to trim.

coll (IN/OUT)

This function removes (frees) trim_num elements from the end of coll.

Comments

The elements are removed from the end of the collection. An error is returned if trim_num is greater than the current size of the collection.

Related Functions

OCIErrorGet(), OCICollSize()


OCIIterCreate()

Purpose

Creates an iterator to scan the elements or the collection.

Syntax

sword OCIIterCreate ( OCIEnv               *env, 
                      OCIError             *err, 
                      CONST OCIColl        *coll, 
                      OCIIter              **itr );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

coll (IN)

Collection which will be scanned. For this release, valid collection types include varrays and nested tables.

itr (OUT)

Address to the allocated collection iterator is returned by this function.

Comments

The iterator is created in the object cache. The iterator is initialized to point to the beginning of the collection.

If OCIIterNext() is called immediately after creating the iterator then the first element of the collection is returned. If OCIIterPrev() is called immediately after creating the iterator then a "at beginning of collection" error is returned.

This function returns an error if any of the input parameters is NULL.

Related Functions

OCIErrorGet(), OCIIterDelete()


OCIIterDelete()

Purpose

Deletes a collection iterator.

Syntax

sword OCIIterDelete ( OCIEnv           *env, 
                      OCIError         *err, 
                      OCIIter          **itr );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

itr (IN/OUT)

The allocated collection iterator which is destroyed and set to NULL prior to returning.

Comments

Deletes an iterator which was previously created by a call to OCIIterCreate().

This function returns an error if any of the input parameters is null.

Related Functions

OCIErrorGet(), OCIIterCreate()


OCIIterGetCurrent()

Purpose

Gets a pointer to the current iterator collection element.

Syntax

sword OCIIterGetCurrent ( OCIEnv            *env, 
                          OCIError          *err, 
                          CONST OCIIter     *itr, 
                          dvoid             **elem, 
                          dvoid             **elemind );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

itr (IN)

Iterator which points to the current element.

elem (OUT)

Address of the element pointed by the iterator is returned.

elemind (OUT) [optional]

Address of the element's NULL indicator information is returned; if (elem_ind == NULL) then the NULL indicator information will not be returned.

Comments

Returns pointer to the current iterator collection element and its corresponding NULL information. This function returns an error if any input parameter is NULL.

Related Functions

OCIErrorGet(), OCIIterNext(), OCIIterPrev()


OCIIterInit()

Purpose

Initializes an iterator to scan a collection.

Syntax

sword OCIIterInit ( OCIEnv              *env, 
                    OCIError            *err, 
                    CONST OCIColl       *coll, 
                    OCIIter             *itr );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

coll (IN)

Collection which will be scanned. For release 8i, valid collection types include varrays and nested tables.

itr (IN/OUT)

Pointer to an allocated collection iterator.

Comments

Initializes given iterator to point to the beginning of given collection. Returns an error if any input parameter is NULL. This function can be used to:

Related Functions

OCIErrorGet()


OCIIterNext()

Purpose

Gets a pointer to the next iterator collection element.

Syntax

sword OCIIterNext ( OCIEnv            *env,
                    OCIError          *err, 
                    OCIIter           *itr, 
                    dvoid             **elem,
                    dvoid             **elemind,
                    boolean           *eoc);

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

itr (IN/OUT)

Iterator is updated to point to the next element.

elem (OUT)

After updating the iterator to point to the next element, address of the element is returned.

elemind (OUT) [optional]

Address of the element's NULL indicator information is returned; if (elem_ind == NULL) then the NULL indicator information will not be returned.

eoc (OUT)

TRUE if iterator is at End of Collection (i.e. next element does not exist); otherwise, FALSE.

Comments

This function returns a pointer to the next iterator collection element and its corresponding NULL information. It also updates the iterator to point to the next element.

If the iterator is pointing to the last element of the collection prior to executing this function, then calling this function will set the eoc flag to TRUE. The iterator will be left unchanged in that case.

This function returns an error if any input parameter is NULL.

Related Functions

OCIErrorGet(), OCIIterGetCurrent(), OCIIterPrev()


OCIIterPrev()

Purpose

Gets a pointer to the previous iterator collection element.

Syntax

sword OCIIterPrev ( OCIEnv            *env, 
                    OCIError          *err, 
                    OCIIter           *itr, 
                    dvoid             **elem, 
                    dvoid             **elemind,
                    boolean           *boc );

Parameters

env (IN/OUT)

The OCI environment handle initialized in object mode. See the description of OCIEnvCreate() and OCIInitialize() in Chapter 15 for more information.

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

itr (IN/OUT)

Iterator which is updated to point to the previous element.

elem (OUT)

Address of the previous element; returned after the iterator is updated to point to it.

elemind (OUT) [optional]

Address of the element's NULL indicator; if (elem_ind == NULL) then the NULL indicator will not be returned.

boc (OUT)

TRUE if iterator is at beginning of collection (i.e. previous element does not exist); otherwise, FALSE.

Comments

This function returns a pointer to the previous iterator collection element and its corresponding NULL information. The iterator is updated to point to the previous element.

If the iterator is pointing to the first element of the collection prior to executing this function, then calling this function will set boc to TRUE. The iterator is left unchanged in that case.

This function returns an error if any input parameter is NULL.

Related Functions

OCIErrorGet(), OCIIterGetCurrent(), OCIIterNext()

OCI Date Functions

This section describes the OCI Date functions.

Table 17-3 OCI Date Functions Quick Reference
Function/Page  Purpose 

OCIDateAddDays()  

Add or subtract days  

OCIDateAddMonths()  

Add or subtract months  

OCIDateAssign()  

Assign date  

OCIDateCheck()  

Check if the given date is valid  

OCIDateCompare()  

Compare dates  

OCIDateDaysBetween()  

Get number of days between two dates  

OCIDateFromText()  

Convert string to date  

OCIDateGetDate()  

Get the date portion of a date  

OCIDateGetTime()  

Get the time portion of a date  

OCIDateLastDay()  

Get date of last day of month  

OCIDateNextDay()  

get date of next day  

OCIDateSetDate()  

Set the date portion of a date  

OCIDateSetTime()  

Set the time portion of a date  

OCIDateSysDate()  

Get current system date and time  

OCIDateToText()  

Convert date to String  

OCIDateZoneToZone()  

Convert date from one time zone to another zone  


OCIDateAddDays()

Purpose

Adds or subtracts days from a given date.

Syntax

sword OCIDateAddDays ( OCIError          *err,
                       CONST OCIDate     *date, 
                       sb4               num_days,
                       OCIDate           *result );

Parameters

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

date (IN)

The given date from which to add or subtract.

num_days (IN)

Number of days to be added or subtracted. A negative value is subtracted.

result (IN/OUT)

Result of adding days to, or subtracting days from, date.

Comments

This function returns and error if an invalid date is passed to it.

Related Functions

OCIErrorGet(), OCIDateAddMonths()


OCIDateAddMonths()

Purpose

Adds or subtracts months from a given date.

Syntax

sword OCIDateAddMonths ( OCIError            *err,
                         CONST OCIDate       *date,
                         sb4                 num_months,
                         OCIDate             *result );

Parameters

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

date (IN)

The given date from which to add or subtract.

num_months (IN)

Number of months to be added or subtracted. A negative value is subtracted.

result (IN/OUT)

Result of adding days to, or subtracting days from, date.

Comments

If the input date is the last day of a month, then the appropriate adjustments are made to ensure that the output date is also the last day of the month. For example, Feb. 28 + 1 month = March 31, and November 303 months = August 31. Otherwise the result date has the same day component as date.

This function returns an error if invalid date is passed to it.

Related Functions

OCIErrorGet(), OCIDateAddDays()


OCIDateAssign()

Purpose

Performs a date assignment.

Syntax

sword OCIDateAssign ( OCIError         *err,
                      CONST OCIDate    *from, 
                      OCIDate          *to );

Parameters

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

from (IN)

Date to be assigned.

to (OUT)

Target of assignment.

Comments

This function assigns a value from one OCIDate variable to another.

Related Functions

OCIErrorGet(), OCIDateCheck()


OCIDateCheck()

Purpose

Checks if the given date is valid.

Syntax

sword OCIDateCheck ( OCIError          *err,
                     CONST OCIDate     *date, 
                     uword             *valid );

Parameters

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

date (IN)

Date to be checked

valid (OUT)

Returns zero for a valid date. Otherwise, the OR'ed combination of all error bits specified as follows:

Macro Name   Bit Number   Error  

OCI_DATE_INVALID_DAY  

0x1  

Bad day  

OCI_DATE_DAY_BELOW_VALID  

0x2  

Bad day low/high bit (1=low)  

OCI_DATE_INVALID_MONTH  

0x4  

Bad month  

OCI_DATE_MONTH_BELOW_VALID  

0x8  

Bad month low/high bit (1=low)  

OCI_DATE_INVALID_YEAR  

0x10  

Bad year  

OCI_DATE_YEAR_BELOW_VALID  

0x20  

Bad year low/high bit (1=low)  

OCI_DATE_INVALID_HOUR  

0x40  

Bad hour  

OCI_DATE_HOUR_BELOW_VALID  

0x80  

Bad hour low/high bit (1=low)  

OCI_DATE_INVALID_MINUTE  

0x100  

Bad minute  

OCI_DATE_MINUTE_BELOW_VALID  

0x200  

Bad minute low/high bit (1=low)  

OCI_DATE_INVALID_SECOND  

0x400  

Bad second  

OCI_DATE_SECOND_BELOW_VALID  

0x800  

Bad second low/high bit (1=low)  

OCI_DATE_DAY_MISSING_FROM_1582  

0x1000  

Day is one of those "missing" from 1582  

OCI_DATE_YEAR_ZERO  

0x2000  

Year may not equal zero  

OCI_DATE_INVALID_FORMAT  

0x8000  

Bad date format input  

For example, if the date passed in was 2/0/1990 25:61:10 in (month/day/year hours:minutes:seconds format), the error returned would be:

OCI_DATE_INVALID_DAY | OCI_DATE_DAY_BELOW_VALID | OCI_DATE_INVALID_HOUR | 
   OCI_DATE_INVALID_MINUTE.

Comments

This function returns an error if date or valid pointer is NULL.

Related Functions

OCIErrorGet(), OCIDateCompare()


OCIDateCompare()

Purpose

Compares two dates.

Syntax

sword OCIDateCompare ( OCIError           *err, 
                       CONST OCIDate      *date1, 
                       CONST OCIDate      *date2,
                       sword              *result );

Parameters

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

date1, date2 (IN)

Dates to be compared.

result (OUT)

Comparison result:

Comparison result   Output in result parameter  

date1 < date2  

-1  

date1 = date2  

0  

date1 > date2  

1  

Comments

This function returns and error if an invalid date is passed to it.

Related Functions

OCIErrorGet(), OCIDateCheck()


OCIDateDaysBetween()

Purpose

Gets the number of days between two dates.

Syntax

sword OCIDateDaysBetween ( OCIError            *err, 
                           CONST OCIDate       *date1, 
                           CONST OCIDate       *date2, 
                           sb4                 *num_days );

Parameters

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

date1 (IN)

Input date.

date2 (IN)

Input date.

num_days (OUT)

Number of days between date1 and date2.

Comments

When the number of days between date1 and date2 is computed, the time is ignored.

This function returns an error if invalid date is passed to it.

Related Functions

OCIErrorGet(), OCIDateCheck()


OCIDateFromText()

Purpose

Converts a character string to a date type according to the specified format.

Syntax

sword OCIDateFromText ( OCIError           *err,
                        CONST text         *date_str, 
                        ub4                d_str_length, 
                        CONST text         *fmt,
                        ub1                fmt_length, 
                        CONST text         *lang_name,
                        ub4                lang_length, 
                        OCIDate            *date );

Parameters

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

date_str (IN)

Input string to be converted to Oracle date.

d_str_length (IN)

Size of the input string, if the length is -1 then date_str is treated as a NULL terminated string.

fmt (IN)

Conversion format. If fmt is a null pointer, then the string is expected to be in 'DD-MON-YY' format.

fmt_length (IN)

Length of the fmt parameter.

lang_name (IN)

Language in which the names and abbreviations of days and months are specified. If lang_name is a NULL string, (text *) 0, then the default language of the session is used.

lang_length (IN)

Length of the lang_name parameter.

date (OUT)

Given string converted to date.

Comments

Refer to the TO_DATE conversion function described in Chapter 3 of the Oracle8i SQL Reference for a description of format and NLS arguments.

This function returns an error if it receives an invalid format, language, or input string.

Related Functions

OCIErrorGet(), OCIDateToText()


OCIDateGetDate()

Purpose

Get the year, month, and day stored in an Oracle date.

Syntax

void OCIDateGetDate ( CONST OCIDate    *date,
                      sb2              *year,
                      ub1              *month, 
                      ub1              *day ); 

Parameters

date (IN)

Oracle date whose year, month, day data is retrieved.

year (OUT)

Year value returned.

month (OUT)

Month value returned.

day (OUT)

Day value returned.

Comments

None.

Related Functions

OCIDateSetDate(), OCIDateGetTime()


OCIDateGetTime()

Purpose

Gets the time stored in an Oracle date.

Syntax

void OCIDateGetTime ( CONST OCIDate    *date,
                      ub1              *hour,
                      ub1              *min, 
                      ub1              *sec );

Parameters

date (IN)

Oracle date whose time data is retrieved.

hour (OUT)

Hour value returned.

min (OUT)

Minute value returned.

sec (OUT)

Second value returned.

Comments

Returns the time information returned in the form: hour, minute and seconds.

Related Functions

OCIDateSetTime(), OCIDateGetDate()


OCIDateLastDay()

Purpose

Gets the date of the last day of the month in a specified date.

Syntax

sword OCIDateLastDay ( OCIError            *err,
                       CONST OCIDate       *date,
                       OCIDate             *last_day );

Parameters

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

date (IN)

Input date.

last_day (OUT)

Last day of the month in date.

Comments

This function returns an error if invalid date is passed to it.

Related Functions

OCIErrorGet(), OCIDateGetDate()


OCIDateNextDay()

Purpose

Gets the date of next day of the week, after a given date.

Syntax

sword OCIDateNextDay ( OCIError            *err,
                       CONST OCIDate       *date,
                       CONST text          *day, 
                       ub4                 day_length,
                       OCIDate             *next_day );

Parameters

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

date (IN)

Returned date should be later than this date.

day (IN)

First day of week named by this is returned.

day_length (IN)

Length in bytes of string day.

next_day (OUT)

First day of the week named by day later than date.

Comments

Returns the date of the first day of the week named by day that is later than date.

Example

Get the date of the next Monday after April 18, 1996 (a Thursday).

OCIDateNextDay(&err, '18-APR-96', 'MONDAY', strlen('MONDAY'), &next_day)

OCIDateNextDay() returns '22-APR-96'.

This function returns and error if an invalid date or day is passed to it.

Related Functions

OCIErrorGet(), OCIDateGetDate()


OCIDateSetDate()

Purpose

Set the values in an Oracle date.

Syntax

void OCIDateSetDate ( OCIDate    *date, 
                      sb2        year, 
                      ub1        month, 
                      ub1        day );

Parameters

date (OUT)

Oracle date whose time data is set.

year (IN)

Year value to be set.

month (IN)

Month value to be set.

day (IN)

Day value to be set.

Comments

None.

Related Functions

OCIDateGetDate()


OCIDateSetTime()

Purpose

Sets the time information in an Oracle date.

Syntax

void OCIDateSetTime ( OCIDate    *date,
                      ub1        hour, 
                      ub1        min, 
                      ub1        sec ); 

Parameters

date (OUT)

Oracle date whose time data is set.

hour (IN)

Hour value to be set.

min (IN)

Minute value to be set.

sec (IN)

Second value to be set.

Comments

None.

Related Functions

OCIDateGetTime()


OCIDateSysDate()

Purpose

Gets the current system date and time.

Syntax

sword OCIDateSysDate ( OCIError       *err,
                       OCIDate        *sys_date );

Parameters

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

sys_date (OUT)

Current system date and time.

Comments

None.

Related Functions

OCIErrorGet()


OCIDateToText()

Purpose

Converts a date type to a character string.

Syntax

sword OCIDateToText ( OCIError           *err, 
                      CONST OCIDate      *date, 
                      CONST text         *fmt, 
                      ub1                fmt_length, 
                      CONST text         *lang_name,
                      ub4                lang_length, 
                      ub4                *buf_size, 
                      text               *buf );

Parameters

err (IN/OUT)

The OCI error handle. If there is an error, it is recorded in err and this function returns OCI_ERROR. Obtain diagnostic information by calling OCIErrorGet().

date (IN)

Oracle date to be converted.

fmt (IN)

Conversion format, if NULL string pointer, (text *) 0, then the date is converted to a character string in the default date format, DD-MON-YY.

fmt_length (IN)

Length of the fmt parameter.

lang_name (IN)

Specifies the language in which names and abbreviations of months and days are returned; default language of session is used if lang_name is NULL ((text *) 0).

lang_length (IN)

Length of the lang_name parameter.

buf_size (IN/OUT)
buf (OUT)

Buffer into which the converted string is placed.