| Programmer's Guide to the Oracle Pro*COBOL Precompiler
By checking the syntax and semantics of embedded SQL statements and PL/SQL blocks, the Oracle Precompilers help you quickly find and fix coding mistakes. This appendix shows you how to use the SQLCHECK option to control the type and extent of checking.
Rules of syntax specify how language elements are sequenced to form valid statements. Thus, syntactic checking verifies that keywords, object names, operators, delimiters, and so on are placed correctly in your SQL statement. For example, the following embedded SQL statements contain syntax errors:
* -- misspelled keyword WHERE
EXEC SQL DELETE FROM EMP WERE DEPTNO = 20 END-EXEC.
* -- missing parentheses around column names COMM and SAL
INSERT INTO EMP COMM, SAL VALUES (NULL, 1500)
Rules of semantics specify how valid external references are made. Thus, semantic checking verifies that references to database objects and host variables are valid and that host-variable datatypes are correct. For example, the following embedded SQL statements contain semantic errors:
* -- nonexistent table, EMPP
EXEC SQL DELETE FROM EMPP WHERE DEPTNO = 20 END-EXEC.
* -- undeclared host variable, EMP-NAME
EXEC SQL SELECT * FROM EMP WHERE ENAME = :EMP-NAME END-EXEC.
The rules of SQL syntax and semantics are defined in the Oracle8 Server SQL Reference.
You control the type and extent of checking by specifying the SQLCHECK option on the command line. With SQLCHECK, the type of checking can be syntactic, semantic, or both. The extent of checking can include data manipulation statements and PL/SQL blocks. However, SQLCHECK cannot check dynamic SQL statements because they are not defined fully until run time.
You can specify the following values for SQLCHECK:
The values SEMANTICS and FULL are equivalent, as are the values SYNTAX and LIMITED. The default value is SYNTAX.
When SQLCHECK=SEMANTICS, the precompiler checks the syntax and semantics of
However, the precompiler checks only the syntax of remote data manipulation statements (those using the AT db_name clause).
The precompiler gets the information for a semantic check from embedded DECLARE TABLE statements or, if you specify the option USERID, by connecting to Oracle8 and accessing the data dictionary. You need not connect to Oracle8 if every table referenced in a data manipulation statement or PL/SQL block is defined in a DECLARE TABLE statement.
If you connect to Oracle8 but some information cannot be found in the data dictionary, you must use DECLARE TABLE statements to supply the missing information. A DECLARE TABLE definition overrides a data dictionary definition if they conflict.
When checking data manipulation statements, the precompiler uses the Oracle8 set of syntax rules found in the Oracle8 Server SQL Reference but uses a stricter set of semantic rules. As a result, existing applications written for earlier versions of Oracle might not precompile successfully when SQLCHECK=SEMANTICS.
Specify SQLCHECK=SEMANTICS when precompiling new programs. If you embed PL/SQL blocks in a host program, you must specify SQLCHECK=SEMANTICS.
When SQLCHECK=SEMANTICS, the precompiler can get information needed for a semantic check in either of the following ways:
To do a semantic check, the precompiler can connect to an Oracle8 database that maintains definitions of tables and views referenced in your host program. After connecting to Oracle8, the precompiler accesses the data dictionary for needed information. The data dictionary stores table and column names, table and column constraints, column lengths, column datatypes, and so on.
If some of the needed information cannot be found in the data dictionary (because your program refers to a table not yet created, for example), you must supply the missing information using the DECLARE TABLE statement.
To connect to Oracle8, specify the option USERID on the command line, using the syntax
where username and password comprise a valid Oracle8 userid. If you omit the password, you are prompted for it. If, instead of a username and password, you specify
the precompiler tries to connect to Oracle8 automatically with the userid
where prefix is the value of the Oracle8 initialization parameter OS_AUTHENT_PREFIX (the default value is OPS$) and username is your operating system user or task name.
If you try connecting to Oracle8 but cannot (for example, if the database is unavailable), the precompiler stops processing and issues an error message. If you omit the option USERID, the precompiler must get needed information from embedded DECLARE TABLE statements.
The precompiler can do a semantic check without connecting to Oracle8. To do the check, the precompiler must get information about tables and views from embedded DECLARE TABLE statements. Thus, every table referenced in a data manipulation statement or PL/SQL block must be defined in a DECLARE TABLE statement.
The syntax of the DECLARE TABLE statement is
EXEC SQL DECLARE table_name TABLE
(col_name col_datatype [DEFAULT expr] [NULL|NOT NULL], ...)
where expr is any expression that can be used as a default column value in the CREATE TABLE statement. col_datatype is an Oracle column declaration. Only integers can be used, not expressions. See "DECLARE TABLE (Oracle Embedded SQL Directive)" on page F-20.
If you use DECLARE TABLE to define a database table that already exists, the precompiler uses your definition, ignoring the one in the data dictionary.