Programmer's Guide to the Pro*C/C++ Precompiler | ![]() Library |
![]() Product |
![]() Contents |
![]() Index |
EXEC SQL DELETE FROM EMP WHER DEPTNO = 20;
-- misspelled keyword WHERE
EXEC SQL INSERT INTO EMP COMM, SAL VALUES (NULL, 1500);
-- missing parentheses around column names COMM and SAL
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:
EXEC SQL DELETE FROM empp WHERE deptno = 20;
-- nonexistent table, EMPP
EXEC SQL SELECT * FROM emp WHERE ename = :emp_name;
-- undeclared host variable, emp_name
The rules of SQL syntax and semantics are defined in the Oracle7 Server SQL Reference.
You can specify the following values for SQLCHECK:
The use of SQLCHECK does not affect the normal syntax checking done on data control, cursor control, and dynamic SQL statements.
When SQLCHECK=SEMANTICS, the precompiler gets information needed for a semantic check by using embedded DECLARE TABLE statements or if you specify the USERID option on the command line, by connecting to Oracle and accessing the data dictionary. You need not connect to Oracle if every table referenced in a data manipulation statement or PL/SQL block is defined in a DECLARE TABLE statement.
If you connect to Oracle, but some needed 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.
If you embed PL/SQL blocks in a host program, you must specify SQLCHECK=SEMANTICS.
When checking data manipulation statements, the precompiler uses the Oracle7 set of syntax rules found in the Oracle7 Server SQL Reference, but uses a stricter set of semantic rules. In particular, stricter datatype checking is done. As a result, existing applications written for earlier versions of Oracle might not precompile successfully when SQLCHECK=SEMANTICS.
Specify SQLCHECK=SEMANTICS when you precompile new programs or want stricter datatype checking.
After connecting to Oracle, 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 (discussed later in this appendix).
To connect to Oracle, specify the USERID option on the command line, using the syntax
USERID=username/password
where username and password comprise a valid Oracle userid. If you omit the password, you are prompted for it.
If, instead of a username and password, you specify
USERID=/
the precompiler attempts to automatically connect to Oracle. The attempt succeeds only if an existing Oracle username matches your operating system ID prefixed with "OPS$'', or whatever value the parameter OS_AUTHENT_PREFIX is set to in the INIT.ORA file. For example, if your operating system ID is MBLAKE, an automatic connect only succeeds if OPS$MBLAKE is a valid Oracle username.
If you omit the USERID option, the precompiler must get needed information from embedded DECLARE TABLE statements.
If you try connecting to Oracle but cannot (because the database is unavailable, for example), an error message is issued and your program is not precompiled.
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.
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.
![]() ![]() Prev Next |
![]() Copyright © 1997 Oracle Corporation. All Rights Reserved. |
![]() Library |
![]() Product |
![]() Contents |
![]() Index |