clear markdown compare help best fiddles feedback dbanow.uk a leap of faith?
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 1130824 fiddles created (16567 in the last week).

CREATE FUNCTION GetStringCount(strValue VARCHAR(4000), charValue VARCHAR(4000)) RETURNS INTEGER DETERMINISTIC NO SQL BEGIN RETURN IFNULL((CHAR_LENGTH(strValue) - CHAR_LENGTH(REPLACE(strValue, charValue, ''))) / CHAR_LENGTH(charValue), 0); END
 hidden batch(es)


CREATE TABLE example ( col VARCHAR(4000) ); INSERT INTO example VALUES ('Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.'), ('At vero eos et accusam et justo duo dolores et ea rebum.'), ('Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.'), (NULL);
 hidden batch(es)


SELECT GetStringCount('Hello', 'l'); SELECT GetStringCount('This costs 5$.', '$'); SELECT GetStringCount('This costs 5€.', '€');
GetStringCount('Hello', 'l')
2
GetStringCount('This costs 5$.', '$')
1
GetStringCount('This costs 5€.', '€')
1
 hidden batch(es)


SELECT *, GetStringCount(col, 'a') FROM example;
col GetStringCount(col, 'a')
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. 11
At vero eos et accusam et justo duo dolores et ea rebum. 3
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. 8
0
 hidden batch(es)


CREATE FUNCTION GetStringCountB(strValue TEXT, charValue TEXT) RETURNS INTEGER DETERMINISTIC NO SQL BEGIN RETURN IFNULL(FLOOR((LENGTH(strValue) - LENGTH(REPLACE(strValue, charValue, ''))) / LENGTH(charValue)), 0); END
 hidden batch(es)


SELECT GetStringCountB('Hello', 'l'); SELECT GetStringCountB('This costs 5$.', '$'); SELECT GetStringCountB('This costs 5€.', '€');
GetStringCountB('Hello', 'l')
2
GetStringCountB('This costs 5$.', '$')
1
GetStringCountB('This costs 5€.', '€')
1
 hidden batch(es)


SELECT *, GetStringCountB(col, 'a') FROM example;
col GetStringCountB(col, 'a')
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. 11
At vero eos et accusam et justo duo dolores et ea rebum. 3
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. 8
0
 hidden batch(es)