You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将SQL查询返回的STRUCTURE字段统一替换为正斜杠格式?

Convert Backslash Path to Forward Slash in SQL

Alright, let's solve this path formatting problem. You need to turn a Windows-style backslash-separated path into a forward-slash one, and the solution is straightforward using SQL's built-in string replacement functions. Here's how to implement it across common database systems:

MySQL/MariaDB

In MySQL, backslashes are escape characters, so you need to double them in the REPLACE function to target a single backslash:

SELECT REPLACE(PATH, '\\', '/') AS STRUCTURE
FROM OBJ_RESOURCE
WHERE PATH LIKE '%Small Business%';

This query will swap every backslash (\) in the PATH value with a forward slash (/), turning your original string exactly into the desired format: /Small Business/Organisation / IT / Logistik/Organisation / Governance/Person/Prozess-User.

SQL Server

SQL Server handles backslashes a bit differently — you can use a single backslash in the REPLACE function without escaping it (since it's not an escape character in regular string literals here):

SELECT REPLACE(PATH, '\', '/') AS STRUCTURE
FROM OBJ_RESOURCE
WHERE PATH LIKE '%Small Business%';

This will produce the same forward-slash path you need, converting all backslashes including the leading one.

Oracle

Oracle doesn't treat backslashes as escape characters in string literals, so the REPLACE function works with a single backslash directly:

SELECT REPLACE(PATH, '\', '/') AS STRUCTURE
FROM OBJ_RESOURCE
WHERE PATH LIKE '%Small Business%';

Just like the other examples, this will fully convert the path to use forward slashes exclusively.

Key Note

All these solutions work because the REPLACE function operates on every occurrence of the target character in the string. That means the leading backslash gets converted to a forward slash, and every subsequent backslash in the path is swapped out too — exactly matching your required output.

内容的提问来源于stack exchange,提问作者anna

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 04:25:45