Explain the concept of DYNAMIC SQL in DB2 with the help of an example

A static SQL is hardcoded in COBOL-DB2 program and the SQL query cannot change during the program execution. We can only change the value of the host variables. In the case of DYNAMIC SQL, we can change the columns, tables and predicates in the COBOL-DB2 program in run time.

For example, based on the current date, we can update ORDERS or ORDERS_HIST table. This query can be built using DYNAMIC SQL which includes ORDERS table or ORDER_HIST table.

The main advantage of DYNAMIC SQL is its flexibility. We can add columns or change tables/predicates as per our business logic. On the other hand, the main disadvantage of DYNAMIC SQL is, they take more CPU and execution time as compared to STATIC SQL.

Updated on: 30-Nov-2020


Kickstart Your Career

Get certified by completing the course

Get Started