Subject | RE: [firebird-support] How to add empty space into between characters in string? |
---|---|
Author | Svein Erling Tysvær |
Post date | 2009-09-02T15:16:24Z |
What about
With Recursive CommaMe(WithComma, WithoutComma)
As
(select cast('' as VarChar(255)), 'ABCD'
from rdb$database
union all
select WithComma || ',' || substring(WithoutComma from 1 for 1),
substring(WithoutComma from 2 for 255)
from CommaMe
where WithoutComma > '')
select max(WithComma)
from CommaMe
Though looking at the SQL above, it might be simpler to use a stored procedure.
And I haven't tested whether the above SQL works (or contains syntax errors) or whether you could replace 'ABCD' with a parameter. The level of recursion is somewhat limited in Firebird (I don't remember how deep recursion can be), so don't expect it to work if you have strings with 30000 characters.
HTH,
Set
-----Original Message-----
From: firebird-support@yahoogroups.com [mailto:firebird-support@yahoogroups.com] On Behalf Of Le Phuc
Sent: 2. september 2009 16:53
To: firebird-support@yahoogroups.com
Subject: RE: [firebird-support] How to add empty space into between characters in string?
Thanks, but string’s length not fixed.
Mr. Lê Phúc
Hi,
select substring(yourfield from 1 for 1)||','||substring(yourfield from 2
for 1) from yourtable
Regards,
Anderson
With Recursive CommaMe(WithComma, WithoutComma)
As
(select cast('' as VarChar(255)), 'ABCD'
from rdb$database
union all
select WithComma || ',' || substring(WithoutComma from 1 for 1),
substring(WithoutComma from 2 for 255)
from CommaMe
where WithoutComma > '')
select max(WithComma)
from CommaMe
Though looking at the SQL above, it might be simpler to use a stored procedure.
And I haven't tested whether the above SQL works (or contains syntax errors) or whether you could replace 'ABCD' with a parameter. The level of recursion is somewhat limited in Firebird (I don't remember how deep recursion can be), so don't expect it to work if you have strings with 30000 characters.
HTH,
Set
-----Original Message-----
From: firebird-support@yahoogroups.com [mailto:firebird-support@yahoogroups.com] On Behalf Of Le Phuc
Sent: 2. september 2009 16:53
To: firebird-support@yahoogroups.com
Subject: RE: [firebird-support] How to add empty space into between characters in string?
Thanks, but string’s length not fixed.
Mr. Lê Phúc
Hi,
> Hi all, I use FB 2.1.3 RC2, I have a string(Ex: ABCD), I want to add anUse SUBSTRING , ex:
>empty space(or an character ‘,’) between each characters in string. Please
>send me what function or SQL code.
select substring(yourfield from 1 for 1)||','||substring(yourfield from 2
for 1) from yourtable
Regards,
Anderson