Tuesday, March 16, 2010

CLR Functions

Any static function can be use as the body of the CRL function. (containing assembly should be already loaded)
In the following sample demonstrates how-to create a simple CLR function to add two numbers.

First create the static c# function,
public static int Add(int x, int y)
{
return x + y
}

Then create a SQL function that reference the static function createtd above,
CREATE FUNCTION add_num(x INT, y INT)
RETURNS INT
NO SQL
LANGUAGE DOTNET
EXTERNAL NAME 'EffiProz.CLFunctionSample.Add'

Now we can call add_num function as any regular SQL function. e.g:
SELECT add_num(3,4) FROM DUAL;

You can download the sample code with upcoming Effiproz Database 0.1RC from http://www.effiproz.com/samples/CLRFunctionSample.zip

0 comments:

Post a Comment