在此位置使用无效输入 MySQL Workbench

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30799615/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:05:37  来源:igfitidea点击:

Use is not valid input at this position MySQL Workbench

mysqlsqlstored-proceduresmysql-workbench

提问by Sarah

I'm trying to create a stored procedure in MySQL Workbench:

我正在尝试在 MySQL Workbench 中创建一个存储过程:

USE `data_p`;
DROP PROCEDURE IF EXISTS `Product`;
DELIMITER $$
USE `data_p`$$
CREATE DEFINER=`data_s_admin`@`...` PROCEDURE `Product`(

  INOUT d_id INT,
  INOUT d_fk_c INT,
  INOUT d_s VARCHAR(255),
  INOUT d_p DECIMAL,
  INOUT d_c_a DATE,
  INOUT d_o_p DECIMAL,
  INOUT d_s_c DECIMAL,
  INOUT d_x_s VARCHAR(20),
  INOUT d_d_w VARCHAR(20),
  INOUT d_fk_c_a INT,
  INOUT d_s enum('ac','in','de')
)

BEGIN
    DECLARE cs_id INT;
    DECLARE cs_fk_c INT;
    DECLARE cs_s VARCHAR(255);
    DECLARE cs_p DECIMAL;
    DECLARE cs_c_a DATE;
    DECLARE cs_o_p DECIMAL;
    DECLARE cs_s_c DECIMAL;
    DECLARE cs_x_s VARCHAR(20);
    DECLARE cs_d_w VARCHAR(20);
    DECLARE cs_fk_c_a INT;
    DECLARE cs_s enum('ac','in','de');

 SELECT 

   d_id ,
   d_fk_c ,
   d_s,
    d_p ,
   d_c_a ,
   d_o_p ,
   d_s_c ,
   d_x_s,
   d_d_w,
   d_fk_c_a,
   d_s
 )
 INTO 

  cs_id,
  cs_fk_c,
  cs_s,
  cs_p,
  cs_c_a,
  cs_o_p,
  cs_s_c,
  cs_x_s,
  cs_d_w,
  cs_fk_c_a,
  cs_s

 FROM 

        data_p.cas
 WHERE 
        cs_s = d_s AND cs_s = 'ac';

 END $$
 DELIMITER ;

When i click on data_s==> stored procedures, i create new stored procedure and then i paste this code, my errors are : Syntax error: 'USE' is not valid input at this position Syntax error: IF : unexpected at this position

当我单击 data_s==> 存储过程时,我创建新的存储过程,然后粘贴此代码,我的错误是:语法错误:'USE' 在此位置无效输入语法错误:IF:在此位置意外

What is the problem? i really want to fix this to know how many rows affected

问题是什么?我真的很想解决这个问题以了解受影响的行数

I create my stored procedure in database 'data_s' and i return all data from 'data_p '

我在数据库“data_s”中创建了我的存储过程,并从“data_p”返回所有数据

Can anyone help me please.

任何人都可以请帮助我。

Many thanks for any help

非常感谢您的帮助

回答by Ilan

Although it is an old question, didn't saw the answer, but I manage to solve a same problem.

虽然这是一个老问题,没有看到答案,但我设法解决了同样的问题。

It is possible that the file was save as UTF8 with BOM (or the content was copied from such a file).

文件可能已保存为带有 BOM 的 UTF8(或内容是从此类文件中复制的)。

In this case, try to save the file in UTF8 format (without BOM) and then re-run the code.

在这种情况下,尝试将文件保存为 UTF8 格式(不带 BOM),然后重新运行代码。

For me it fix a same problem.

对我来说,它解决了同样的问题。

Note: 1) You can change the encoding, for example, with Notepadd++. 2) Note that BOM is acronyms for Byte-Order-Mark, which is a short sequence of bytes in the beginning of a file that marks the encoding of the file.

注意:1) 您可以更改编码,例如,使用 Notepadd++。2)注意BOM是Byte-Order-Mark的首字母缩写,它是文件开头的一个短字节序列,用于标记文件的编码。

回答by Mike Lischke

When you use the object editor (which you get when you select "Create Stored Procedure..." in the context menu of the schema tree) you don't need to add all the decoration. Simply write your stored procedure without USE, DELIMITER and DROP. When you apply your changes you will see that MySQL Workbench automatically creates a USE command for you (depending on which schema you clicked to trigger the SP editor). You should drop an existing SP manually before you create it again.

当您使用对象编辑器(当您在架构树的上下文菜单中选择“创建存储过程...”时获得)时,您不需要添加所有装饰。只需编写您的存储过程,无需 USE、DELIMITER 和 DROP。当您应用更改时,您将看到 MySQL Workbench 自动为您创建一个 USE 命令(取决于您单击哪个模式以触发 SP 编辑器)。您应该在再次创建之前手动删除现有 SP。

If you use the SQL editor instead then you need all the decoration, however.

但是,如果您改用 SQL 编辑器,则需要所有修饰。