blackDoggy wrote:

> Hello,
> 
> 
> It seems I have a problem :(( I can't get TRUNC function to 
> work expected.
> TRUNC only seems to work when the second parameter does not come from
> database (e.g. TRUNC(measurement, 2) works perfectly well). 
> If it's comes
> from a table, then it returns the original parameter instead 
> of truncated
> one.
> 
> I also tried to create a function, however, it does not work 
> as expected as
> well.
> 
> CREATE DBFUNCTION trunc_measurement (measurement FIXED(14,7), 
> precision_id
> INT) RETURNS NUMBER AS
> TRY
>     RETURN TRUNC(measurement, precision_id);
> CATCH
>     RETURN NULL;
> 
> Is there anything I could do to get it working? Or am I - as it usual
> happens :) - missing something?
> 
> Thanks,
> Andris
> 

As Andris wrote in another mail, the numeric result of the TRUNC-function is correct.
But the datatype is not as he expected it.

The datatype of the result is calculated during preparation of a statement/dbproc,
not during execution.
In the case of TRUNC(..., constant) the value of constant can be and is taken into
account to calculate the resulting datatype.
In case of TRUNC (..., column_or_dbproc_parameter) the value of this column/parameter
during EXECUTION_time is not known at preparation-time --> The maximum (not-trunced)
datatype is calculated.
In case of TRUNC(..., (SELECT...) ) the select will be DONE during execution time-->
the result is only known at execution time. And the single special case 
SELECT constant FROM DUAL (all other selects HAVE to be selected during execution time)
is not expected (because very ... strange) and therefore not handled differently to 
every other
select.

--> with TRUNC the result is correct even if the datatype is perhaps not the smallest 
possible
to hold the result.

Elke
SAP Labs Berlin

> 
> P.S.
> I am using MaxDB 7.5.05
> 
> 
> 
> 
> 
> 
> 
> -- 
> MaxDB Discussion Mailing List
> For list archives: http://lists.mysql.com/maxdb
> To unsubscribe:    
http://lists.mysql.com/[EMAIL PROTECTED]

-- 
MaxDB Discussion Mailing List
For list archives: http://lists.mysql.com/maxdb
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to