没有合适的资源?快使用搜索试试~ 我知道了~
首页Oracle11g Pro*C/C++ Programmer's Guide
"Oracle11g_Help"
《Oracle11g Pro*C/C++ Programmer's Guide》是Oracle公司为开发者提供的一份详尽指南,专注于11g Release 1 (11.1) 版本的Pro*C/C++编程。这本书由Deepti Kamal作为主要作者,并有多位贡献者共同编写,出版于2008年4月。文档涵盖了版权信息以及对程序和文档的使用和披露的限制,同时强调了反向工程、拆卸或反编译程序(除非法律另有规定或为了与其他独立创建的软件实现互操作性)是被禁止的。
Pro*C/C++是Oracle提供的一种预编译器,它允许开发人员使用C或C++语言来编写数据库应用程序,同时充分利用Oracle数据库的功能。在Oracle 11g中,Pro*C/C++提供了以下关键知识点:
1. **预编译过程**:Pro*C/C++将包含PL/SQL块的C/C++源代码转换为标准的C/C++代码,这样可以在运行时与Oracle数据库进行交互。预编译器处理PL/SQL语法,将其转化为与C/C++代码兼容的形式。
2. **数据类型映射**:Pro*C/C++定义了如何将Oracle数据库的数据类型映射到C/C++中的数据类型,使得开发者可以方便地在C/C++代码中操作数据库数据。
3. **游标管理**:Pro*C/C++支持Oracle的游标机制,允许开发人员逐行处理查询结果,提供了一种高效且灵活的方式来遍历和操作数据。
4. **错误处理**:通过使用Oracle的异常处理机制,Pro*C/C++允许开发者捕获和处理数据库操作中可能出现的错误。
5. **动态SQL**:Pro*C/C++支持动态SQL,允许在运行时构建和执行SQL语句,增强了程序的灵活性。
6. **绑定变量和定义变量**:绑定变量是提高性能的关键,它们允许多次使用相同的SQL语句但用不同的值。Pro*C/C++提供了绑定变量和定义变量的方法。
7. **事务控制**:在C/C++代码中,Pro*C/C++提供了对Oracle事务开始、提交和回滚的支持,确保数据的一致性和完整性。
8. **连接管理**:包括建立、管理和关闭数据库连接的函数,如`OCILogon`和`OCILogoff`。
9. **游标变量**:游标变量是存储游标位置的特殊变量,可以用于在PL/SQL块和C/C++之间传递数据。
10. **包和过程调用**:Pro*C/C++支持调用已定义在数据库中的存储过程和包,使C/C++代码能够利用Oracle的存储逻辑。
通过这份指南,开发者可以学习如何有效地利用Pro*C/C++工具来开发高效、可靠的Oracle数据库应用程序。书中详细介绍了各种示例和最佳实践,帮助读者掌握在11g环境中使用C/C++与Oracle数据库交互的技巧。
xvi
10.2.6.1 Configuration File...................................................................................................... 10-5
10.2.6.2 CODE........................................................................................................................... 10-5
10.2.6.3 DBMS........................................................................................................................... 10-5
10.2.6.4 INCLUDE ................................................................................................................... 10-5
10.2.6.5 PARSE ......................................................................................................................... 10-6
10.3 Quick Reference ....................................................................................................................... 10-6
10.4 Entering Options...................................................................................................................... 10-8
10.4.1 On the Command Line..................................................................................................... 10-8
10.4.2 Inline................................................................................................................................... 10-8
10.4.2.1 Uses for EXEC ORACLE........................................................................................... 10-9
10.4.2.2 Scope of EXEC ORACLE.......................................................................................... 10-9
10.5 Using the Precompiler Options ............................................................................................. 10-9
10.5.1 AUTO_CONNECT......................................................................................................... 10-10
10.5.2 CHAR_MAP.................................................................................................................... 10-10
10.5.3 CINCR .............................................................................................................................. 10-11
10.5.4 CLOSE_ON_COMMIT .................................................................................................. 10-11
10.5.5 CMAX............................................................................................................................... 10-12
10.5.6 CMIN................................................................................................................................ 10-12
10.5.7 CNOWAIT....................................................................................................................... 10-12
10.5.8 CODE................................................................................................................................ 10-13
10.5.9 COMMON_PARSER...................................................................................................... 10-13
10.5.10 COMP_CHARSET .......................................................................................................... 10-14
10.5.11 CONFIG ........................................................................................................................... 10-14
10.5.12 CPOOL ............................................................................................................................. 10-15
10.5.13 CPP_SUFFIX.................................................................................................................... 10-15
10.5.14 CTIMEOUT...................................................................................................................... 10-15
10.5.15 DB2_ARRAY ................................................................................................................... 10-16
10.5.16 DBMS................................................................................................................................ 10-16
10.5.17
DEF_SQLCODE .............................................................................................................. 10-17
10.5.18 DEFINE ............................................................................................................................ 10-18
10.5.19 DURATION..................................................................................................................... 10-19
10.5.20 DYNAMIC....................................................................................................................... 10-19
10.5.21 ERRORS............................................................................................................................ 10-19
10.5.22 ERRTYPE.......................................................................................................................... 10-20
10.5.23 EVENTS............................................................................................................................ 10-20
10.5.24 FIPS ................................................................................................................................... 10-20
10.5.25 HEADER .......................................................................................................................... 10-21
10.5.26 HOLD_CURSOR............................................................................................................. 10-22
10.5.27 IMPLICIT_SVPT ............................................................................................................. 10-23
10.5.28 INAME ............................................................................................................................. 10-23
10.5.29 INCLUDE......................................................................................................................... 10-24
10.5.30 INTYPE............................................................................................................................. 10-25
10.5.31 LINES................................................................................................................................ 10-25
10.5.32 LNAME ............................................................................................................................ 10-26
10.5.33 LTYPE............................................................................................................................... 10-26
10.5.34 MAX_ROW_INSERT...................................................................................................... 10-27
10.5.35 MAXLITERAL................................................................................................................. 10-27
xvii
10.5.36 MAXOPENCURSORS.................................................................................................... 10-28
10.5.37 MODE............................................................................................................................... 10-29
10.5.38 NATIVE_TYPES.............................................................................................................. 10-29
10.5.39 NLS_CHAR ..................................................................................................................... 10-30
10.5.40 NLS_LOCAL ................................................................................................................... 10-30
10.5.41 OBJECTS........................................................................................................................... 10-30
10.5.42 ONAME ........................................................................................................................... 10-31
10.5.43 ORACA ............................................................................................................................ 10-31
10.5.44 OUTLINE......................................................................................................................... 10-32
10.5.45 OUTLNPREFIX............................................................................................................... 10-32
10.5.46 PAGELEN........................................................................................................................ 10-33
10.5.47 PARSE............................................................................................................................... 10-33
10.5.48 PREFETCH ...................................................................................................................... 10-34
10.5.49 RELEASE_CURSOR....................................................................................................... 10-34
10.5.50 RUNOUTLINE................................................................................................................ 10-35
10.5.51 SELECT_ERROR............................................................................................................. 10-36
10.5.52 STMT_CACHE................................................................................................................ 10-36
10.5.53 SYS_INCLUDE................................................................................................................ 10-36
10.5.54 THREADS........................................................................................................................ 10-38
10.5.55 TYPE_CODE.................................................................................................................... 10-38
10.5.56 UNSAFE_NULL.............................................................................................................. 10-39
10.5.57 USERID ............................................................................................................................ 10-39
10.5.58 UTF16_CHARSET........................................................................................................... 10-40
10.5.59 VARCHAR....................................................................................................................... 10-40
10.5.60 VERSION ......................................................................................................................... 10-41
11 Multithreaded Applications
11.1 What are Threads?................................................................................................................... 11-1
11.2 Runtime Contexts in Pro*C/C++ .......................................................................................... 11-2
11.3 Runtime Context Usage Models............................................................................................ 11-3
11.3.1 Multiple Threads Sharing a Single Runtime Context.................................................. 11-3
11.3.2 Multiple Threads Sharing Multiple Runtime Contexts............................................... 11-4
11.4 User Interface Features for Multithreaded Applications................................................... 11-5
11.4.1 THREADS Option............................................................................................................. 11-5
11.4.2 Embedded SQL Statements and Directives.................................................................. 11-6
11.4.2.1 EXEC SQL ENABLE THREADS.............................................................................. 11-6
11.4.2.2 EXEC SQL CONTEXT ALLOCATE........................................................................ 11-6
11.4.2.3 EXEC SQL CONTEXT USE...................................................................................... 11-6
11.4.2.4 EXEC SQL CONTEXT FREE.................................................................................... 11-7
11.4.3 CONTEXT USE Examples............................................................................................... 11-8
11.4.4 Programming Considerations......................................................................................... 11-9
11.5 Multithreaded Example .......................................................................................................... 11-9
11.6 Connection Pooling ............................................................................................................... 11-15
11.6.1 Using the Connection Pooling Feature........................................................................ 11-16
11.6.1.1 How to Enable Connection Pooling...................................................................... 11-16
11.6.1.2 Command Line Options for Connection Pooling............................................... 11-16
11.6.1.3 Example..................................................................................................................... 11-18
xviii
11.6.1.4 Performance Tuning................................................................................................ 11-18
11.6.2 Demo Program:1............................................................................................................. 11-18
11.6.2.1 Example..................................................................................................................... 11-19
11.6.3 Demo Program:2............................................................................................................. 11-23
11.6.3.1 Case 1: By varying CMIN....................................................................................... 11-24
11.6.3.2 Case 2: By varying CMAX...................................................................................... 11-24
11.6.3.3 Example..................................................................................................................... 11-25
12 C++ Applications
12.1 Understanding C++ Support.................................................................................................. 12-1
12.1.1 No Special Macro Processing.......................................................................................... 12-2
12.2 Precompiling for C++.............................................................................................................. 12-2
12.2.1 Code Generation............................................................................................................... 12-2
12.2.2 Parsing Code ..................................................................................................................... 12-3
12.2.3 Output Filename Extension............................................................................................. 12-4
12.2.4 System Header Files ........................................................................................................ 12-4
12.3 Example Programs................................................................................................................... 12-4
12.3.1 cppdemo1.pc ..................................................................................................................... 12-4
12.3.2 cppdemo2.pc ..................................................................................................................... 12-7
12.3.3 cppdemo3.pc ................................................................................................................ 12-10
13 Oracle Dynamic SQL
13.1 What is Dynamic SQL? ........................................................................................................... 13-1
13.2 Advantages and Disadvantages of Dynamic SQL.............................................................. 13-2
13.3 When to Use Dynamic SQL.................................................................................................... 13-2
13.4 Requirements for Dynamic SQL Statements ...................................................................... 13-2
13.5 How Dynamic SQL Statements are Processed ................................................................... 13-3
13.6 Methods for Using Dynamic SQL ........................................................................................ 13-3
13.6.1 Method 1 ........................................................................................................................... 13-4
13.6.2 Method 2 ........................................................................................................................... 13-4
13.6.3 Method 3 ........................................................................................................................... 13-4
13.6.4 Method 4 ........................................................................................................................... 13-4
13.6.5 Guidelines ......................................................................................................................... 13-4
13.6.5.1 Avoiding Common Errors ....................................................................................... 13-5
13.7 Using Method 1 ....................................................................................................................... 13-6
13.7.1 Example Program: Dynamic SQL Method 1 ................................................................ 13-7
13.8 Using Method 2 ....................................................................................................................... 13-9
13.8.1 The USING Clause ......................................................................................................... 13-10
13.8.2 Example Program: Dynamic SQL Method 2 .............................................................. 13-11
13.9 Using Method 3 ..................................................................................................................... 13-14
13.9.1 PREPARE ........................................................................................................................ 13-14
13.9.2 DECLARE ....................................................................................................................... 13-15
13.9.3 OPEN ............................................................................................................................... 13-15
13.9.4 FETCH ............................................................................................................................. 13-15
13.9.5 CLOSE ............................................................................................................................. 13-16
13.9.6 Example Program: Dynamic SQL Method 3 .............................................................. 13-16
13.10 Using Method 4 ..................................................................................................................... 13-19
xix
13.10.1 Need for the SQLDA .................................................................................................... 13-19
13.10.2 The DESCRIBE Statement ............................................................................................ 13-20
13.10.3 What is a SQLDA? ......................................................................................................... 13-20
13.10.4 Implementing Oracle Method 4 ................................................................................... 13-21
13.10.5 Restriction ........................................................................................................................ 13-21
13.11 Using the DECLARE STATEMENT Statement ................................................................ 13-21
13.11.1 Using Host Arrays ......................................................................................................... 13-22
13.12 Using PL/SQL ....................................................................................................................... 13-22
13.12.1 With Method 1 ................................................................................................................ 13-23
13.12.2 With Method 2 ................................................................................................................ 13-23
13.12.3 With Method 3 ................................................................................................................ 13-23
13.12.4 With Oracle Method 4 ................................................................................................... 13-23
13.13 Dynamic SQL Statement Caching ....................................................................................... 13-24
14 ANSI Dynamic SQL
14.1 Basics of ANSI Dynamic SQL ................................................................................................ 14-1
14.1.1 Precompiler Options ........................................................................................................ 14-2
14.2 Overview of ANSI SQL Statements ...................................................................................... 14-2
14.2.1 Example Code ................................................................................................................... 14-5
14.3 Oracle Extensions..................................................................................................................... 14-5
14.3.1 Reference Semantics......................................................................................................... 14-6
14.3.2 Using Arrays for Bulk Operations ................................................................................. 14-6
14.3.3 Support for Arrays of Structs.......................................................................................... 14-8
14.3.4 Support for Object Types................................................................................................. 14-8
14.4 ANSI Dynamic SQL Precompiler Options........................................................................... 14-8
14.5 Full Syntax of the Dynamic SQL Statements ....................................................................... 14-9
14.5.1 ALLOCATE DESCRIPTOR........................................................................................... 14-10
14.5.2 DEALLOCATE DESCRIPTOR...................................................................................... 14-10
14.5.3 GET DESCRIPTOR ......................................................................................................... 14-11
14.5.4 SET DESCRIPTOR.......................................................................................................... 14-14
14.5.5 Use of PREPARE............................................................................................................. 14-17
14.5.6 DESCRIBE INPUT .......................................................................................................... 14-17
14.5.7 DESCRIBE OUTPUT ...................................................................................................... 14-18
14.5.8 EXECUTE......................................................................................................................... 14-18
14.5.9 Use of EXECUTE IMMEDIATE.................................................................................... 14-19
14.5.10 Use of DYNAMIC DECLARE CURSOR ..................................................................... 14-19
14.5.11 OPEN Cursor................................................................................................................... 14-20
14.5.12 FETCH.............................................................................................................................. 14-20
14.5.13 CLOSE a Dynamic Cursor............................................................................................. 14-21
14.5.14 Differences From Oracle Dynamic Method 4............................................................. 14-21
14.5.15 Restrictions ...................................................................................................................... 14-22
14.6 Example Programs................................................................................................................. 14-22
14.6.1 ansidyn1.pc...................................................................................................................... 14-22
14.6.2 ansidyn2.pc...................................................................................................................... 14-29
xx
15 Oracle Dynamic SQL: Method 4
15.1 Meeting the Special Requirements of Method 4 ................................................................. 15-1
15.1.1 What Makes Method 4 Special? ..................................................................................... 15-2
15.1.2 What Information Does Oracle Need? .......................................................................... 15-2
15.1.3 Where Is the Information Stored? ................................................................................. 15-2
15.1.4 How is the SQLDA Referenced? .................................................................................... 15-3
15.1.5 How is the Information Obtained? ............................................................................... 15-3
15.2 Understanding the SQLDA ................................................................................................... 15-3
15.2.1 Purpose of the SQLDA .................................................................................................... 15-3
15.2.2 Multiple SQLDAs ............................................................................................................ 15-4
15.2.3 Declaring a SQLDA ......................................................................................................... 15-4
15.2.4 Allocating a SQLDA ........................................................................................................ 15-4
15.3 Using the SQLDA Variables .................................................................................................. 15-5
15.3.1 The N Variable .................................................................................................................. 15-5
15.3.2 The V Variable .................................................................................................................. 15-6
15.3.3 The L Variable .................................................................................................................. 15-6
15.3.4 The T Variable .................................................................................................................. 15-7
15.3.5 The I Variable ................................................................................................................... 15-7
15.3.6 The F Variable .................................................................................................................. 15-8
15.3.7 The S Variable .................................................................................................................. 15-8
15.3.8 The M Variable ................................................................................................................. 15-8
15.3.9 The C Variable .................................................................................................................. 15-8
15.3.10 The X Variable .................................................................................................................. 15-8
15.3.11 The Y Variable .................................................................................................................. 15-9
15.3.12 The Z Variable .................................................................................................................. 15-9
15.4 Some Preliminaries ................................................................................................................. 15-9
15.4.1 Converting Data ............................................................................................................... 15-9
15.4.1.1 Internal Datatypes .................................................................................................... 15-9
15.4.1.2 External Datatypes ................................................................................................. 15-10
15.4.2 Coercing Datatypes ....................................................................................................... 15-11
15.4.2.1 Extracting Precision and Scale .............................................................................. 15-12
15.4.3 Handling NULL/Not NULL Datatypes .................................................................... 15-13
15.5 The Basic Steps ...................................................................................................................... 15-14
15.6 A Closer Look at Each Step ................................................................................................. 15-15
15.6.1 Declare a Host String ..................................................................................................... 15-16
15.6.2 Declare the SQLDAs ...................................................................................................... 15-16
15.6.3 Allocate Storage Space for the Descriptors ................................................................ 15-17
15.6.4 Set the Maximum Number to DESCRIBE .................................................................. 15-17
15.6.5 Put the Query Text in the Host String ........................................................................ 15-19
15.6.6 PREPARE the Query from the Host String ................................................................ 15-19
15.6.7 DECLARE a Cursor ....................................................................................................... 15-20
15.6.8 DESCRIBE the Bind Variables ..................................................................................... 15-20
15.6.9 Reset Number of Placeholders ..................................................................................... 15-21
15.6.10 Get Values and Allocate Storage for Bind Variables ................................................ 15-21
15.6.11 OPEN the Cursor ........................................................................................................... 15-23
15.6.12 DESCRIBE the Select List .............................................................................................. 15-24
15.6.13 Reset Number of Select-List Items .............................................................................. 15-25
剩余779页未读,继续阅读
点击了解资源详情
342 浏览量
217 浏览量
2395 浏览量
117 浏览量
2023-08-10 上传
127 浏览量
217 浏览量
joeandlily
- 粉丝: 18
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功