1 sql string postgresql datetime special-characters
我无法在 PostgreSQL 中创建单引号后带有分号的字符串。例如。我需要创建一个像这样的字符串:
Delhi is India's capital; It's a beautiful state
Run Code Online (Sandbox Code Playgroud)
我如何创建这样的字符串?
我尝试了以下方法:
select 'Delhi is India\'s capital; It\'s a beautiful state'
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Invalid operation: unterminated quoted string at or near "'Delhi is India\'s capital"
Position: 8;
Run Code Online (Sandbox Code Playgroud)
在 SQL 中,您不使用反斜杠来转义单引号,而是通过将它们加倍来转义。分号不需要转义。
所以你应该使用
SELECT 'Delhi is India''s capital; It''s a beautiful state';
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3058 次 |
| 最近记录: |