• <legend id='xQmxc'><style id='xQmxc'><dir id='xQmxc'><q id='xQmxc'></q></dir></style></legend>

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

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

      2. <tfoot id='xQmxc'></tfoot>
          <bdo id='xQmxc'></bdo><ul id='xQmxc'></ul>

        MySQL DECLARE 中的 SELECT INTO 变量导致语法错误?

        SELECT INTO Variable in MySQL DECLARE causes syntax error?(MySQL DECLARE 中的 SELECT INTO 变量导致语法错误?)

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

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

                • <bdo id='XOon5'></bdo><ul id='XOon5'></ul>
                    <tbody id='XOon5'></tbody>
                  <tfoot id='XOon5'></tfoot>
                  本文介绍了MySQL DECLARE 中的 SELECT INTO 变量导致语法错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想将单个值 SELECT 到一个变量中.我试图遵循:

                  Id like to SELECT a single value into a variable. Id tried to following:

                  DECLARE myvar INT(4);
                  

                  -- 立即返回一些语法错误.

                  -- immediately returns some syntax error.

                  SELECT myvalue 
                    FROM mytable 
                   WHERE anothervalue = 1;
                  

                  -- 返回一个整数

                  SELECT myvalue 
                    INTO myvar 
                    FROM mytable 
                   WHERE anothervalue = 1;
                  

                  -- 不行,也试过@myvar

                  -- does not work, also tried @myvar

                  是否可以在存储过程或函数之外使用 DECLARE?

                  Is possible to use DECLARE outside of stored procedures or functions?

                  也许我只是不明白用户变量的概念......我只是试过:

                  Maybe I just dont get the concept of user variables... I just tried:

                  SELECT myvalue INTO @var FROM `mytable` WHERE uid = 1;
                  SELECT @var;
                  

                  ...就像它应该的那样工作.但是如果我一次运行每个查询,我只会得到@var NULL.

                  ...which worked just like its supposed to. But if I run each query at a time i just get @var NULL.

                  推荐答案

                  最后一个存储过程解决了我的问题.

                  In the end a stored procedure was the solution for my problem.

                  这里有什么帮助:

                  DELIMITER //
                  
                  CREATE PROCEDURE test ()
                  BEGIN
                    DECLARE myvar DOUBLE;
                    SELECT somevalue INTO myvar FROM mytable WHERE uid = 1;
                  
                    SELECT myvar;
                  END//
                  
                  DELIMITER ;
                  
                  call test();
                  

                  这篇关于MySQL DECLARE 中的 SELECT INTO 变量导致语法错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to update a record using sequelize for node?(如何使用节点的 sequelize 更新记录?)
                  How to provide a mysql database connection in single file in nodejs(如何在 nodejs 中的单个文件中提供 mysql 数据库连接)
                  Looping Over Result Sets in MySQL(在 MySQL 中循环结果集)
                  How to get Top 5 records in SqLite?(如何获得 Sqlite 中的前 5 条记录?)
                  SQL Server SELECT where any column contains #39;x#39;(SQL Server SELECT,其中任何列包含“x)
                  Default row order in SELECT query - SQL Server 2008 vs SQL 2012(SELECT 查询中的默认行顺序 - SQL Server 2008 与 SQL 2012)

                  • <bdo id='ViYg2'></bdo><ul id='ViYg2'></ul>

                        <tbody id='ViYg2'></tbody>

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

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

                        1. <tfoot id='ViYg2'></tfoot>