[EMAIL PROTECTED] wrote:

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?

That's what happens:

ij> values replace('banana', 'an', 'ul');
1
--------------------------------------------------------------------------------------------------------------------------------
bulula

1 row selected

Why should it map to java char?

My intention was use java.lang.String.replace(CharSequence, CharSequence) (since 1.5), it would then work with a string of 1 or more characters. If instead you want to use java.lang.String.replace(char, char), I guess you could just replace strings by chars, and varchars by chars where it is needed and it would work, but I have not tried it.

Best regards,

Fernanda

Reply via email to