Simple IF Statement in MySQL isn't working -



Simple IF Statement in MySQL isn't working -

i have table columns id , name.

start transaction; update test set name='test' id=1; select row_count() @affected_rows; if (@affected_rows > 0) commit; else rollback; end if

it seems returning error

you have error in sql syntax; check manual corresponds mysql server version right syntax utilize near 'if (affected_rows > 0) commit' @ line 1 0 secs

currently running mysql 5.6.22

first, if command flow look allowed in programming blocks -- stored procedures, triggers, , functions.

second, logic doesn't create sense. if no rows affected, there no need rollback transaction.

to point out documentation:

the if statement stored programs implements basic conditional construct.

the term "stored programs" means programming block. don't confuse if mysql function if(), can used in query.

mysql

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -