INSERT 中的百分号 (%)

发布于 2025-01-06 03:14:13 字数 187 浏览 0 评论 0原文

我必须将值更改到我的数据库中。字符串值之一可以包含 % 符号。

粗略示例:

UPDATE Mortgage 
SET TEXT = 'The interest rate is 7%';

更改未保存在数据库中。如何在 SQL Server 中转义百分号

I have to change values into my database. One of the string values can contain a % sign.

Rough example:

UPDATE Mortgage 
SET TEXT = 'The interest rate is 7%';

The change is not saved in the database. How can I escape the percentage sign in SQL Server

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

北风几吹夏 2025-01-13 03:14:13
UPDATE Mortgage SET TEXT = 'The interest rate is 7' + CHAR(37);

37 是百分号的十进制 ASCII 代码

UPDATE Mortgage SET TEXT = 'The interest rate is 7' + CHAR(37);

37 is the decimal ASCII code for a percent symbol.

清浅ˋ旧时光 2025-01-13 03:14:13

您可以使用自定义转义字符,例如:

UPDATE Mortgage 
SET TEXT = 'The interest rate is 7\%' ESCAPE '\';

但我认为您不需要在这里转义这个字符 % 因为它作为输入值没有特殊含义,但您必须在如果您想在 LIKE 查询中使用它。

You can use a custom escape character, for example:

UPDATE Mortgage 
SET TEXT = 'The interest rate is 7\%' ESCAPE '\';

But I think you didn't need to escape this character % here becouse it has no special meaning as an input value, but you have to escape it in case you want to use it in a LIKE query.

魄砕の薆 2025-01-13 03:14:13

您是否尝试过用“\”转义字符?

UPDATE Mortgage 
SET TEXT = 'The interest rate is 7\%';

Have you tried escaping the character with "\"?

UPDATE Mortgage 
SET TEXT = 'The interest rate is 7\%';
青丝拂面 2025-01-13 03:14:13

你的架构是什么?

我尝试过这个&它有效(SQL-Server 2008 R2 和 SSMS):

CREATE TABLE [dbo].[Mortgage](
    [TEXT] [varchar](500) NOT NULL
) ON [PRIMARY]
insert Mortgage (TEXT) values ('The interest rate is 7%');
SELECT TEXT FROM Mortgage;

UPDATE Mortgage SET TEXT = 'The new interest rate is 3%';
SELECT TEXT FROM Mortgage;

What is your schema?

I tried this & it works(SQL-Server 2008 R2 & SSMS):

CREATE TABLE [dbo].[Mortgage](
    [TEXT] [varchar](500) NOT NULL
) ON [PRIMARY]
insert Mortgage (TEXT) values ('The interest rate is 7%');
SELECT TEXT FROM Mortgage;

UPDATE Mortgage SET TEXT = 'The new interest rate is 3%';
SELECT TEXT FROM Mortgage;
情话难免假 2025-01-13 03:14:13

尝试将 %: %% 加倍

UPDATE Mortgage 
SET TEXT = 'The interest rate is 7%%';

Try doubling the %: %%

UPDATE Mortgage 
SET TEXT = 'The interest rate is 7%%';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文