Oracle® Objects for OLE C++ Class Library Developer's Guide 10g Release 1 (10.1) Part Number B10119-01 |
|
Applies To
Description
This method returns the object's value as a double.
Usage
operator double() const
Remarks
This method hands the value of the object back to the caller as a double. If the object's current value is not a double, the method attempts to convert the value. This can fail., resulting in a return of the value 0.0.
Return Value
The value of the field as a double; 0.0 on failure.
Example
Sum all the salaries of employees:
// open the employee database
ODatabase odb("ExampleDB", "scott", "tiger");
// open a dynaset on the employee's table
ODynaset odyn(odb, "select sal, comm from employees");
// get a field on the salary for speed
OField salf = odyn.GetField("sal");
/*
By using the = operator in the declaration of salf we are invoking the copy constructor. It is copying the temporary object that is returned by the GetField method.
*/
// sum the salaries
double sumsal = 0.0;
odyn.MoveFirst();
while (!odyn.IsEOF())
{
sumsal += (double) salf;
odyn.MoveNext();
}
// of course, we could have done the same thing (faster) with:
ODatabase odb("ExampleDB", "scott", "tiger");
ODynaset odyn(odb, "select sum(sal) from employees");
odyn.GetFieldValue(0, &sumsal);
// the server is good at that kind of bulk calculation