Subject | [firebird-support] Stored Proc to act like the string.Copy method in Delphi |
---|---|
Author | Martin Dew |
Post date | 2005-07-05T12:10:25Z |
Can anyone help me with the following, I have a real problem at site
where a udf is leaking memory, and I would like to replace the functions
of it by using a stored procedure instead, this basically involves
passing in a string, a start index and an end index, I want to return a
string with the characters found from startindex to the endindex
Ie.
DECLARE VARIABLE subStr VARCHAR(1024);
subStr = Execute procedure '123456789', 1, 5;
substr would now contain '12345'
I have the starts of the proc, but have no idea how to iterate through
the provided string to be able to pick out a character each time. Can
anyone help me ?
CREATE PROCEDURE F_COPY (
STR VarChar(1024),
STARTINDEX Integer,
ENDINDEX Integer)
returns (
COPYSTRING VarChar(1024))
AS
DECLARE VARIABLE Tmp VARCHAR(1024);
DECLARE VARIABLE Pos INTEGER;
BEGIN
IF (Str IS NULL) THEN BEGIN
CopyString = '';
EXIT;
END
IF (StartIndex <= EndIndex) THEN BEGIN
CopyString = '';
EXIT;
END
Tmp = '';
Pos = 0;
WHILE (pos <= EndIndex) DO BEGIN
Pos = Pos + 1;
END
END
[Non-text portions of this message have been removed]
where a udf is leaking memory, and I would like to replace the functions
of it by using a stored procedure instead, this basically involves
passing in a string, a start index and an end index, I want to return a
string with the characters found from startindex to the endindex
Ie.
DECLARE VARIABLE subStr VARCHAR(1024);
subStr = Execute procedure '123456789', 1, 5;
substr would now contain '12345'
I have the starts of the proc, but have no idea how to iterate through
the provided string to be able to pick out a character each time. Can
anyone help me ?
CREATE PROCEDURE F_COPY (
STR VarChar(1024),
STARTINDEX Integer,
ENDINDEX Integer)
returns (
COPYSTRING VarChar(1024))
AS
DECLARE VARIABLE Tmp VARCHAR(1024);
DECLARE VARIABLE Pos INTEGER;
BEGIN
IF (Str IS NULL) THEN BEGIN
CopyString = '';
EXIT;
END
IF (StartIndex <= EndIndex) THEN BEGIN
CopyString = '';
EXIT;
END
Tmp = '';
Pos = 0;
WHILE (pos <= EndIndex) DO BEGIN
Pos = Pos + 1;
END
END
[Non-text portions of this message have been removed]