How to use Decimal(15,2)
Teradata Teradata Discussion Forums Teradata.com Discussion Forum
Visit Teradata.com
Home       Guidelines    Member List
Welcome Guest ( Login | Register )
        


This online forum is for user-to-user discussions of Teradata products, and is not an official customer support channel for Teradata. If you require direct assistance, please contact Teradata support.


How to use Decimal(15,2) Expand / Collapse
Author
Message
Posted 3/11/2006 5:59:59 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 11/28/2008 7:01:15 AM
Posts: 8, Visits: 12
Can someone give me an example for a very simple UDF. I just want to have the C-code and the definition of the function.

Name: UDF_Multiplyby2()
Input: Decimal(15,2)
Output: Decimal(15,2)

To do: Multiply Input by 2, that's all.

Teradata gives me always a stack error.
I'm using DECIMAL8 as in- and output.

Thank's a lot,
Koen.


AXA Belgium
Post #3718
Posted 3/16/2006 6:59:21 PM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 10/7/2008 12:54:51 PM
Posts: 116, Visits: 20
you have to increase the output lenght. leave the input as is decimal (15,2)
so the largest number you can provide is
9999999999999.99

set the output: Decimal(18,2) {I guess 18 is the max that is allowed}

and when you do the multiplication use the cast function

output = cast(input * 2 as decimal(18,2))

this should work.

please let me know if it does not work.




Feroz Shaik
Post #3752
Posted 3/17/2006 12:12:13 AM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: PAC and SFT Members
Last Login: Today @ 6:11:07 PM
Posts: 331, Visits: 533
Note that though the logic inside the function body may be "simple", you can't code the prototype as a "simple C function". In other words,
DECIMAL8 *udf_m_2(DECIMAL8 *in_val){...}
will not work.

If you register the function as
CREATE FUNCTION UDF_Multiplyby2(InVal DECIMAL(15,2)) RETURNS DECIMAL(15,2)
... PARAMETER STYLE TD_GENERAL ... EXTERNAL NAME ... !udf_m_2'
Then the function prototype would be something like
void *udf_m_2(DECIMAL8 *in_val, DECIMAL8 *result, char sqlstate[6])

or for PARAMETER STYLE SQL
void *udf_m_2(DECIMAL8 *in_val, DECIMAL8 *result,
int *in_val_NULL_indicator, int *result_NULL_indicator, char sqlstate[6],
SQL_TEXT extname[129],
SQL_TEXT specific_name[129],
SQL_TEXT error_message[257])

Then note that DECIMAL8 is a struct with a 32-bit unsigned and 32-bit signed integer. You may want to convert that to a native 64-bit integer type.
Post #3753
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 ( 0 guests, 0 members, 0 anonymous members )
No members currently viewing this topic.


All times are GMT -5:00, Time now is 11:49pm

Powered By InstantForum.NET v4.1.4 © 2008
Execution: 0.203. 10 queries. Compression Disabled.