-1

执行以下 mysql 查询时,字段将填充为 null 而不是指定的值。

INSERT INTO invoices VALUES( 
slNo='2', mrp='3', PplusT='3.375', 
name='Eraser', code='002', qty='15', 
unitPrice='3', rateOfTax='12.5', taxAmt='0.375',
cess='0.004', total='50.625', billNo='10001')

表架构

slNo            int(11)                                     
mrp             float                                           
PplusT          float                                       
name            varchar(50)                          
code            varchar(10)                          
qty             int(11)                 
unitPrice       float                   
rateOfTax       float                   
taxAmt          float                           
cess            float                       
total           float           
billNo          varchar(10) 

我尝试使用 PHP 以及 PHPMYADMIN 进行查询,但结果是相同的。

4

6 回答 6

3

请查看手册。替换VALUESSET

INSERT INTO invoices
SET slNo=2, mrp=3, PplusT=3.375, 
name='Eraser', code='002', qty=15, 
unitPrice=3, rateOfTax=12.5, taxAmt=0.375,
cess=0.004, total=50.625, billNo='10001'

您必须从数值数据类型的值中删除引号,否则它将尝试将它们作为字符串插入。

于 2012-05-30T17:24:19.780 回答
0

删除数值周围的单引号。

于 2012-05-30T17:23:49.703 回答
0

尝试取消引用您的数字...您实际上是在尝试将字符串插入整数和浮点数

INSERT INTO invoices VALUES( 
slNo=2, mrp=3, PplusT=3.375, 
name='Eraser', code='002', qty=15, 
unitPrice=3, rateOfTax=12.5, taxAmt=0.375,
cess=0.004, total=50.625, billNo='10001')
于 2012-05-30T17:24:00.473 回答
0

请阅读手册http://dev.mysql.com/doc/refman/5.0/en/insert-select.html

       INSERT INTO invoices SET 
           slNo='2', mrp='3', PplusT='3.375', 
           name='Eraser', code='002', qty='15', 
           unitPrice='3', rateOfTax='12.5', taxAmt='0.375',
           cess='0.004', total='50.625', billNo='10001'

或者

   INSERT INTO invoices ( slNo, mrp, PplusT, name, code, qty, unitPrice, rateOfTax,taxAmt,
       cess, total, billNo) VALUES( '2', '3', '3.375', 'Eraser', '002', '15', '3', '12.5', '0.375','0.004', '50.625', '10001')
于 2012-05-30T17:25:29.877 回答
0

我可能是错的,但插入语句不应该是这样的:

INSERT INTO invoices (slNo, mrp, PplusT, name, code, qty, unitPrice, rateOfTax, taxAmt, cess, total, billNo) 
VALUES('2', '3', '3.375', 'Eraser', '002', '15', '3', '12.5', '0.375',
'0.004', '50.625', '10001')
于 2012-05-30T17:25:46.910 回答
0

查看您拥有的格式,并阅读此页面。此外,不建议将整数值括在引号中,但我认为它在 MySQL 中有效......

http://en.wikipedia.org/wiki/Insert_(SQL )

于 2012-05-30T17:27:09.397 回答