sql long python line is folded a plurality of rows and a plurality of process parameters

sql statement

There is a very long sql, editor written using open too long lead time to write very difficult, and prone to confusion, I want to do is to A, B, C three variables assigned to the fields in the sql to go.

A=1
B=2
C=3
 
sql = "update student t set t.name = '',t.sex = '',t.age = '',t.height = '',t.weight = '',t.class = '',t.stuid = '',t.xxx = '' where t.stuid= '' and t.xxx = '';"


Solution is as follows: after a plurality of rows folded wording

Parentheses may be strings each row by neat splice (), the string will automatically after each splicing the transport line, and each pass required parameter fields plus% S, before the end of the bracket with% (variable name, variable name, variable name) sequentially assigned. The final perfect solution.

A=1
B=2
C=3
sql = ("update student t set t.name = '%s',"
     "t.sex = '%s',"
     "t.age = '%s',"
     "t.height = '%s',"
     "t.weight = '%s',"
     "t.class = '%s',"
     "t.stuid = '%s',"
     "t.xxx = '%s'"
     " where t.stuid= '%s'"
     " and t.xxx = 'P';" %(A,B,A,B,B,A,A,B,C)
  )

 

Published 105 original articles · won praise 17 · views 110 000 +

Guess you like

Origin blog.csdn.net/qq_38890412/article/details/104264031