Created
October 7, 2019 09:55
-
-
Save kolserdav/40e661d76703b2023a3046c87556a7d8 to your computer and use it in GitHub Desktop.
Drop procedure
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
DROP PROCEDURE IF EXISTS update_or_insert; | |
| |
DELIMITER $$ | |
CREATE PROCEDURE update_or_insert(name VARCHAR(80), email VARCHAR(50)) | |
| |
BEGIN | |
| |
DECLARE totalOrder INT DEFAULT 0; | |
DECLARE id INT DEFAULT 0; | |
SELECT COUNT(*) | |
INTO totalOrder | |
FROM `contacts` | |
WHERE `contacts`.`email` LIKE email; | |
IF totalOrder = 1 THEN | |
SELECT `contacts`.`id` INTO id FROM `contacts` WHERE `contacts`.`email` LIKE email AND `contacts`.`name` LIKE name; | |
IF id = 0 THEN | |
UPDATE `contacts` SET `contacts`.`note` = CONCAT('Старое ФИО: ', `contacts`.`name`), `contacts`.`name` = name | |
WHERE `contacts`.`email` = email; | |
ELSE | |
SELECT 'Идентичное имя'; | |
END IF; | |
ELSEIF totalOrder > 1 THEN | |
SELECT 'pass'; | |
ELSE | |
INSERT INTO `contacts` (`name`, `email`) | |
VALUES(name, email); | |
END IF; | |
| |
END $$ | |
DELIMITER ; | |
| |
call update_or_insert('Новое ФИО Тестового', '[email protected]'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment