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?
sqlite3I'd recommend using prepared statements.:TABLENAMEwith%(TABLENAME)s, and then substitute likesql % {'TABLENAME': TABLENAME}. If you don't care about keywords, just use%sas mentioned below (however this introduces SQL-injection risks and prepared statements as mentioned by @Whymarrh would be the safest).