First of all, the so-called SQL dynamic and static, refers to when SQL statements are compiled and executed, both are used in SQL embedded programming, which is referred to as embedded refers to the SQL statement embedded in the high-level language, rather than the type of microcontroller embedded programming.
In a high-level language, if an SQL statement is embedded, and the main structure of the SQL statement is clear, for example, there is a SQL "select * from T1 where c1>5" to execute in a piece of Java code, in the Java compilation phase, You can pass this SQL to the database management system to analyze, the database software can parse this SQL, generate database executable code, such SQL is called Static SQL, that is, in the compilation phase can determine what the database to do.
And if the embedded SQL is not explicitly given, such as a variable sql:string SQL that defines a string type in Java, then executes the SQL using the Execute method of the PreparedStatement object, The value of the SQL may be equal to one SQL read from the text box or SQL entered from the keyboard, but what is not determined at compile time, only wait until the program is run, in the process of execution can be determined, this SQL is called Dynamic SQL. For example, each database software has the ability to execute the SQL statement interface, the interface received SQL is dynamic SQL, because the database vendors do this interface, do not know what the user will enter the SQL, only after the interface executes, the user's actual input, only to know what SQL is.
Also note that in SQL if some parameters are not determined, such as "select * from T1 where C1> and c2< ", this statement is static SQL, not dynamic SQL, although the value of the individual parameters is not known, but the entire SQL structure has been determined that the database can be compiled, in the execution phase only need to add the values of individual parameters.
The difference between dynamic SQL and static SQL