Using dynamic SQL

A static SQL statement is one for which all the information is known at compile time. For example, the following SELECT statement is a static SQL statement because all information needed for its execution is present at compile time.
EXEC SQL select company into :cmp_name from customer where customer_num 
= 101;

However, in some applications the programmer does not know the contents, or possibly even the types, of SQL statements that the program needs to execute. For example, a program might prompt the user to enter a select statement, so that the programmer has no idea what columns are accessed when the program is run. Such applications require dynamic SQL. Dynamic SQL allows the HCL OneDB™ ESQL/C program to build an SQL statement at run time, so that the contents of the statement can be determined by user input.

These topics describe the following dynamic SQL information:
  • How to execute a dynamic SQL statement, the SQL statements to use, and the types of statements that you can execute dynamically
  • How to execute SQL statements when you know most of the information about the statement at compile time