SQL-','附近的语法错误 [英] SQL - Syntax error near ','

查看:115
本文介绍了SQL-','附近的语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法终生弄清楚为什么无论我尝试使用哪个本地数据库(oracle,mysql,microsoft sql),该查询都不起作用.

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).

INSERT INTO testtable
VALUES ( 'testvalue' , 12345678, 123.04, 0, '1950-01-03' )

例如,在Microsoft SQL Server中,,"附近出现错误.

For example, with Microsoft SQL Server I get an Error near ','.

使用MySQL我得到

第2行的'12345678,123.04,0,)'附近的SQL语法有错误.

You have an error in your SQL syntax near '12345678, 123.04, 0, )' at line 2.

我尝试过使用它,我在W3学校学习了INSERT INTO的语法.一切看起来都很好.会是什么?

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?

谢谢!

根据要求:这是mysql的布局

As requested: here's the layout for 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.

我的猜测是您一次要运行多个语句,而没有正确地分隔每个语句.例如:

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' )

将导致错误.但是:

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.

这篇关于SQL-','附近的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆