<tfoot id='zYM0G'></tfoot>

        <legend id='zYM0G'><style id='zYM0G'><dir id='zYM0G'><q id='zYM0G'></q></dir></style></legend>
      1. <i id='zYM0G'><tr id='zYM0G'><dt id='zYM0G'><q id='zYM0G'><span id='zYM0G'><b id='zYM0G'><form id='zYM0G'><ins id='zYM0G'></ins><ul id='zYM0G'></ul><sub id='zYM0G'></sub></form><legend id='zYM0G'></legend><bdo id='zYM0G'><pre id='zYM0G'><center id='zYM0G'></center></pre></bdo></b><th id='zYM0G'></th></span></q></dt></tr></i><div id='zYM0G'><tfoot id='zYM0G'></tfoot><dl id='zYM0G'><fieldset id='zYM0G'></fieldset></dl></div>

          <bdo id='zYM0G'></bdo><ul id='zYM0G'></ul>

        <small id='zYM0G'></small><noframes id='zYM0G'>

      2. MySQL - 替换列中的字符

        MySQL - Replace Character in Columns(MySQL - 替换列中的字符)

      3. <small id='7ZEpM'></small><noframes id='7ZEpM'>

          <bdo id='7ZEpM'></bdo><ul id='7ZEpM'></ul>

              <tbody id='7ZEpM'></tbody>
          1. <tfoot id='7ZEpM'></tfoot>
            <legend id='7ZEpM'><style id='7ZEpM'><dir id='7ZEpM'><q id='7ZEpM'></q></dir></style></legend>
              1. <i id='7ZEpM'><tr id='7ZEpM'><dt id='7ZEpM'><q id='7ZEpM'><span id='7ZEpM'><b id='7ZEpM'><form id='7ZEpM'><ins id='7ZEpM'></ins><ul id='7ZEpM'></ul><sub id='7ZEpM'></sub></form><legend id='7ZEpM'></legend><bdo id='7ZEpM'><pre id='7ZEpM'><center id='7ZEpM'></center></pre></bdo></b><th id='7ZEpM'></th></span></q></dt></tr></i><div id='7ZEpM'><tfoot id='7ZEpM'></tfoot><dl id='7ZEpM'><fieldset id='7ZEpM'></fieldset></dl></div>
                  本文介绍了MySQL - 替换列中的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  作为一个自学的新手,我给自己制造了一个大问题.在将数据插入到我的数据库之前,我已经将字符串中的撇号 (') 转换为双引号 (""),而不是 MySQL 实际需要的必需的反斜杠和撇号 (\').

                  在我的表增长超过 200,000 行之前,我认为最好立即纠正这个问题.所以我做了一些研究,发现了 SQL REPLACE 函数,这很棒,但我现在很困惑.

                  在 ASP 中,我是这样做的:

                  str = Replace(str,"'","""")

                  如果我在 SQL Workbench 中查看我的数据库,我转换的符号现在是单引号 ("),这让我有点困惑.我明白为什么它从双引号变为单引号,但我不知道是哪个一个我现在打算改变的.

                  要使用 SQL REPLACE 解决并纠正我的问题,我现在是将单引号 (") 转换为反斜杠和撇号 (\'),还是将双引号 ("") 转换为反斜杠和撇号 (\')?

                  例如:

                  SQL = " SELECT REPLACE(myColumn,"""","\'") FROM myTable "

                  或者这个:

                  SQL = " SELECT REPLACE(myColumn,""","\'") FROM myTable "

                  我希望我能很好地解释自己,任何建议一如既往地感激收到.对我的问题有任何疑问,请发表评论.

                  非常感谢

                  -- 更新 --

                  我尝试了以下查询,但仍然无法更改数据中的 ("):

                  SELECT REPLACE(caption,'\"','\'') FROM photos WHERE photoID = 3371SELECT REPLACE(caption,'"','\'') 从照片 WHERE photoID = 3371SELECT REPLACE(caption,'""','\'') 从照片中选择照片 ID = 3371

                  但是如果我搜索:

                  SELECT COUNT(*) FROM photos WHERE caption LIKE '%"%'

                  我得到 16,150 行.

                  -- 更新 2 --

                  好吧,我已经创建了一个解决方法".我设法使用此 SQL 编写 ASP 脚本非常快速地转换了整个列:

                  SELECT photoID, caption FROM photos WHERE caption LIKE '%""%';

                  然后在 ASP 中我做了:

                  caption = Replace(caption,"""","\'")

                  但我仍然想知道为什么我不能用 SQL 实现这一点?

                  解决方案

                  只运行 SELECT 语句对数据没有影响.您必须使用带有 REPLACEUPDATE 语句来进行更改:

                  更新照片SET caption = REPLACE(caption,'"','\'')

                  这是一个工作示例:http://sqlize.com/7FjtEyeLAh

                  Being a self-taught newbie, I created a large problem for myself. Before inserting data in to my database, I've been converting apostrophes (') in a string, to double quotes (""), instead of the required back-slash and apostrophe (\'), which MySQL actually requires.

                  Before my table grows more than the 200,000 rows it already is, I thought it was best to rectify this issue immediately. So I did some research and found the SQL REPLACE function, which is great, but I'm now confused.

                  In ASP, I was doing this:

                  str = Replace(str,"'","""")
                  

                  If I look at my database in SQL Workbench, the symbol I converted is now a single quote ("), which has confused me a little. I understand why it changed from double to single, but I don't know which one I'm meant to be changing now.

                  To go through and rectify my problem using SQL REPLACE, do I now convert single quotes (") to back-slash and apostrophes (\') or do I convert double quotes ("") to back-slash and apostrophes (\')?

                  For example, this:

                  SQL = " SELECT REPLACE(myColumn,"""","\'") FROM myTable "
                  

                  or this:

                  SQL = " SELECT REPLACE(myColumn,""","\'") FROM myTable "
                  

                  I hope I explained myself well, any suggestions gratefully received as always. Any queries about my question, please comment.

                  Many thanks

                  -- UPDATE --

                  I have tried the following queries but still fail to change the ( " ) in the data:

                  SELECT REPLACE(caption,'\"','\'') FROM photos WHERE photoID = 3371
                  SELECT REPLACE(caption,'"','\'') FROM photos WHERE photoID = 3371
                  SELECT REPLACE(caption,'""','\'') FROM photos WHERE photoID = 3371
                  

                  Yet if I search:

                  SELECT COUNT(*) FROM photos WHERE caption LIKE '%"%'
                  

                  I get 16,150 rows.

                  -- UPDATE 2 --

                  Well, I have created a 'workaround'. I managed to convert an entire column pretty quickly writing an ASP script, using this SQL:

                  SELECT photoID, caption FROM photos WHERE caption LIKE '%""%';
                  

                  and then in ASP I did:

                  caption = Replace(caption,"""","\'")
                  

                  But I would still like to know why I couldn't achieve that with SQL?

                  解决方案

                  Just running the SELECT statement will have no effect on the data. You have to use an UPDATE statement with the REPLACE to make the change occur:

                  UPDATE photos
                     SET caption = REPLACE(caption,'"','\'')
                  

                  Here is a working sample: http://sqlize.com/7FjtEyeLAh

                  这篇关于MySQL - 替换列中的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to delete duplicate records in mysql database?(如何删除mysql数据库中的重复记录?)
                  Python Pandas write to sql with NaN values(Python Pandas 使用 NaN 值写入 sql)
                  MySQL Insert amp; Joins(MySQL 插入 amp;加入)
                  MySQL concat() to create column names to be used in a query?(MySQL concat() 创建要在查询中使用的列名?)
                  NodeJS responded MySQL timezone is different when I fetch directly from MySQL(当我直接从 MySQL 获取时,NodeJS 响应 MySQL 时区不同)
                  WHERE datetime older than some time (eg. 15 minutes)(WHERE 日期时间早于某个时间(例如 15 分钟))
                  <legend id='dhZMS'><style id='dhZMS'><dir id='dhZMS'><q id='dhZMS'></q></dir></style></legend>
                    <tbody id='dhZMS'></tbody>
                  <tfoot id='dhZMS'></tfoot>

                      • <i id='dhZMS'><tr id='dhZMS'><dt id='dhZMS'><q id='dhZMS'><span id='dhZMS'><b id='dhZMS'><form id='dhZMS'><ins id='dhZMS'></ins><ul id='dhZMS'></ul><sub id='dhZMS'></sub></form><legend id='dhZMS'></legend><bdo id='dhZMS'><pre id='dhZMS'><center id='dhZMS'></center></pre></bdo></b><th id='dhZMS'></th></span></q></dt></tr></i><div id='dhZMS'><tfoot id='dhZMS'></tfoot><dl id='dhZMS'><fieldset id='dhZMS'></fieldset></dl></div>
                        • <bdo id='dhZMS'></bdo><ul id='dhZMS'></ul>

                          <small id='dhZMS'></small><noframes id='dhZMS'>