【问题标题】:Single and double quote issue in SQL insertSQL插入中的单引号和双引号问题
【发布时间】:2012-05-30 14:44:58
【问题描述】:

请参阅下面的查询。

INSERT INTO pro VALUES ("260915",'Peel and Stick Floral Wall Art','Transform your tot's bedroom into a bright, burgeoning meadow with this set of oh-so-colorful wall art. Each unique flower, bird, butterfly, and swirly sun is a colorful creation of multilayered vinyl brimming with life and energy. How best to arrange them is entirely up to you--and your 12.2" x 15.4"','','Shipping',"790","110-m4jlgu36n",1.00,0,0,"0.00","70.00","http://.com/peel-and-stick-floral-wall-art.html","622")

在这里,我想在列中插入相同值的单引号和双引号:

eg a) 12.2" x 15.4"
   b) Transform your tot's 

请提出最佳解决方案。

【问题讨论】:

    标签: ios sql database sqlite


    【解决方案1】:

    在构建INSERT时,在外面使用单引号,双引号的问题就解决了。

    要解决单引号问题,请将' 替换为''

    【讨论】:

      【解决方案2】:

      为什么你不逃避你的报价? 12.2\"?

      【讨论】:

      • 我不能,因为它来自服务器,我需要在数据库中插入相同的内容
      • 如果它来自服务器,那么你不需要担心它们是吗?
      【解决方案3】:

      将所有内容放在单引号'

      '12.2" x 15.4"<br>'
      

      对于像 Transform your tot's 这样的字符串,你将不得不像这样逃避它

      'Transform your tot\'s'
      

      【讨论】:

        【解决方案4】:

        对于 T-SQL,要在数据中获取单引号,您只需将其转义为另一个(例如,使用两个相邻的单引号)您无需担心字符串文字中的双引号。

        INSERT INTO foo VALUES ('qwerty''s: 25" sq.')
        

        【讨论】:

          【解决方案5】:

          仅使用单引号 (') 将值括起来。如果单引号是值的一部分,请输入两次(这是转义它的方法)。

          例如

          INSERT INTO TABLE VALUES ('12.2" x 15.4"', 'Transform your tot''s bedroom...');
          

          【讨论】:

            猜你喜欢
            • 2023-03-25
            • 2013-03-24
            • 2019-07-20
            • 1970-01-01
            • 1970-01-01
            • 2021-01-16
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多