Create UDF

Connectivity

Create UDF

Hi All,

Can anybody tell me, How to create and execute the UDF with simple example.

Regards
Srikant
3 REPLIES
Teradata Employee

Re: Create UDF

Hello,

Following is the sample UDF code file, save it as "udfvarchartest.c":

#define SQL_TEXT Latin_Text
#include "sqltypes_td.h"

void udfvarchartest( VARCHAR_LATIN *var_in_varchar1, VARCHAR_LATIN *var_out_varchar1)
{
strcpy(var_out_varchar1, var_in_varchar1);
return;
}

Following is the code for its compilation save it as "udfvarchartest.btq":

.LOGON username/pass;

DATABASE db;

REPLACE FUNCTION udfvarchartest
(var1 VARCHAR(20))
RETURNS VARCHAR(20)
LANGUAGE C
NO SQL
EXTERNAL NAME 'CS!udfvarchartest!udfvarchartest.c!F!udfvarchartest'
PARAMETER STYLE TD_GENERAL;

.LOGOFF;

Place both the files in one folder e.g. c:\UDF and run bteq < udfvarchartest.btq

HTH!

Regards,

Adeel
Enthusiast

Re: Create UDF

I used this template today and it worked perfectly, thanks.

Re: Create UDF

Can some one provide me steps for creating a simple Java UDF function (without any SQL), and then use that function as a UDF in an update query?

For example, I want to write a Java function which reverses the Last name column in a Teradata table and then update the reversed value back to the table column.  For example if my java function is called 'reverse()', once it's compiled and stored in Teradata, I should be able to run a query as follows.

Update Employee set Lname = reverse(Lname) where dept = 'Marketing';