If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Informix > Split Variable

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-24-09, 16:07
dicipulofer dicipulofer is offline
Registered User
 
Join Date: Oct 2007
Posts: 55
Split Variable

Hello.

How I do split in SPL ?

my variavel: "abc - def"

I want split in two variable using the separator "-"

var1 = abc
var2 = def

There are one way in spl to do this ??

Yours
Fernando.
Reply With Quote
  #2 (permalink)  
Old 07-25-09, 17:58
Tyveleyn Tyveleyn is offline
Registered User
 
Join Date: Aug 2006
Location: The Netherlands
Posts: 248
Hi, try this one...
Code:
CREATE FUNCTION splitvar(sep VARCHAR(255), str VARCHAR(255))
    RETURNING VARCHAR(255), VARCHAR(255);

    DEFINE i        SMALLINT;
    DEFINE j        SMALLINT;
    DEFINE len1     SMALLINT;
    DEFINE len2     SMALLINT;

    LET len1 = length(replace(sep, ' ', '@'));
    LET len2 = length(str);
    IF len1 > 0 AND len2 >= len1 THEN
        FOR i IN (1 TO len2)
            IF substr(sep, 1, 1) = substr(str, i, 1) THEN
                LET j = 2;
                IF len1 > 1 THEN
                    IF len1 - 1 > len2 - i THEN
                        RETURN '', '';
                    END IF
                    WHILE j <= len1
                        IF substr(sep, j, 1) != substr(str, i + j - 1, 1) THEN
                            EXIT WHILE;
                        END IF
                        LET j = j + 1;
                    END WHILE
                END IF
                IF j > len1 THEN
                    RETURN substr(str, 1, i - 1), substr(str, i + len1);
                END IF
            END IF
        END FOR
    END IF
    RETURN '', '';

END FUNCTION;
The used built-in functions are available from IDS 7.x on I believe.

Regards,
Hans

Last edited by Tyveleyn; 07-25-09 at 18:03.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On