表的类型为:MyISAM在存储过程中好像无法锁表.提示:LOCK is not allowed in stored procedures 在调用存储过程前锁表,提示:was not locked with LOCK TABLES 
请问有什么办法可以解决吗?

解决方案 »

  1.   

    在SP中不能用LOCK
    用别名方法试试,MYSQL示例
    mysql> LOCK TABLE t WRITE, t AS t1 WRITE;
    mysql> INSERT INTO t SELECT * FROM t;
    ERROR 1100: Table 't' was not locked with LOCK TABLES
    mysql> INSERT INTO t SELECT * FROM t AS t1;
      

  2.   

    lock table tablename write;
    call procedurename();//存储过程-读取数据
    unlock table;我在mysql中输入这3行就提示was not locked with LOCK TABLES  
    我要是单独使用"call procedurename();//存储过程-读取数据"可以.
    +上lock就不行了?
      

  3.   

     procedurename() 的代码是什么? 贴出来,这样别人可以模拟你的错误。
      

  4.   

    根本没有你所说的问题!mysql> create table t1 (id int primary key, c int);
    Query OK, 0 rows affected (0.08 sec)mysql> insert into t1 values (1,1),(2,2);
    Query OK, 2 rows affected (0.01 sec)
    Records: 2  Duplicates: 0  Warnings: 0mysql> select * from t1;
    +----+------+
    | id | c    |
    +----+------+
    |  1 |    1 |
    |  2 |    2 |
    +----+------+
    2 rows in set (0.00 sec)mysql>
    mysql> create procedure p1()
        ->  update t1 set c=1 where id=2;
    Query OK, 0 rows affected (0.14 sec)mysql> lock tables t1 WRITE;
    Query OK, 0 rows affected (0.00 sec)mysql> call p1();
    Query OK, 1 row affected (0.23 sec)mysql> UNLOCK TABLES;
    Query OK, 0 rows affected (0.00 sec)mysql> select * from t1;
    +----+------+
    | id | c    |
    +----+------+
    |  1 |    1 |
    |  2 |    1 |
    +----+------+
    2 rows in set (0.00 sec)mysql>