使用 cx_Oracle 的 LIKE 中字符串的正确语法是什么?

What's the proper syntax for strings in LIKE using cx_Oracle?

我正在尝试执行查询,但我不确定如何让它搜索字符串。例如

cursor.execute('SELECT * FROM table WHERE column LIKE 'blah%'') 

这给我一个语法错误。另外,如果不是很明显,我是 python 和 oracle

的新手

如果您的字符串以 ' 开头并想在字符串中使用 ',您要么必须使用 \ 转义它,要么可以使用不同的引号开始你的字符串:

cursor.execute('SELECT * FROM table WHERE column LIKE \'blah%\'') 
cursor.execute("SELECT * FROM table WHERE column LIKE 'blah%'") 
cursor.execute("""SELECT * FROM table WHERE column LIKE 'blah%'""")