I have the following stored procedure in phpmyadmin using mysql:
CREATE DEFINER=`user`@`localhost` PROCEDURE `set_address`(IN `patient_street` VARCHAR(128), IN
`patient_city` VARCHAR(45), IN `patient_post_code` VARCHAR(45), IN `patient_state_or_province` VARCHAR(45), IN `patient_country` VARCHAR(45))
NOT DETERMINISTIC NO SQL SQL SECURITY
DEFINER
BEGIN
IF NOT EXISTS (SELECT a.address_id FROM address as a where a.street = patient_street and a.city = patient_city and a.post_code = patient_post_code and a.country = patient_country)
THEN
BEGIN
INSERT INTO address (street, city, post_code, state_or_province, country) VALUES (patient_street, patient_city, patient_post_code, patient_state_or_province, patient_country);
SELECT LAST_INSERT_ID();
END;
ELSE
BEGIN
SELECT a.address_id FROM address as a where a.street = patient_street and a.city = patient_city and a.post_code = patient_post_code and a.country = patient_country
END;
END IF;
END;
However, I got 2 errors in IF NOT EXISTS:
- Unrecognized keyword. (near IF NOT EXISTS)
- Unexpected token. (near()