SoFunction
Updated on 2024-11-18

python one line of sql is too long folded into multiple lines and have multiple parameters of the method

sql statement

There is a very long sql, with the editor to open the preparation of the time is too long to lead to the preparation of a very strenuous, and easy to mess up, I want to do is to A,B,C three variables assigned to the field in the sql to go!

A=1
B=2
C=3

sql = "update student t set  = '', = '', = '', = '', = '', = '', = '', = '' where = '' and  = '';"

written after many lines have been folded

The solution is as follows:

You can use () parentheses to neatly splice the strings on each line, and after the carriage return, you will automatically splice the strings on each line, and add %s to each field that needs to be passed as a parameter, and before the end of the parentheses, you will use %(variable name, variable name, variable name) to assign the value in turn. It worked perfectly in the end.

A=1
B=2
C=3
sql = ("update student t set  = '%s',"
     " = '%s',"
     " = '%s',"
     " = '%s',"
     " = '%s',"
     " = '%s',"
     " = '%s',"
     " = '%s'"
     " where = '%s'"
     " and  = 'P';" %(A,B,A,B,B,A,A,B,C)
  )

Above this python line sql is too long folded into multiple lines and have multiple parameters is all that I have shared with you, I hope to give you a reference, and I hope you support me more.