Embedded SQL

Each of the preprocessors works by taking the SQL statements that you have embedded in your COBOL program and converting them to the appropriate function calls to the database.

In your COBOL program, each embedded SQL statement must be preceded by the introductory keywords:

EXEC SQL

and followed by the keyword:

END-EXEC

For example:

     EXEC SQL
         SELECT au_lname INTO :lastname FROM authors
          WHERE au_id = '124-59-3864'
     END-EXEC

The embedded SQL statement can be broken over as many lines as necessary following the normal COBOL rules for continuation, but between the EXEC SQL and END-EXEC keywords you can only code an embedded SQL statement, you cannot include any ordinary COBOL code.

Most vendors provide SQL Reference documentation with their database software which will include full information about embedded SQL statements but you should, for example, be able to perform the following typical operations using the statements shown:

Operation SQL Statement(s)
Add data to a table INSERT
Change data in a table UPDATE
Retrieve a row of data from a table SELECT
Create a named cursor DECLARE CURSOR
Retrieve multiple rows of data using a cursor OPEN, FETCH, CLOSE

A full syntax description is given for each of the embedded SQL statements, together with an example of its use, in the topic Embedded SQL Statements.

Related information
Embedded SQL Statements