Created
July 27, 2023 08:27
-
-
Save RomanTuras/ae40f86b44ced76ff96eaecb407ca7e9 to your computer and use it in GitHub Desktop.
MySQL Replace cyrillic 'x' by lat 'x' when 'x' between numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Replace cyrillic 'x' by lat 'x' when 'x' between numbers | |
| DROP PROCEDURE IF EXISTS replace_char_product_name; | |
| DELIMITER $$ | |
| CREATE PROCEDURE replace_char_product_name() | |
| BEGIN | |
| DECLARE cursor_List_isdone BOOLEAN DEFAULT FALSE; | |
| DECLARE cur_product_id INT; | |
| DECLARE cur_name TEXT; | |
| DECLARE cur_finded TEXT; | |
| DECLARE cur_replaced TEXT; | |
| DECLARE cur_new_name TEXT; | |
| DECLARE cursor_List CURSOR FOR | |
| SELECT product_id, name, REGEXP_SUBSTR(name, '[0-9]х[0-9]') AS finded | |
| FROM oc_product_description | |
| WHERE name REGEXP '[0-9]х[0-9]' | |
| ; | |
| DECLARE CONTINUE HANDLER FOR NOT FOUND SET cursor_List_isdone = TRUE; | |
| OPEN cursor_List; | |
| loop_List: LOOP | |
| FETCH cursor_List INTO cur_product_id, cur_name, cur_finded; | |
| IF cursor_List_isdone THEN | |
| LEAVE loop_List; | |
| END IF; | |
| SET cur_replaced = REPLACE(cur_finded, 'х', 'x'); | |
| SET cur_new_name = REPLACE(cur_name, cur_finded, cur_replaced); | |
| UPDATE `oc_product_description` | |
| SET `name`=cur_new_name | |
| WHERE `product_id`=cur_product_id AND name LIKE cur_name; | |
| END LOOP loop_List; | |
| CLOSE cursor_List; | |
| END | |
| $$ | |
| DELIMITER ; | |
| CALL replace_char_product_name(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment