MySQL SQL - ',' 附近的语法错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12418027/
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
SQL - Syntax error near ','
提问by Thenin
I can't for the life of me figure out why this query won't work no matter which one of my local databases I try (oracle, mysql, microsoft sql).
我一生都无法弄清楚为什么无论我尝试使用哪个本地数据库(oracle、mysql、microsoft sql),这个查询都不起作用。
INSERT INTO testtable
VALUES ( 'testvalue' , 12345678, 123.04, 0, '1950-01-03' )
For example, with Microsoft SQL Server I get an Error near ','.
例如,使用 Microsoft SQL Server 时,我在“,”附近出现错误。
With MySQL I get
使用 MySQL 我得到
You have an error in your SQL syntax near '12345678, 123.04, 0, )' at line 2.
在第 2 行的 '12345678, 123.04, 0, )' 附近,您的 SQL 语法有错误。
I've tried playing with it, I've looked at W3 school for the syntax of INSERT INTO. Everything looks good. What could it be?
我试过玩它,我看过 W3 学校的 INSERT INTO 语法。一切看起来都不错。会是什么呢?
Thank you!
谢谢!
EDIT:
编辑:
As requested: here's the layout for mysql
根据要求:这是 mysql 的布局
+------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+--------------+------+-----+---------+-------+ | TestString | varchar(600) | NO | | NULL | | | TestInt | int(11) | NO | | NULL | | | TestDouble | double | NO | | NULL | | | Testbool | tinyint(1) | NO | | NULL | | | TestDate | date | NO | | NULL | | +------------+--------------+------+-----+---------+-------+
Also, it should be noted I can run a parameterized query using these values and it will work just fine. It's only when I go to manually create the query that it's a problem.
另外,应该注意的是,我可以使用这些值运行参数化查询,它会正常工作。只有当我手动创建查询时才会出现问题。
回答by Mike Christensen
There is nothing wrong with your schema or syntax, as you can see from this SQL Fiddle.
正如您从这个SQL Fiddle 中看到的,您的架构或语法没有任何问题。
My guess is that you're running more than one statement at a time and not properly delimiting each one. For example:
我的猜测是您一次运行多个语句,并且没有正确分隔每个语句。例如:
INSERT INTO testtable
VALUES ( 'testvalue' , 12345678, 123.04, 0, '1950-01-03' )
INSERT INTO testtable
VALUES ( 'testvalue' , 12345678, 123.04, 0, '1950-01-03' )
Will cause an error. However:
会导致错误。然而:
INSERT INTO testtable
VALUES ( 'testvalue' , 12345678, 123.04, 0, '1950-01-03' ); --End statement with ;
INSERT INTO testtable
VALUES ( 'testvalue' , 12345678, 123.04, 0, '1950-01-03' );
...will run fine. It's also possible that you have a stray open-quote somewhere that isn't being closed, causing part of your statement to be the ending part of another string constant. Verify exactlywhat you're running, as the code you've posted will work fine as-is.
...会运行良好。也有可能您在某处未关闭的地方有一个杂散的开引号,导致您的语句的一部分成为另一个字符串常量的结尾部分。准确验证您正在运行的内容,因为您发布的代码将按原样正常工作。
回答by diEcho
format of the value depends on the dataType of your columns, but other hand always wrap you value with '
except intdataType
值的格式取决于列的数据类型,但另一方面总是用'
除了intdataType包装你的值
TRY
尝试
INSERT INTO testtable
VALUES ( 'testvalue' , '12345678', '123.04', '0', '1950-01-03' );
回答by jainvikram444
INSERT INTO testtable(column1,column2,column3,column4,column5)
VALUES ( 'testvalue' , 12345678, 123.04, 0, '1950-01-03' )
回答by Dinesh Guptha
INSERT INTO testtable (TestString,TestInt,TestDouble,Testbool,TestDate )
VALUES ( 'testvalue' , '12345678', '123.04', '0', '1950-01-03' )
Try This...
尝试这个...