In static SQL, you embed SQL statements (the SQL source) in a host language program and bind them before executing the program. This makes the statements static, that is, when you write the SQL source into the program, the format of the SQL statements are known to you and do not change when the program is executed. If you therefore know, when you write the program, the type of SQL statements (such as SELECT, UPDATE, INSERT) to be used and the table names and column names of the data to be accessed, static SQL efficiently provides what you need. But if your program requires complete flexibility, that is, if it needs to execute so many different types and structures of SQL statements that it is impossible for it to contain a model of each one, use dynamic SQL.
Do not think of static SQL as being totally unflexible. If your static SQL statements include host variables that your program changes, you can use static SQL and still enjoy a reasonable amount of flexibility. Consider the following COBOL example. Notice that the values of WRKRID and NEWPRAT are reset each time the UPDATE statement is re-executed, so that it updates the performance ratings of as many workers as required with whatever values are needed.
MOVE PRFRAT-7 TO NEWPRAT.
MOVE 000090 TO WRKRID.
EXEC SQL
UPDATE DRAKE06.WRK
SET RATING = :NEWPRAT
WHERE WRKNO = :WRKRID
END-EXEC.
|
Copyright © 2014 CA.
All rights reserved.
|
|