更新临时表问题的查询 - mysql

时间:2013-08-08 09:32:19

标签: mysql temp

更新查询不会将值更新到mysql中的临时表中。

DECLARE _defaultDateTime DATETIME;
DECLARE _resourceTypeId CHAR(36);
DECLARE _billedUsageHrs DECIMAL(15,6);
DECLARE _unbilledusageHrs DECIMAL(15,6);
DECLARE _billedCost DECIMAL(15,6);
DECLARE _unBilledCost DECIMAL(15,6);
DECLARE _resourceIdentifier CHAR(36);

DROP TABLE IF EXISTS _usageTable;

CREATE TEMPORARY TABLE _usageTable(resourceinstanceId CHAR(36),billedusageinHrs DECIMAL(15,6), billedusageCost DECIMAL(15,6),                       unBilledusageinHrs DECIMAL(15,6), unbilledusageCost DECIMAL(15,6)) ENGINE=MEMORY;


UPDATE  _usageTable SET resourceinstanceId = 'a17b5e49-000c-11e3-8bfa-842b2bac06e5' WHERE 1 = 1;  

SELECT resourceinstanceId, billedusageinHrs, billedusageCost, unBilledusageinHrs, unbilledusageCost FROM _usageTable; 

上述存储过程返回空行

1 个答案:

答案 0 :(得分:0)

CREATE TEMPORARY TABLE _usageTable(resourceinstanceId CHAR(36),
                                   billedusageinHrs DECIMAL(15,6), 
                                   billedusageCost DECIMAL(15,6),
                                   unBilledusageinHrs DECIMAL(15,6), 
                                   unbilledusageCost DECIMAL(15,6)) ENGINE=MEMORY;


UPDATE  _usageTable SET resourceinstanceId = 'a17b5e49-000c-11e3-8bfa-842b2bac06e5' WHERE 1 = 1;  

UPDATE将更新现有的行。

据我所见,您刚刚创建了表格。所以它是空的。只需更新 no 行。

也许您正在寻找INSERT而不是UPDATE?或者你的例子可能没有强调真正的问题?