From 57538f92486509faec4ae9b7f1f34c6c552d872c Mon Sep 17 00:00:00 2001 From: Rogan Hamby Date: Fri, 7 Feb 2020 09:37:14 -0500 Subject: [PATCH] adding mariadb/mysql functions file starting with split_string --- sql/koha/general_functions.sql | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-) create mode 100644 sql/koha/general_functions.sql diff --git a/sql/koha/general_functions.sql b/sql/koha/general_functions.sql new file mode 100644 index 0000000..83f2c4c --- /dev/null +++ b/sql/koha/general_functions.sql @@ -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 ; + + -- 1.7.2.5