ITPub博客

首页 > 数据库 > MySQL > Mysql单引号使用

Mysql单引号使用

原创 MySQL 作者:jx_yu 时间:2015-07-06 16:36:36 0 删除 编辑
工作中经常需要批处理数据,select 字符串连接生成SQL from tab;

而对字符串的字段,值2边通常需要单引号,在select concat(字符串1,字符串2..........)时,给字符串加单引号,目前知道的有如下方法:
基于select 'test',给test2边添加单引号 
select '\'test\'';    #用反斜杠转义
select '''test''';     #''一起变成一个单引号
select concat("'",'test',"'");  #用""去意
select QUOTE('test');    #使用QUOTE函数

实验:
mysql> select 'test';
+------+
| test |
+------+
| test |
+------+
1 row in set (0.00 sec)


mysql> select '\'test\'';
+--------+
| 'test' |
+--------+
| 'test' |
+--------+
1 row in set (0.00 sec)


mysql> select '''test''';
+--------+
| 'test' |
+--------+
| 'test' |
+--------+
1 row in set (0.00 sec)


mysql> select concat("'",'test',"'");
+------------------------+
| concat("'",'test',"'") |
+------------------------+
| 'test'                 |
+------------------------+
1 row in set (0.00 sec)


mysql> select QUOTE('test');
+---------------+
| QUOTE('test') |
+---------------+
| 'test'        |
+---------------+
1 row in set (0.00 sec)

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/27000195/viewspace-1724674/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2012-05-23

  • 博文量
    80
  • 访问量
    876947