简体   繁体   English

SQL - ','附近的语法错误

[英]SQL - Syntax error near ','

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. 我试过玩它,我看过W3学校的INSERT INTO语法。 Everything looks good. 一切都很好看。 What could it be? 会是什么呢?

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. 只有当我手动创建查询时才会出现问题。

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 exactly what you're running, as the code you've posted will work fine as-is. 确切地验证您正在运行的内容,因为您发布的代码将按原样正常运行。

format of the value depends on the dataType of your columns, but other hand always wrap you value with ' except int dataType 值的格式取决于列的dataType,但另一方面始终使用'int dataType包装值

TRY 尝试

INSERT INTO testtable
VALUES ( 'testvalue' , '12345678', '123.04', '0', '1950-01-03' );
INSERT INTO testtable(column1,column2,column3,column4,column5) 
VALUES ( 'testvalue' , 12345678, 123.04, 0, '1950-01-03' )
INSERT INTO testtable (TestString,TestInt,TestDouble,Testbool,TestDate ) 
VALUES ( 'testvalue' , '12345678', '123.04', '0', '1950-01-03' )

Try This... 尝试这个...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM