0

I have a Workers SQLite table and I am trying to display all workers whose name starts with a particular character input by the user.

letter = input("\nEnter starting letter of worker: ")
(cursor.execute("SELECT * FROM Workers WHERE Worker_Name LIKE '(?)%'", (letter,))).fetchall()

But I always keep getting this error:

sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 0, and there are 1 supplied.

But when I give like this, it works:

(cursor.execute("SELECT * FROM Workers WHERE Worker_Name LIKE 'J%'")).fetchall()

1 Answer 1

2

Use string concatenation in the query:

cursor.execute("SELECT * FROM Workers WHERE Worker_Name LIKE ? || '%'", (letter,))

... Or use string concatenation in your application code:

cursor.execute("SELECT * FROM Workers WHERE Worker_Name LIKE ?", (letter + "%",))
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much! The first method was the one which worked for me. I had tried the second method earlier but it was giving me the same error.
@Animeartist If the second gave you an error, you probably tried LIKE '?' instead of LIKE ?. A question mark inside a string literal is not a parameter, it is just a string with a question mark.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.