我正在尝试检查Python中是否存在数据库。我发现可以使用以下sql语句完成此操作:Uncaught TypeError: old.remove is not a function
但是,在尝试执行它后,出现以下错误:
cur.execute(f'SHOW DATABASES LIKE {event["db_name"]}')
答案 0 :(得分:0)
您在语句中遗漏了撇号,可以在%
语句中使用LIKE
来匹配更多结果,请尝试以下操作:
cur.execute(f"SHOW DATABASES LIKE '%{event["db_name"]}%;'")
有关LIKE
运算符的更多信息:
LIKE 'a%' Finds any values that start with "a"
LIKE '%a' Finds any values that end with "a"
LIKE '%or%' Finds any values that have "or" in any position
LIKE '_r%' Finds any values that have "r" in the second position
LIKE 'a__%' Finds any values that start with "a" and are at least 3 characters in length
LIKE 'a%o' Finds any values that start with "a" and ends with "o"
答案 1 :(得分:-1)
发现错误是由于以下事实引起的:我需要用引号将数据库名称引起来,以便以下SQL语句起作用:cur.execute(f'SHOW DATABASES LIKE "{event["db_name"]}"')