Deepak,
following is a VERY basic example of C UDF for print():
in file prt.c:

#include <stdio.h>
#include <sqludf.h>
#include <sqlca.h>
#include <sqlda.h>
#ifdef __cplusplus
extern "C"
#endif
void SQL_API_FN print (                                                 
   char *str,
   char *out,
   short *outnull,                      /* output NULL indicator */
   char *sqlstate,                      /* SQL STATE */
   char *funcname,                      /* function name */
   char *specname,                      /* specific function name */
   char *mesgtext) {                    /* message text insert */
        strcpy (out, str);
}

then exec bldrtn -- script provided by IBM.  Once you've compiled it you
should check that all *so* obj. are being resolved correctly.  For example
this script will not work for Sol.8.  Issue ldd prt (if you've compiled
prt.c) and you should see that all *.so.* links are resolved.  If not than
you'll have to modify bldrtn script and add -RPathName
where PathName=location of *.so.* objects not found.  Modify EXTRA_LFLAG
line and recompile.
Providing you were able to compile this UDF without any errs you should
copy/move it ~/sqllib/function dir.  After that just issue:

CREATE FUNCTION print (varchar(255))
RETURNS varchar(255)
NOT FENCED
DETERMINISTIC
NO SQL 
NO EXTERNAL ACTION
LANGUAGE C
PARAMETER STYLE DB2SQL
EXTERNAL NAME 'prt!print';

Note that file name in ~/sqllib/function dir should be identical to the one
in first part of EXTERNAL NAME parameter and second part should be the entry
point (exactly as coded) in source file.

Once all has been compiled and setup you should be able to issue something
like:

select print('this is a test') from sysibm.sysdummy1

and it should return string 'this is a test'...



For more info you can refer to manual.

Regards,




-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] 
Sent: Sunday, January 12, 2003 7:30 AM
To: [EMAIL PROTECTED]
Subject: [DB2EUG] Writing UDF in C or JAVA


Hi Experts,

We re using version 7.1 of DB2 on AIX .

We need some UDF for our application.
As It will become very complex in SQL Language.
Can anyone tell me how to write UDF in Programming Language C or JAVA ?????

Thanx & Rgds
Deepak Bansal


********* The information contained in this message is legally privileged
and confidential information intended only for the use of the addressed
individual or entity indicated in this message (or responsible for delivery
of the message to such person). It must not be read, copied, disclosed,
distributed or used by any person other than the addressee. Unauthorised
use, disclosure or copying is strictly prohibited and may be unlawful.
Opinions, conclusions and other information on this message that do not
relate to the official business of any of the constituent companies of the
TATA CONSULTANCY SERVICES shall be understood as neither given nor endorsed
by the Group. If you have received this message in error, you should
destroy this message and kindly notify the sender by e-mail.   Thank you.
*********

-
:::  When replying to the list, please use 'Reply-All' and make sure
:::  a copy goes to the list ([EMAIL PROTECTED]).
***  To unsubscribe, send 'unsubscribe' to [EMAIL PROTECTED]
***  For more information, check http://www.db2eug.uni.cc
-
:::  When replying to the list, please use 'Reply-All' and make sure
:::  a copy goes to the list ([EMAIL PROTECTED]).
***  To unsubscribe, send 'unsubscribe' to [EMAIL PROTECTED]
***  For more information, check http://www.db2eug.uni.cc

Reply via email to