众所周知, cx_Oracle 在运行 sql 语句时,可以这么写:
连接过程忽略,只看执行
sql = '''select phone_num from address_book where name = :1'''
cursor.execute(sql_sentence, ('爸爸'))
这样, sql 中的:1 位置就被替换成了 ‘爸爸’
问题来了,我要把句子这么写:
sql = '''select phone_num from address_book where name like %:1% '''
只要包含关键字就取出,可是 ------> %:1% <-----
这么写是错误的,-----> '%:1%' <-----
这么写也是错误的
请问涉及到 like 的句子,怎么写能使用上 cx_Oracle 的参数替换?
cursor.execute(sql_sentence, ('爸爸'))