Subject | Re: [firebird-support] counting number of occurances of a sub string in a field |
---|---|
Author | Ivan Prenosil |
Post date | 2003-07-05T14:11:53Z |
From: "Rajesh Punjabi" <solutions@...>
CREATE TABLE tab ( id INTEGER, b BLOB SUB_TYPE TEXT);
CREATE PROCEDURE proc (id INTEGER, str VARCHAR(100))
RETURNS (num INTEGER)
AS
DECLARE VARIABLE tmp VARCHAR(32000);
BEGIN
tmp = '%' || :str || '%';
num = 0;
WHILE ( EXISTS(SELECT * FROM tab WHERE id=:id AND b LIKE :tmp) ) DO BEGIN
num = num+1;
tmp = tmp || str || '%';
END
END
INSERT INTO tab(id,b) VALUES (1, 'AbcAbcAbcwwwAbcwwwAbc');
EXECUTE PROCEDURE proc 1, 'Abc';
-> 5
Ivan
> Is there a direct way in sql to count the number of occurances of aIf you can use SP and blob is not segmented try:
> substring inside a field (memo) using fb 1.0.2 without using UDF (user
> defined functions)
CREATE TABLE tab ( id INTEGER, b BLOB SUB_TYPE TEXT);
CREATE PROCEDURE proc (id INTEGER, str VARCHAR(100))
RETURNS (num INTEGER)
AS
DECLARE VARIABLE tmp VARCHAR(32000);
BEGIN
tmp = '%' || :str || '%';
num = 0;
WHILE ( EXISTS(SELECT * FROM tab WHERE id=:id AND b LIKE :tmp) ) DO BEGIN
num = num+1;
tmp = tmp || str || '%';
END
END
INSERT INTO tab(id,b) VALUES (1, 'AbcAbcAbcwwwAbcwwwAbc');
EXECUTE PROCEDURE proc 1, 'Abc';
-> 5
Ivan