In this post we show how to add the popular INITCAP function to GemFireXD or SQLFire.
1. Create a class with a public static method as shown below , this class method will do the INITCAP for us in SQL terms.
package pivotal.au.accelarator.gemfirexd.sql.functions; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.text.WordUtils; public class GemFireXdSqlFunctions { public static String initcap (String input) { return WordUtils.capitalizeFully(input); } }2. Add the class to the classpath of the distributed system.
3. Create a stored function called INITCAP to use the method defined at #1
CREATE FUNCTION INITCAP (data VARCHAR(32672)) RETURNS VARCHAR(32672) LANGUAGE JAVA EXTERNAL NAME 'pivotal.au.accelarator.gemfirexd.sql.functions.GemFireXdSqlFunctions.initcap' PARAMETER STYLE JAVA;4. Test as shown below.
sqlf> connect client 'localhost:1527'; sqlf> select initcap('pas APICELLA') from sysibm.sysdummy1; 1 -------------------------------------------------------------------------------------------------------------------------------- Pas Apicella 1 row selectedFor more information on Pivotal GemFireXD see the link below.
http://gopivotal.com/products/pivotal-hd