I can not execute query like: and I dont know why:
IF(NOT EXISTS(SELECT accountId FROM test_account WHERE content = '123')) THEN
INSERT INTO test_account (content) VALUES ('123');
END IF;
SELECT accountId FROM test_account WHERE content = '123' LIMIT 1;
Error received:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF(NOT EXISTS(SELECT accountId FROM test_account WHERE content = '123')) THEN INSE' at line 1
Edit:
I tried to write procedure first:
CREATE FUNCTION getTestAccount(var_c VARCHAR(20)) RETURNS INT
BEGIN
IF NOT EXISTS(SELECT accountId FROM test_account WHERE content = var_c)
THEN
INSERT INTO test_account (content) VALUES (var_c);
END IF;
RETURN (SELECT accountId FROM test_account WHERE content = var_c LIMIT 1);
END;
I tried with THEN
and without...
Can not even query something simple:
CREATE FUNCTION getVar(var INT) RETURNS INT
BEGIN
RETURN var;
END;