我的代码:
Name Null? Type
------------ ----- -------------
SNO NUMBER(38)
STUD_ID VARCHAR2(26)
STUDENT_NAME VARCHAR2(128)
DATEOFBIRTH VARCHAR2(26)
CLASS NUMBER(38)
SECTION VARCHAR2(26)
GENDER VARCHAR2(26)
TELEGU VARCHAR2(26)
MATHS VARCHAR2(26)
SOCIAL VARCHAR2(26)
ENGLISH VARCHAR2(26)
错误:
name1 = name_entry.get()
conn = sqlite3.connect('test123.db')
c = conn.cursor()
c.execute("SELECT * FROM table123 WHERE name = name1")
print(c.fetchall())
conn.commit()
conn.close()
我的问题 如何在WHERE游标中使用变量来查找所需的元组?
答案 0 :(得分:1)
您应在name1
语句中替换变量c.execute
的值。这样做:
c.execute("SELECT * FROM table123 WHERE name = {}".format(name1))
或:
c.execute("SELECT * FROM table123 WHERE name = ?", name1)