Hi,
Thanks! This is now implemented in the trunk and will be included in the
next version of H2 (released in about a week).
Regards,
Thomas
On Saturday, March 10, 2012, Vinod wrote:
> Following is the custom implementation I added:
> -------------------------------------------------
> public static String customSubStrXX(String...str) throws
> SQLException {
> // In Oracle/PLSQL, the substr functions allows you to extract a
> substring from a string.
> // The syntax for the substr function is:
> // substr( string, start_position, [ length ] )
> //
> // string is the source string.
> // start_position is the position for extraction. The first
> position in the string is always 1.
> // length is optional. It is the number of characters to extract.
> If this parameter is omitted, substr will return the entire string.
> //
> // Note:
> // If start_position is 0, then substr treats start_position as 1
> (ie: the first position in the string).
> // If start_position is a positive number, then substr starts
> from the beginning of the string.
> // If start_position is a negative number, then substr starts
> from the end of the string and counts backwards.
> // If length is a negative number, then substr will return a NULL
> value.
>
> String actualStr = str[0];
> String strStartPos = str[1];
> int start_position = Integer.parseInt(strStartPos);
>
> if(start_position < 0) {
> start_position = actualStr.length() + start_position + 1;
> }
>
> int length = -1;
> boolean lengthProvided = false;
> if(str.length == 3) {
> String strLength = str[2];
> length = Integer.parseInt(strLength);
> lengthProvided = true;
>
> if(length < 0) {
> return null;
> }
> }
>
> if(lengthProvided) {
> int end_position = start_position-1 + length;
> return actualStr.substring(start_position-1, end_position);
> } else {
> return actualStr.substring(start_position-1);
> }
> }
> -------------------------------------------------
>
> On Mar 8, 12:09 am, Vinod <[email protected] <javascript:;>> wrote:
> > Thanks, fixing substr will be a good idea.
> > Also negative number in substr works with Oracle.
> >
> > On Mar 6, 3:00 pm, Thomas Mueller
> > <[email protected]<javascript:;>
> >
> > wrote:
> >
> >
> >
> >
> >
> >
> >
> > > Hi,
> >
> > > Is there a way to register the new implementation with the same name
> >
> > > > substr ?
> >
> > > No. I think it would be a source of trouble if we would allow to
> overwrite
> > > library methods.
> >
> > > Instead, SUBSTR should be fixed if there is a bug. It seems only MySQL
> > > returns "Net" (the end of the input string) when using -3. All other
> > > databases either throw an exception, or return an empty string. In the
> next
> > > release, H2 will work like MySQL in this case.
> >
> > > Regards,
> > > Thomas
>
> --
> You received this message because you are subscribed to the Google Groups
> "H2 Database" group.
> To post to this group, send email to
> [email protected]<javascript:;>
> .
> To unsubscribe from this group, send email to
> [email protected] <javascript:;>.
> For more options, visit this group at
> http://groups.google.com/group/h2-database?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en.