簡體   English   中英

如何在sql列中搜索帶引號的值並替換?

[英]How to search for a value with quotation marks in sql column and replace it?

在我的 sql 表中,有一列我的值如下:

在此處輸入圖像描述

我需要找到這些類型的條目並刪除單引號,因為我不需要它們,但是如何通過 where 子句中的查詢來獲取它們? 如果我使用表 1 中的 select *,其中 desc = 'the values is '10',它根本不會工作,因為語句不正確。 我如何修改我的 where 子句以獲得所需的結果?

將引號加倍以使其轉義:

select * from table 1 where desc = 'i am ''not'' a graduate'

附帶說明,不要選擇* ,顯式列出您感興趣的列:

select id, "desc" from table 1 where desc = 'i am ''not'' a graduate'

…而且不要用SQL保留字來命名列;-)

您也可以選擇 * from table 1 where desc like '%'%'

嘗試在值的內部和外部使用不同的引號類型(雙引號和單引號)。 例如

SELECT * FROM table 1 WHERE desc = "the values is '10'";

或一次查找在 desc 中包含單引號的所有行

SELECT * FROM table 1 WHERE desc LIKE "%'%";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM