Hello I write mysql query:
CREATE PROCEDURE simple6() BEGIN SET @sql_text = concat("SELECT endtime INTO @coins_id FROM coins where id_coins = 'bitcoin'"); PREPARE stmt FROM @sql_text; EXECUTE stmt; if @coins_id = 0 then SET @sql_text2=concat("INSERT INTO coins (name) VALUES ('new_coins')"); PREPARE stmt2 FROM @sql_text2; EXECUTE stmt2; DEALLOCATE PREPARE stmt2; else SET @sql_text3= concat("UPDATE coins SET name = 'xxx2' WHERE id_name = 'bitcoin'"); PREPARE stmt3 FROM @sql_text3; EXECUTE stmt3; DEALLOCATE PREPARE stmt3; end if; DEALLOCATE PREPARE stmt; END
I used this answer link. But something is wrong, because I have error:
#1064 – Something is wrong in your syntax next to ” in line 4
I try write instruction if to my table coins
:
When isset the record id_name = bitcoin
query must update
name
, but when does not exist id_name = bitcoin
in my table now query must insert
new record with name = new_coins
.