adding mariadb/mysql functions file starting with split_string
[migration-tools.git] / sql / koha / general_functions.sql
diff --git a/sql/koha/general_functions.sql b/sql/koha/general_functions.sql
new file mode 100644 (file)
index 0000000..83f2c4c
--- /dev/null
@@ -0,0 +1,19 @@
+DROP FUNCTION IF EXISTS split_string;
+DELIMITER $
+CREATE FUNCTION 
+   split_string (s TEXT, del VARCHAR(10), i INT)
+   RETURNS TEXT
+   DETERMINISTIC
+    BEGIN
+        DECLARE n INT ;
+        SET n = LENGTH(s) - LENGTH(REPLACE(s, del, '')) + 1;
+        IF i > n THEN
+            RETURN NULL ;
+        ELSE
+            RETURN SUBSTRING_INDEX(SUBSTRING_INDEX(s, del, i) , del , -1 ) ;        
+        END IF;
+    END
+$
+DELIMITER ;
+
+