counting segments of string by delimiter
authorRogan Hamby <rhamby@equinoxinitiative.org>
Fri, 7 Feb 2020 14:41:16 +0000 (09:41 -0500)
committerRogan Hamby <rhamby@equinoxinitiative.org>
Fri, 7 Feb 2020 14:41:16 +0000 (09:41 -0500)
sql/koha/general_functions.sql

index 83f2c4c..6998171 100644 (file)
@@ -16,4 +16,16 @@ CREATE FUNCTION
 $
 DELIMITER ;
 
-
+DROP FUNCTION IF EXISTS string_segment_count;
+DELIMITER $
+CREATE FUNCTION 
+   string_segment_count(s TEXT, del VARCHAR(10))
+   RETURNS TEXT
+   DETERMINISTIC
+    BEGIN
+        DECLARE n INT ;
+        SET n = LENGTH(s) - LENGTH(REPLACE(s, del, '')) + 1;
+        RETURN n;
+    END
+$
+DELIMITER ;