db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rick Hillegas <Richard.Hille...@Sun.COM>
Subject Re: NVL function implementation
Date Tue, 09 Mar 2010 15:46:35 GMT
Hello,

If you want to do this with a user-defined function, then you will need 
to declare a separate function for each datatype you need to handle.

You might be able to use a CASE expression for this problem. It's a 
little more verbose than using a function. Here is an example:

connect 'jdbc:derby:memory:derby;create=true';

create table t( a int, b int, c date, d date );
insert into t( b, d ) values ( 1, date('1994-02-23') );

select
   case when a is null then b else a end,
   case when c is null then d else c end
from t;

Hope this helps,
-Rick


Hardie82 wrote:
> 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.
>   


Mime
View raw message