开发者

Can I lock tables in an IF statement (or a stored proc) in MySQL?

This (from body of a stored proc) is throwing a syntax error:

  IF (name = in_name)
          SET out_id开发者_开发技巧 = temp;
  ELSE
          LOCK TABLE People WRITE;
          INSERT INTO People (Name)
          VALUES (in_name);
          UNLOCK TABLE;
          SELECT LAST_INSERT_ID() INTO out_id 
  END IF

do I have to lock any tables I need at the start of the SP?


THEN is missing: IF (name = in_name) THEN

But why do you want to lock the table? In this example it doesn't make sense at all, it will just kill overall performance because nobody else can do anything with the table. And the lock doesn't add anything. I don't see the point, but maybe you didn't tell us everything. ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜