Site icon TechTricky: A Technology Blog on HTML, CSS, JQuery, Webaps and How to\'s

Dynamic SQL in DB2 COBOL

How to code Dynamic SQL(DS) in a COBOL DB2 Program

Dynamic SQL is prepared and executed at the run time as opposed to embedding it in the host language program as in a static  one.

Using dynamic SQL in the application programs has proved many advantages. For ex: In some cases the businesses requirement demands various predicates to be used in a SQL statement which may vary depending upon the requirement or the input PARM value (i.e; In one case, it requires only one predicate to be used and in another it may require more to be used). Dynamic SQL proved very convenient and effective to implement these type of business requirements.

It can be used where the SQL statements to be used in the select query are not known (or not fixed) before the execution of the application.

In general, an application that uses DS has a higher start-up (or initial) cost per SQL statement due to the need of compiling the statements before using them. Once compiled, the execution time for dynamic compared to static is more or less equal and, in some cases, faster due to better access plans being chosen by the optimizer. Each time a dynamic statement is executed, the initial compilation cost becomes less of a factor. If multiple users are running the same dynamic application with the same statements, only the first application to issue the statement realizes the cost of statement compilation.

More Info:

Static queries are hard-coded, and only the values of host variables in predicates can change. Dynamic SQL is characterized by its capability to change columns, tables, and predicates during a program’s execution. This flexibility requires different techniques for embedding dynamic SQL in application programs.

Notes:

Example and important parts will be discussed in the next topics.

Feel free to post via comments. if you have more information on this topic.

– Admin

Exit mobile version
Close Bitnami banner
Bitnami