正确的代码改进

时间:2012-08-02 12:11:57

标签: mysql procedure

有人可以查看我的代码,因为我不知道MySQL中是否可以

set @max=concat('select max(length(CommentsId))from', table_name);
    prepare stmt from @max;
    execute stmt;

    set @max=concat('UPDATE', table_name, 'SET CommentsId= ',CommentsId * power(10, (@max - length(CommentsId))),' WHERE CommentsId= ', @CommentsId );
    prepare stmt from @max;
    execute stmt;

1 个答案:

答案 0 :(得分:0)

您需要在fromUPDATESET关键字之前或之后使用空格。

set @max=concat('select max(length(CommentsId)) from ', table_name);
prepare stmt from @max;
execute stmt;

set @max=concat('UPDATE ', table_name, ' SET CommentsId= ',CommentsId * power(10, (@max -   length(CommentsId))),' WHERE CommentsId= ', @CommentsId );
prepare stmt from @max;
execute stmt;