db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oyvind.Bakk...@Sun.COM
Subject Re: Characters replacement function
Date Wed, 02 Nov 2005 13:44:01 GMT
Fernanda Pizzorno wrote:
> Hello,
> 
> Have you tried to create a user defined function for replace? You can do 
> that using the CREATE FUNCTION statement 
> (http://db.apache.org/derby/docs/10.1/ref/rrefcreatefunctionstatement.html). 
> I have tried creating a very simple java method that does the replace 
> and it seems to work fine.
> 
> Here is what I tried:
> 
> 1. Java method
>    public static String replace (String orgStr, String oldStr, String 
> newStr) {
>        return orgStr.replace(oldStr, newStr);
>    }
> 
> 2. User defined function
>    CREATE FUNCTION REPLACE(orgStr VARCHAR(50), oldStr VARCHAR(50), 
> newStr VARCHAR(50)) RETURNS VARCHAR(50)
>    PARAMETER STYLE JAVA NO SQL LANGUAGE JAVA
>    EXTERNAL NAME 'StringReplaceTest.replace';
> 
> 3. Test
>    ij> values replace('fernanda', 'a', 'e');
>    1
>    
> --------------------------------------------------------------------------------------------------------------------------------

> 
>    fernende

What happens if you execute "values replace('banana', 'an', 'ul')"? How 
does VARCHAR(50) map to a java char?

-- 
Oyvind Bakksjo
Sun Microsystems, Database Technology Group
Trondheim, Norway
http://weblogs.java.net/blog/bakksjo/

Mime
View raw message