gpt4 book ai didi

python - 当我更新的属性是用户输入时,如何编写更新语句?

转载 作者:行者123 更新时间:2023-12-01 02:23:52 27 4
gpt4 key购买 nike

def updateNurseSpecification():

nurse_lname = input("\nEnter the last name of the nurse "
"you would to update: \n")

query = c.execute('SELECT fname, lname, specification FROM Nurses '
'WHERE lname LIKE ?', (nurse_lname,))

new_spec = input("\nEnter the updated specification of this employee: \n")

query1 = c.execute('UPDATE Nurses SET specification = ', (new_spec,)
' WHERE lname LIKE ?', (nurse_lname,))

我不知道使用变量“new_spec”更新记录的语法。

    print("Your update is as shown: \t")

query2 = c.execute('SELECT fname, lname, specification FROM Nurses'
'WHERE lname LIKE ?', (nurse_lname,))

最佳答案

execute 接受两个参数 - 一个 SQL 字符串和一个参数元组:

c.execute('UPDATE Nurses SET specification = %s WHERE lname LIKE %s', 
(new_spec, nurse_lname))

关于python - 当我更新的属性是用户输入时,如何编写更新语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47641803/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com