db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Knut Anders Hatlen <Knut.Hat...@Sun.COM>
Subject Re: NVL function implementation
Date Tue, 09 Mar 2010 15:47:11 GMT
Hardie82 <thomas.hartthaler@yahoo.de> writes:

> Hi,
> I want to implement the NVL-function for my derby-db to use sql-statement
> once written for an informix-db. Therefor I began to write a function class
> with methods like the following code:
>   public static String nvl(String arg1, String arg2)
>   {
>     if(arg1 == null)
>       return arg2;
>     return arg1;
>   }
> I also create a function in sql:
> CREATE FUNCTION NVL(arg1 VARCHAR(100), arg2 VARCCHAR(100)) returns
> VARCHAR(100) language java 
> external name 'mypackage.testdb.DerbyCustomFunctions.nvl' parameter style 
> java no sql;
> That works fine for statements with varchar-argument and length 100. But
> what about other data-types like INTEGER or DATE? Have I to implement
> methods for all data-type combination or is there a better way? Something
> like a data-type converter for derby? I thought to get informations for
> implementation from the nullif-function but can't find it in the derby-code.

You could use the COALESCE function defined in the SQL standard. It does
more or less the same thing as NVL. See here:

Knut Anders

View raw message