<small id='2a7hE'></small><noframes id='2a7hE'>

        <tfoot id='2a7hE'></tfoot>
      1. <legend id='2a7hE'><style id='2a7hE'><dir id='2a7hE'><q id='2a7hE'></q></dir></style></legend>
          <bdo id='2a7hE'></bdo><ul id='2a7hE'></ul>
        <i id='2a7hE'><tr id='2a7hE'><dt id='2a7hE'><q id='2a7hE'><span id='2a7hE'><b id='2a7hE'><form id='2a7hE'><ins id='2a7hE'></ins><ul id='2a7hE'></ul><sub id='2a7hE'></sub></form><legend id='2a7hE'></legend><bdo id='2a7hE'><pre id='2a7hE'><center id='2a7hE'></center></pre></bdo></b><th id='2a7hE'></th></span></q></dt></tr></i><div id='2a7hE'><tfoot id='2a7hE'></tfoot><dl id='2a7hE'><fieldset id='2a7hE'></fieldset></dl></div>

      2. 更新变量的MYSQL存储过程为0

        时间:2023-10-26
              <bdo id='ab1lY'></bdo><ul id='ab1lY'></ul>

                  <tbody id='ab1lY'></tbody>

                  <i id='ab1lY'><tr id='ab1lY'><dt id='ab1lY'><q id='ab1lY'><span id='ab1lY'><b id='ab1lY'><form id='ab1lY'><ins id='ab1lY'></ins><ul id='ab1lY'></ul><sub id='ab1lY'></sub></form><legend id='ab1lY'></legend><bdo id='ab1lY'><pre id='ab1lY'><center id='ab1lY'></center></pre></bdo></b><th id='ab1lY'></th></span></q></dt></tr></i><div id='ab1lY'><tfoot id='ab1lY'></tfoot><dl id='ab1lY'><fieldset id='ab1lY'></fieldset></dl></div>

                • <legend id='ab1lY'><style id='ab1lY'><dir id='ab1lY'><q id='ab1lY'></q></dir></style></legend><tfoot id='ab1lY'></tfoot>

                  <small id='ab1lY'></small><noframes id='ab1lY'>

                  本文介绍了更新变量的MYSQL存储过程为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 MYSQL 数据库中有以下存储过程.存储过程得到 lon、lat 并且我正在对不同的数据库和表进行更新.

                  I have the following stored procedure in a MYSQL database. The stored procedure gets lon,lat and than I'm doing an update on a different database and table.

                  DROP PROCEDURE IF EXISTS annuals.updateSalesFlorida;
                  CREATE DEFINER=`dddd`@`%` PROCEDURE `updateSales`(propertyId int)
                  BEGIN
                  
                     DECLARE lat   FLOAT;
                      DECLARE lon FLOAT;
                  
                  
                    SELECT  SitusLongitude,SitusLatitude
                    INTO lon,lat
                    FROM annuals.florida
                    WHERE PropertyID=propertyId
                    LIMIT 1 FOR UPDATE;
                  
                    UPDATE sales.florida
                    SET
                      `SitusLongitude` = lon,
                      `SitusLatitude` = lat
                    WHERE PROPERTYUNIQUEID=propertyId;
                  
                  END;
                  

                  每次运行存储过程时,SitusLongitudeSitusLatitude 列都是 0.我知道之前选择的 SitusLongitudeSitusLatitude 在那里有实际值.出于某种原因,变量没有设置在纬度,经度.知道我做错了什么吗?

                  Every time I run the stored procedure the SitusLongitude and SitusLatitude columns are 0. I know for a fact that the previous selected SitusLongitude and SitusLatitude have actual values in there. For some reason the variables are not being set in lat,lon. Any idea what I'm dong wrong?

                  推荐答案

                  问题是过程参数与表中的列同名.当您在查询中引用 propertyid 时,它使用的是列,而不是参数.列名和变量名不区分大小写,因此您拼写其中一个 PropertyID 和另一个 propertyId 无关紧要.

                  The problem is that the procedure parameter has the same name as a column in the tables. When you refer to propertyid in the queries, it uses the column, not the parameter. Column and variable names are case-insensitive, so it doesn't matter that you spelled one of them PropertyID and the other propertyId.

                  为参数使用不同的名称,例如p_propertyId

                  Use a different name for the parameter, e.g. p_propertyId

                  此外,不需要两个查询,您可以使用 JOIN 将其合二为一.

                  Also, there's no need for two queries, you can do it in one with a JOIN.

                  UPDATE sales.florida AS s
                  CROSS JOIN (
                      SELECT *
                      FROM annuals.florida
                      WHERE propertyId = p_propertyId
                      LIMIT 1) AS a
                  SET s.SitusLongitude = a.SitusLongitude, s.SitusLatitude = a.SitusLatitude
                  WHERE s.PROPERTYUNIQUEID = p_propertyId
                  

                  请注意,使用 LIMIT 而没有 ORDER BY 意味着被选中的行将是不可预测的.

                  Note that using LIMIT without ORDER BY means that the row that's selected will be unpredictable.

                  这篇关于更新变量的MYSQL存储过程为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:这个存储过程有什么问题? 下一篇:过程中的游标返回的值多于查询

                  相关文章

                    <small id='68bHj'></small><noframes id='68bHj'>

                  1. <legend id='68bHj'><style id='68bHj'><dir id='68bHj'><q id='68bHj'></q></dir></style></legend>
                  2. <i id='68bHj'><tr id='68bHj'><dt id='68bHj'><q id='68bHj'><span id='68bHj'><b id='68bHj'><form id='68bHj'><ins id='68bHj'></ins><ul id='68bHj'></ul><sub id='68bHj'></sub></form><legend id='68bHj'></legend><bdo id='68bHj'><pre id='68bHj'><center id='68bHj'></center></pre></bdo></b><th id='68bHj'></th></span></q></dt></tr></i><div id='68bHj'><tfoot id='68bHj'></tfoot><dl id='68bHj'><fieldset id='68bHj'></fieldset></dl></div>
                  3. <tfoot id='68bHj'></tfoot>

                      <bdo id='68bHj'></bdo><ul id='68bHj'></ul>