Pro*C/C++ Programmer's Guide Release 9.2 Part Number A97269-03 |
|
|
View PDF |
This document is a comprehensive user's guide and reference to the Pro*C/C++. It shows you how to use the database language SQL and Oracle's procedural extension, PL/SQL, in conjunction with Pro*C/C++ to manipulate data in an Oracle database. It explores a full range of topics, from underlying concepts to advanced programming techniques, and provides code examples.
This Preface contains these topics:
The Pro*C/C++ Programmer's Guide is intended for programmers, systems analysts, project managers, and other Oracle users who perform, or are interested in learning about, the following tasks:
Design and develop software applications in the Oracle environment.
Convert existing software applications to run in an Oracle environment.
Manage the development of software applications.
To use this document, you need a working knowledge of applications programming in C and C++, and familiarity with the use of the Structured Query Language (SQL).
Our goal is to make Oracle products, services, and supporting documentation accessible, with good usability, to the disabled community. To that end, our documentation includes features that make information available to users of assistive technology. This documentation is available in HTML format, and contains markup to facilitate access by the disabled community. Standards will continue to evolve over time, and Oracle is actively engaged with other market-leading technology vendors to address technical obstacles so that our documentation can be accessible to all of our customers. For additional information, visit the Oracle Accessibility Program Web site at
http://www.oracle.com/accessibility/
JAWS, a Windows screen reader, may not always correctly read the code examples in this document. The conventions for writing code require that closing braces should appear on an otherwise empty line; however, JAWS may not always read a line of text that consists solely of a bracket or brace.
This documentation may contain links to Web sites of other companies or organizations that Oracle does not own or control. Oracle neither evaluates nor makes any representations regarding the accessibility of these Web sites.
This document contains:
This chapter introduces you to Pro*C/C++. You look at its role in developing application programs that manipulate Oracle data. There is a Frequently Asked Questions section which is important.
This chapter explains how embedded SQL programs work. Programming guidelines follow. Then the sample tables that we work with are shown, along with a sample query Pro*C/C++ application
This chapter describes transaction processing. You learn the basic techniques that safeguard the consistency of your database and how to connect to the database server.
You learn about the Oracle datatypes, host variables, indicator variables, data conversion, Unicode character strings.
This chapter presents advanced topics, such as how to take advantage of datatype equivalencing, C preprocessor support, new names for SQLLIB functions, and interfacing to OCI.
This chapter teaches you the essentials of embedded SQL programming. You learn how to use host variables, indicator variables, cursors, cursor variables, and the fundamental SQL commands that insert, update, select, and delete Oracle data.
This chapter shows you how to improve performance by embedding PL/SQL transaction processing blocks in your program. You learn how to use PL/SQL with host variables, indicator variables, cursors, stored procedures, host arrays, and dynamic SQL.
This chapter looks at using arrays to improve program performance. You learn how to manipulate Oracle data using arrays, how to operate on all elements of an array with a single SQL statement, and how to limit the number of elements processed.
This chapter discusses error reporting and recovery. It shows you how to use the SQLSTATE and SQLCODE status variables with the WHENEVER statement to detect errors and status changes. It also shows you how to use the SQLCA and ORACA to detect error conditions and diagnose problems.
This chapter details the requirements for running the Oracle Pro*C/C++ Precompiler. You learn what happens during precompilation, how to issue the precompiler command, and how to specify the many useful precompiler options.
Writing multithreaded applications is discussed in this chapter. Your compiler must also support multithreading.
This chapter describes how to precompile your C++ application, and lists three sample C++ programs.
This chapter shows you how to take advantage of dynamic SQL. You are taught three methods—from simple to complex—for writing flexible programs that, among other things, let users build SQL statements interactively at run time.
The new ANSI dynamic SQL should be used for all new method 4 applications (where your program accepts or builds SQL statements with a varying number of variables). ANSI dynamic SQL must be used for applications involving complex types such as object types, collections, cursor variables, arrays of structs, and LOBs.
This chapter gives you an in-depth explanation of Dynamic SQL Method 4—dynamic SQL using descriptors. This will tell you how to modify existing applications that were developed before Oracle release 8.1.
This chapter presents large object datatypes (BLOBs, CLOBs, NCLOBs, and BFILEs). The embedded SQL commands that provide functionality comparable to OCI and PL/SQL are presented and used in sample code.
This chapter describes object support features: associative and navigational interfaces (embedded SQL commands), precompiler options for objects, and restrictions on the use of datatypes in Oracle dynamic SQL.
Collection types (VARRAYS and nested tables) are described in this chapter. Embedded SQL statements for using collections are presented, with examples.
This chapter discusses the Object Type Translator (OTT) which maps object types to C structures that are used in Pro*C/C++ applications. Then it describes the OTT options, how to use OTT, and the results.
This chapter focuses on writing user exits for Oracle Tools applications. You learn about the commands that are used to interface between a forms application and a Pro*C/C++ user exit, and how to write and link a forms user exit.
This appendix highlights the improvements and new features introduced with the 9i release of Pro*C/C++, and where to find them in this guide.
This appendix points you to where to find reserved words and keywords that have a special meaning to Oracle and namespaces that are reserved for Oracle libraries.
This appendix shows you some simple, easy-to-apply methods for improving the performance of your applications.
This appendix shows you how to use the SQLCHECK option to control the type and extent of syntactic and semantic checking done on embedded SQL statements and PL/SQL blocks.
This appendix documents the aspects of Pro*C/C++ that can be system-specific.
This appendix contains descriptions (syntax diagrams, keyword and parameter definitions) of precompiler directives, embedded SQL statements, and Oracle's embedded SQL extensions.
For more information, see these Oracle resources:
Many of the examples in this book use the sample schemas of the seed database, which is installed by default when you install Oracle. Refer to Oracle Database Sample Schemas for information on how these schemas were created and how you can use them yourself.
Printed documentation is available for sale in the Oracle Store at
http://oraclestore.oracle.com/
To download free release notes, installation documentation, white papers, or other collateral, please visit the Oracle Technology Network (OTN). You must register online before using OTN; registration is free and can be done at
http://otn.oracle.com/membership/
If you already have a username and password for OTN, then you can go directly to the documentation section of the OTN Web site at
http://otn.oracle.com/documentation/
This section describes the conventions used in the text and code examples of this documentation set. It describes:
We use various conventions in text to help you more quickly identify special terms. The following table describes those conventions and provides examples of their use.
Convention | Meaning | Example |
---|---|---|
Bold | Bold typeface indicates terms that are defined in the text or terms that appear in a glossary, or both. | When you specify this clause, you create an index-organized table. |
Italics | Italic typeface indicates book titles or emphasis. | Oracle Database Concepts
Ensure that the recovery catalog and target database do not reside on the same disk. |
UPPERCASE monospace (fixed-width) font |
Uppercase monospace typeface indicates elements supplied by the system. Such elements include parameters, privileges, datatypes, RMAN keywords, SQL keywords, SQL*Plus or utility commands, packages and methods, as well as system-supplied column names, database objects and structures, usernames, and roles. | You can specify this clause only for a NUMBER column.
You can back up the database by using the Query the Use the |
lowercase monospace (fixed-width) font |
Lowercase monospace typeface indicates executables, filenames, directory names, and sample user-supplied elements. Such elements include computer and database names, net service names, and connect identifiers, as well as user-supplied database objects and structures, column names, packages and classes, usernames and roles, program units, and parameter values.
Note: Some programmatic elements use a mixture of UPPERCASE and lowercase. Enter these elements as shown. |
Enter sqlplus to start SQL*Plus.
The password is specified in the Back up the datafiles and control files in the The Set the Connect as The |
lowercase italic monospace (fixed-width) font |
Lowercase italic monospace font represents placeholders or variables. | You can specify the parallel_clause .
Run |
Code examples illustrate SQL, PL/SQL, SQL*Plus, or other command-line statements. They are displayed in a monospace (fixed-width) font and separated from normal text as shown in this example:
SELECT username FROM dba_users WHERE username = 'MIGRATE';
The following table describes typographic conventions used in code examples and provides examples of their use.
Convention | Meaning | Example |
---|---|---|
[ ] |
Brackets enclose one or more optional items. Do not enter the brackets. |
DECIMAL (digits [ , precision ]) |
{ } |
Braces enclose two or more items, one of which is required. Do not enter the braces. |
{ENABLE | DISABLE} |
| |
A vertical bar represents a choice of two or more options within brackets or braces. Enter one of the options. Do not enter the vertical bar. |
{ENABLE | DISABLE} [COMPRESS | NOCOMPRESS] |
... |
Horizontal ellipsis points indicate either:
|
CREATE TABLE ... AS subquery; SELECT col1, col2, ... , coln FROM employees; |
. . . |
Vertical ellipsis points indicate that we have omitted several lines of code not directly related to the example. |
SQL> SELECT NAME FROM V$DATAFILE; NAME ------------------------------------ /fsl/dbs/tbs_01.dbf /fs1/dbs/tbs_02.dbf . . . /fsl/dbs/tbs_09.dbf 9 rows selected. |
Other notation | You must enter symbols other than brackets, braces, vertical bars, and ellipsis points as shown. |
acctbal NUMBER(11,2); acct CONSTANT NUMBER(4) := 3; |
Italics |
Italicized text indicates placeholders or variables for which you must supply particular values. |
CONNECT SYSTEM/system_password DB_NAME = database_name |
UPPERCASE |
Uppercase typeface indicates elements supplied by the system. We show these terms in uppercase in order to distinguish them from terms you define. Unless terms appear in brackets, enter them in the order and with the spelling shown. However, because these terms are not case sensitive, you can enter them in lowercase. |
SELECT last_name, employee_id FROM employees; SELECT * FROM USER_TABLES; DROP TABLE hr.employees; |
lowercase |
Lowercase typeface indicates programmatic elements that you supply. For example, lowercase indicates names of tables, columns, or files.
Note: Some programmatic elements use a mixture of UPPERCASE and lowercase. Enter these elements as shown. |
SELECT last_name, employee_id FROM employees; sqlplus hr/hr CREATE USER mjones IDENTIFIED BY ty3MU9; |