
如果插入的记录是数字的话要在数字的逗号后面加n:
通过以上实例我们可以看到insert into语句只能向原表中插入于其字段对应的数据,那么能不能通过insert into语句来把其他表的数据插入到原表中呢:
在MySQL中set方法:
ModifyStatement.Set Method修改语句 set方法
Sets key and value. 设置键和值。
由于insert into语句是一个插入性的语句,所以它的功能要么向指定的表插入数据
也许你看到这个SQL语句是正确的,就觉得这样应该也可以:
mysql>mysql>insert into 4a set sname=4ainall.sname
ERROR 1064 (42000): You have an error in your SQL syntaxcheck the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql>insert into 4a set sname=4ainall.sname' at line 1
或者这样也可以:
mysql>mysql>insert into 4a set sname="赵六"
ERROR 1064 (42000): You have an error in your SQL syntaxcheck the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql>insert into 4a set sname="赵六"' at line 1
然后这样也是不可用:
mysql>insert into 4a select * from 4ainall set sname=4ainall.sname
ERROR 1064 (42000): You have an error in your SQL syntaxcheck the manual that corresponds to your MySQL server version for the right syntax to use near 'from 4ainall set sname=4ainall.sname' at line 1
可以看出由于select是作用于4inall这个表的,而set方法也只能在select语句中,这就直接导致set方法只能作用于4inall这个表,而无法作用于4a这个表。
但是如果我们不用select语句的话编译器又怎么会知道4inall表中的数据在哪里?
显然select是用于查的而set则是一个用于改的方法,两者无法结合在一起——insert into set语句当然也不能用于将其他表的数据插入到原表中了。
你是sql语句错了String sql="insert into information values(information_seq.nextval,?,?,?,?)"错了,mysql中没有序列,改为
String sql="insert into information values(default,?,?,?,?)"就行了
insert into 表名 values(default,"名字","2011-04-15 12:22:25") //default可以换成null------------------------------
insert into 表名 (name,datetime) values("名字","2011-04-15 12:22:25")
//不指定列名的时候,是需要列出所有字段的值的。包括自增列,不然是会报错的~
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)