Insert时,&符号如何插入

用Sql做Insert插入时,如果插入的值中含有'&'特殊字符,会弹出取值框。处理方式如下:

一、创建表UserTable
create table UserTable(
   name varchar(32),
   sex numeric(1),
   mainpage varchar(1000)
);


二、向表中插入值
1、普通值
insert into UserTable(name, sex, mainpage) values('lucy', 1, 'http://student?name=lucy');
提示:1 row插入成功。


2、含有‘&’特殊字符
insert into UserTable(name, sex, mainpage) values('lucy', 1, 'http://student?name=lucy&pageindex=1');
提示:弹出输入pageindex值的输入框。


3、含有‘&’特殊字符,但是不跟字符,可插入
insert into UserTable(name, sex, mainpage) values('lucy', 1, 'http://student?name=lucy&');
提示:1 row插入成功

三、解决方式
1、使用‘set define off’插入
set define off;
insert into UserTable(name, sex, mainpage) values('lucy', 1, 'http://student?name=lucy&pageindex=1');
提示:1 row插入成功


2、使用‘||’连接插入
set define off;
insert into UserTable(name, sex, mainpage) values('lucy', 1, 'http://student?name=lucy'||'&'||'pageindex=1');
提示:1 row插入成功


3、使用ASCII的字符转码
set define off;
insert into UserTable(name, sex, mainpage) values('lucy', 1, 'http://student?name=lucy'||chr(38)||'pageindex=1');
提示:1 row插入成功

如上。第一篇啊,以后要多写点了

猜你喜欢

转载自juzhongdegediao.iteye.com/blog/2191072