Oracle® C++ Call Interface Programmer's Guide 10g Release 1 (10.1) Part Number B10778-01 |
|
|
View PDF |
IntervalYM
supports the SQL92 datatype Year-Month Interval.
Leading field precision will be determined by number of decimal digits on input.
IntervalYM( const Environment *env, int year = 0, int month=0);
Table 10-18 Fields of IntervalYM Class
Field | Type | Description |
---|---|---|
year |
int |
Year component. Valid values are -10^9 through 10^9 . |
month |
int |
Month component. Valid values are -11 through 11 . |
The following code example demonstrates that the default constructor creates a NULL
value, and how you can assign a non NULL
value to a year-month interval and then perform operations on it:
Environment *env = Environment::createEnvironment(); // Create a NULL year-month interval IntervalYM ym if(ym.isNull()) cout << "\n ym is null"; // Assign a non-NULL value to ym Interval UM anotherYM(env, "10-30"); ym=anotherYM; // Now all operations on YM are valid int yr = ym.getYear();
The following code example demonstrates how to get the year-month interval column from a result set, add to the year-month interval by using the += operator, multiply by using the * operator, compare 2 year-month intervals, and convert a year-month interval to a string by using the toText
method:
//SELECT WARRANT_PERIOD from PRODUCT_INFORMATION //obtain result set resultset->next(); //get interval value from resultset IntervalYM ym1 = resultset->getIntervalYM(1); IntervalYM addWith(env, 10, 1); ym1 += addWith; //call += operator IntervalYM mulYm1 = ym1 * Number(env, 10); //call * operator if(ym1<mulYm1) //comparison . . string strym = ym1.toText(3); //3 is the leading field precision
Table 10-19 Summary of IntervalYM Methods
Method | Summary |
---|---|
IntervalYM() |
IntervalYM class constructor. |
operator*() |
Return an IntervalYM with the value represented by instring . |
getMonth() |
Return month interval value. |
getYear() |
Return year interval value. |
isNull() |
Check if the interval is NULL . |
operator*() |
Return the product of two IntervalYM values. |
operator*=() |
Multiplication assignment. |
operator=() |
Simple assignment. |
operator+() |
Check if a and b are equal. |
operator!=() |
Check if a and b are not equal. |
operator==() |
Return an interval with value ( a/b ) . |
operator/=() |
Division assignment. |
operator>() |
Check if a is greater than b . |
operator>=() |
Check if a is greater than or equal to b . |
operator<() |
Check if a is less than b . |
operator>() |
Check if a is less than or equal to b . |
operator+() |
Return an interval with value ( a - b ) . |
operator-= () |
Subtraction assignment. |
operator=() |
Return the sum of two IntervalYM values. |
operator+=() |
Addition assignment. |
getDay() |
Set the interval to the values specified. |
setName() |
Set the interval to NULL . |
operator=() |
Return the string representation of the interval. |
IntervalYM class constructor.
Syntax | Description |
---|---|
IntervalYM(); |
Constructs a NULL IntervalYM object. A NULL IntervalYM can be initialized by assignment or calling operator*() method. Methods that can be called on NULL IntervalYM objects are setName() and isNull(). |
IntervalDS( const IntervalYM &src); |
Constructs an IntervalYM object from val. |
Parameter | Description |
---|---|
scp |
The source that the IntervalYM object will be copied from. |
This method initializes the interval to the values in inpstr
. The string is interpreted using the nls parameters set in the environment.
The nls parameters are picked up from env
. If env
is NULL
, the nls parameters are picked up from the environment associated with the instance, if any.
void fromText( const string &inpStr, const string &nlsParam = "", const Environment *env = NULL);
Parameter | Description |
---|---|
inpStr |
Input string representing a year month interval of the form 'year-month.' |
nlsParam |
The nls parameters string. If nlsParam is specified, this determines the nls parameters to be used for the conversion. If nlsParam is not specified, the nls parameters are picked up from envp . |
env |
Environment whose nls parameters will be used. |
This method returns the month component of the interval.
int getMonth() const;
This method returns the year component of the interval.
int getYear() const;
This method tests whether the interval is NULL
. If the interval is NULL
then TRUE
is returned; otherwise, FALSE
is returned.
bool isNull() const;
This method multiplies the interval by a factor and returns the result.
const IntervalYM operator*( const IntervalDS &interval const Number &value);
Parameter | Description |
---|---|
interval |
Interval to be multiplied. |
val |
Value by which interval is to be multiplied. |
This method multiplies the interval by a specified value.
Syntax
IntervalYM& operator*=( const Number &val);
Parameter | Description |
---|---|
val |
Value to be multiplied. |
This method assigns the specified value to the interval.
const IntervalYM& operator=( const IntervalYM &val);
Parameter | Description |
---|---|
val |
Value to be assigned. |
This method compares the intervals specified. If the intervals are equal then TRUE
is returned; otherwise, FALSE
is returned. If either interval is NULL
then SQLException is thrown.
bool operator==( const IntervalYM &first, const IntervalYM &second);
Parameter | Description |
---|---|
first |
The first interval to be compared. |
second |
The second interval to be compared. |
This method compares the intervals specified. If the intervals are not equal then TRUE
is returned; otherwise, FALSE
is returned. If either interval is NULL
then SQLException is thrown.
bool operator!=( const IntervalYM &first, const IntervalYM &second);
Parameter | Description |
---|---|
first |
The first interval to be compared. |
second |
The second interval to be compared. |
This method returns the result of dividing the interval by a factor.
const IntervalYM operator/( const IntervalYM ÷nd, const Number &factor);
Parameter | Description |
---|---|
dividend |
The interval to be divided. |
factor |
Value by which interval is to be divided. |
This method divides the interval by a factor.
IntervalYM& operator/=( const Number &val);
Parameter | Description |
---|---|
val |
A day second interval. |
This method compares the intervals specified. If the first interval is greater than the second interval then TRUE
is returned; otherwise, FALSE
is returned. If either interval is NULL
then SQLException is thrown.
bool operator>( const IntervalYM &first, const IntervalYM &second);
Parameter | Description |
---|---|
first |
The first interval to be compared. |
second |
The second interval to be compared. |
This method compares the intervals specified. If the first interval is greater than or equal to the second interval then TRUE
is returned; otherwise, FALSE
is returned. If either interval is NULL
then SQLException is thrown.
bool operator>=( const IntervalYM &first, const IntervalYM &second);
Parameter | Description |
---|---|
first |
The first interval to be compared. |
second |
The second interval to be compared. |
This method compares the intervals specified. If the first interval is less than the second interval then TRUE
is returned; otherwise, FALSE
is returned. If either interval is NULL
then SQLException is thrown.
bool operator<( const IntervalYM &first, const IntervalYM &second);
Parameter | Description |
---|---|
first |
The first interval to be compared. |
second |
The second interval to be compared. |
This method compares the intervals specified. If the first interval is less than or equal to the second interval then TRUE
is returned; otherwise, FALSE
is returned. If either interval is NULL
then SQLException is thrown
bool operator<=( const IntervalYM &first, const IntervalYM &second);
Parameter | Description |
---|---|
first |
The first interval to be compared. |
second |
The second interval to be compared. |
This method returns the difference between the intervals specified.
const IntervalYM operator-( const IntervalYM &first, const IntervalYM &second);
Parameter | Description |
---|---|
first |
The first interval to be compared. |
second |
The second interval to be compared. |
-=
()This method computes the difference between itself and another interval.
IntervalYM& operator-=( const IntervalYM &val);
Parameter | Description |
---|---|
val |
A day second interval. |
This method returns the sum of the intervals specified.
const IntervalYM operator+( const IntervalYM &first, const IntervalYM &second);
Parameter | Description |
---|---|
first |
The first interval to be compared. |
second |
The second interval to be compared. |
This method assigns the sum of IntervalYM
and val
to IntervalYM
.
IntervalYM& operator+=( const IntervalYM &val);
Parameter | Description |
---|---|
val |
A day second interval. |
This method sets the interval to the values specified.
void set( int year, int month);
Parameter | Description |
---|---|
year |
Year component. Valid values are -10^9 through 10^9 . |
month |
Month component. Valid values are -11 through 11 . |
This method sets the interval to NULL
.
void setNull();
This method returns the string representation of the interval.
string toText( unsigned int lfPrec, const string &nlsParam = "") const;
Parameter | Description |
---|---|
lfPrec |
Leading field precision. |
nlsParam |
The nls parameters string. If nlsParam is specified, this determines the nls parameters to be used for the conversion. If nlsParam is not specified, the nls parameters are picked up from envp . |