如何在MySQL过程中创建唯一的临时表?
我在程序中创建临时表,但总是收到错误“表已存在”。
然后我尝试创建一个随机名称以避免冲突,但我对如何执行 SQL 字符串了解不够
SET @tbName = CONCAT('temp', random_id);
PREPARE stmt1 FROM 'CREATE TEMPORARY TABLE ? (`FIELDNAME` float NOT NULL);';
EXECUTE stmt1 using @tbName;
DEALLOCATE PREPARE stmt1;
上面的代码不起作用。为什么?如何纠正呢?
I was creating a temporary table in my procedure, but I always got an error "table already exists".
Then I tried to create a random name to avoid collision but I don't know enough about how to execute SQL strings
SET @tbName = CONCAT('temp', random_id);
PREPARE stmt1 FROM 'CREATE TEMPORARY TABLE ? (`FIELDNAME` float NOT NULL);';
EXECUTE stmt1 using @tbName;
DEALLOCATE PREPARE stmt1;
The code above doesn't works. Why? How to correct it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 http://rpbouman.blogspot.com /2005/11/mysql-5-prepared-statement-syntax-and.html
from http://rpbouman.blogspot.com/2005/11/mysql-5-prepared-statement-syntax-and.html