MIDRANGE dot COM Mailing List Archive

Home » MIDRANGE-L » December 2013

Re: SQL Reverse Function


On 19-Dec-2013 07:42 -0800, Gad Miron wrote:

Is there a SQL (scalar) function to reverse a string like in
Select name, reverse(name) from myFile
abc, cba

Easy enough to code one in just about any language and then issue a CREATE FUNCTION (external) to provide the interface to the executable to your SQL request [or write it directly in SQL; though probably not in a very efficient manner], but FWiW:

While REXX has a REVERSE scalar and can implement a SQL External Stored Procedure, there is no support for INOUT or OUT parameters with a REXX SP, so even though a SQL UDF could effect the CALL to a REXX performing the REVERSE [per lack of an ability for LANGUAGE REXX on an External User Defined Function], there is no direct ability to use its scalar.

The COBOL however does have a "REVERSE function" for which a module in a service program or a bound CBLLE program could externalize the capability to the SQL as a UDF:
IBM i 7.1 Information Center -> Programming -> Programming languages -> COBOL -> ILE COBOL Language Reference -> Procedure Division -> _Intrinsic Functions_

The REVERSE function returns a character string that is exactly the same length as the argument, whose characters are exactly the same as those specified in the argument, except that they are in reverse order.

FWiW there is an example of such a procedure here:
Author: Mercury December 17th, 2010, 11:03 AM
"I wrote a Cobol function using the Cobol Built-in FUNCTION REVERSE() many moons ago..."

Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2014 by MIDRANGE dot COM and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available here. If you have questions about this, please contact