MySQL相当于Python的三元组字符串?

2024-09-20 22:21:18 发布

您现在位置:Python中文网/ 问答频道 /正文

使用Python的三重引号字符串,我可以定义包含'、反撇号或"的字符串,而不必关心它们:

hello = """    
            This string is bounded by triple double quotes (3 times ").
        Unescaped newlines in the string are retained, though 
        it is still possible to use all normal escape sequences.

            Whitespace at the beginning of a line is
        significant.  

            This string ends in a newline.
        """

在PHP中,我可以使用heredoc<<<):

^{pr2}$

如何在MySQL中执行相同的操作?现在我必须确保转义我用来分隔的字符,例如,如果我使用'作为分隔符,我必须在字符串中使用\'

UPDATE article
SET article_text ='
Extra-virgin olive oil is a staple in any chef\'s kitchen.
'

我希望能

UPDATE article
SET article_text ='''
Extra-virgin olive oil is a staple in any chef's kitchen.
'''

Tags: the字符串textinstringisarticleupdate
1条回答
网友
1楼 · 发布于 2024-09-20 22:21:18

也可以在一行中使用两个单引号(''),而不是反斜杠转义单引号(\')。在

据我所知,除了双引号,没有更简单的方法。没有等价于"""。这很可悲。在

但实际上,正如前面提到的,here最好的选择是根本不使用任何基于SQL的解决方案;最常见的数据库是由用另一种语言编写的程序或由用另一种语言编写的程序生成的SQL脚本来访问的。在

我还没有遇到过一种编程语言不支持prepared statements,并且为了方便起见至少有一些SQL转义函数。在

相关问题 更多 >

    热门问题