其实这个在手册中的变量赋值一章已经介绍。好多人没有注意看而已。
/*DDL Information For - test.user*/ -----------------------------------
Table Create Table ------ ------------------------------------------------------- user CREATE TABLE `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` char(20) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
|
先看以下INSERT:
insert into `user`(username) values(@var1:='csdn_user1');
select cast(@var1 as char(20)) ;
query result(1 records)
cast(@var1 as char(20)) |
csdn_user2 |
|
这个例子中使用的ID是AUTO_INCREMENT。所以还有另外一种方法得到。
select username from `user` where id = last_insert_id();
query result(1 records)
|
下来看看UPDATE:
update `user` set username = (@var1:='csdn_user2');
|
select cast(@var1 as char(20)) ;
query result(1 records)
cast(@var1 as char(20)) |
csdn_user2 | |
阅读(2147) | 评论(1) | 转发(0) |