user1050619
user1050619

Reputation: 20856

Python string formatting error

I'm trying to bind a parameter in SQL:

sql = "SELECT COLUMN_NAME,DATA_TYPE FROM USER_TAB_COLS WHERE TABLE_NAME=UPPER(:TABLENAME)"
print 'TABLENAME=',TABLENAME
sqlqry = sql %(TABLENAME)

but get the string formatting error:

TypeError: not all arguments converted during string formatting

What could be the problem?

Upvotes: 0

Views: 145

Answers (2)

Bas Wijnen
Bas Wijnen

Reputation: 81

You really should post a bit more code for this to be entirely clear, but it looks like the string 'sql' doesn't contain any %-codes to be substituded. You are trying to substitude one value, but not all of those were used (in other words, nothing was substituted). You should use %s instead of :TABLENAME.

Upvotes: 0

The Unfun Cat
The Unfun Cat

Reputation: 31898

You are missing a placeholder in your string.

You want to replace :TABLENAME in the string sql with %s I suspect.

Upvotes: 1

Related Questions