Oracle8 的OCI常用函数及一部分参数说明

7 篇文章 0 订阅
5 篇文章 1 订阅

Oracle8的OCI常用函数

1. OCIHandleAlloc()

Purpose: This call returns a pointer to anpointer to an allocated and initialized handle.

语法原型:5个参数

         sword    OCIHandleAlloc(      CONST dvoid *          parent,

dvoid **                    hndlpp,

ub4                          type,

size_t                               xtramem_sz,

dvoid**                       usrmempp);

 

         type: Specifies the type of handle tobe allocated. The allowed types are:

         ·OCI_HTYPE_ERROR—specifies generation of an error handle of C typeOCIError.

2. OCIHandleFree()

用途:This call explicitly deallocates a handle.

原型:2个参数

         sword       OCIHandleFree(       dvoid*                hndlp,

                                                                 ub4                     type );

3. OCIServerAttach()

用途: Creates an access path to a datasource for OCI operations.

原型:

         sword       OCIServerAttach(    OCIServer*                srvhp,

OCIError*                           errhp,

CONST  text*                   dblink,

sb4                               dblink_len,

ub4                              mode        );

 

4. OCIServerDettach()

用途:Deletes an access to a data source for OCIoperations.

原型:

         Sword       OCIServerDetach(   OCIServer*                srvhp,

OCIError*                            errhp,

ub4                              mode        );

参数:

         Mode:Specifies the various modes of operation. The only valid mode is OCI_DEFAULTfor the default mode.

 

5. OCISessionBegin()

用途:Creates a user session and begins a user sessionfor a given server.

原型:5个参数

         Sword       OCISessionBegin(    OCISvcCtx*                svchp,

OCIError*                            errhp,

OCISession*              usrhp,

ub4                              credt,

ub4                              mode        )

参数:

        

Credt: Specifies the type of credentials touse for establishing the user session. Valid values for credt are:

·OCI_CRED_RDBMS—authenticate usinga database username and password pair as credentials. The attributesOCI_ATTR_USERNAME and OCI_ATTR_PASSWORD should be set on the user session contextbefore this call.

·OCI_CRED_EXT—authenticate usingexternal credentials. No username or password is provided.

 

6. OCISessionEnd()

 

用途:Terminates a user session context created byOCISessionBegin()

原型:4个参数

         Sword       OCISessionEnd          (      OCISvcCtx*                svchp,

                                                                 OCIError*                            errhp,

                                                                 OCISession*              usrhp,

                                                                 ub4                              mode        );

参数

         mode:The only valid mode is OCI_DEFAULT.

        

1.      OCIStmtPrepare()

用途:This call prepares a SQL or PL/SQLstatement for execution

语法原型:6个参数

         sword     OCIStmtPrepare (    OCIStmt *       stmtp,

                                                                 OCIError*        errhp,

                                                                 CONST text *  stmt,

                                                                 ub4                 stmt_len,

                                                                 ub4                 language,

                                                                 ub4                 mode);

 

language(IN):指明V7、V8或者native syntax,可能的值为:

           ·OCI_V7_SYNTAX—V7 ORACLE parsing syntax

           ·OCI_V8_SYNTAT—V8 ORACLE parsing syntax

           ·OCI_NTV_SYNTAX—syntax depends upon the version of the server.

mode(IN):

           Theonly defined mode is OCI_DEFAULT for default mode.

 

8. OCIStmtExecute()

Purpose: This call associated anapplication request with a server.

语法原型:8个参数

         Sword     OCIStmtExecute(    OCISvcCtx*                      svchp,

                                                               OCIStmt*                         stmtp,

                                                               OCIError*                       errhp,

                                                               ub4                             Iters,

                                                               ub4                                   rowoff,

                                                                 CONST OCISnapshot*   snap_in,

                                                                 OCISnapshot *               snap_out,

                                                                 ub4                                        mode);

参数:

         Iters: For non-SELECTstatements, the number of times this statement is executed is equal to iters-rowoff.

         ForSELECT statement, if iters is non-zero, then defines must have been done forthe statement handle. The execution fetches iters rows into these predefined buffers and prefetches more rowsdepending upon the prefetch row count. If you do not know how many rows theSELECT statement will retrieve, set iters to zero.

         Thisfunction returns an error if iters = 0 for non-SELECT statement.

         Rowoff:

         Thestarting index from which the data in an array bind is relevant for thismultiple row execution.

 

 

9. OCIBindByPos()

用途:Creates an association between a program variableand a placeholder in a SQL statement or PL/SQL block.

原型(Syntax):          13个参数

         Sword       OCIBindByPos (        OCIStmt*                   stmtp,

                                                                 OCIBind**        bindpp,

                                                                 OCIError*                  errhp,

                                                                 ub4                     position,

                                                                 dvoid*                valuep,

                                                                 sb4                     value_sz,

                                                                 ub2                     dty,

                                                                 dvoid*                indp,

                                                                 ub2*                   alenp,

                                                                 ub2*                   rcodep,

                                                                 ub4                     maxarr_len,

                                                                 ub4*                   curelep,

                                                                 ub4                     mode);

参数:

value_sz (IN)

The size of a data value. Inthe case of an array bind, this is the maximum size of

any element possible with theactual sizes being specified in the alenp parameter.

For descriptors, locators, orREFs, whose size is unknown to client applications use

the size of the structure you are passing in; e.g., sizeof (OCILobLocator*).

 

 

 

10.  OCIDefineByPos()

Purpose: Associates an item in aselect-list with the type and output data buffer.

语法原型:11个参数

         Sword  OCIDefineByPos(  OCIStmt*             stmtp,

                                                           OCIDefine**  defnpp,

                                                           OCIError*    errhp,

                                                           ub4                      position,

                                                           dvoid*                  valuep,

                                                           sb4                        value_sz,

                                                           ub2                       dty,

                                                           dvoid*                  indp,

                                                           ub2*                     rlenp,

                                                           ub2*                     rcodep,

                                                           ub4                       mode);

当获取LOB字段时,需要定义一个OCILobLocator的指针来获取LOB定位符(查询LOB字段返回的字段值是OCILobLocator),例如OCILobLocator* pLobLocator;OCIDefineByPos()函数获取字段值的程序变量的参数valuep,对于OCILobLocator须传递&pLobLocator,即指针的地址。

 

 

参数:

         Indp: 指示器变量指针,The datatype of indicatorvariables is sb2. In the case of arrays of indicator variables, the individualarray elements should be of type sb2.

         Rcodep:Pointer to array of column-level return code.字段级返回代码.

         Mode:The valid modes are:

         ·OCI_DEFAULT—this is the default mode.

         ·OCI_DYNAMIC_FETCH—For applicationsrequiring dynamically allocated data at the time of fetch, this mode must beused.

11. OCIDescriptorAlloc()

Purpose: Allocates storage to holddescriptors or LOB locators.

语法原型:5个参数

         sword  OCIDesriptorAlloc(    CONST dvoid*           parenth,

                                                                 dvoid**                       descpp,

                                                                 ub4                              type,

                                                                 size_t                          xtramem_sz,

                                                                 dvoid**                       usrmempp);

 

12. OCIStmtFetch()

Purpose: Fetches rows from a query.

语法原型:5个参数

         Sword  OCIStmtFetch(   OCIStmt*                   stmtp,      语句句柄statement handle

OCIError*                  errhp,       错误句柄 error handle

ub4                     nrows,

ub2                     orientation,

ub4                     mode);

nrows:         number of rows to be fetched from the currentposition.

Orientation:  Forrelease 8.0, the only acceptable value is OCI_FETCH_NEXT,

which isalso the default value.

                  mode:               For release 8.0, pass asOCI_DEFAULT.

 

13. OCITransCommit()

Purpose: Commits the transaction associatedwith a specified service context.

原型:

         Sword      OCITransCommit(    OCISvcCtx*      svchp,

                                                                 OCIError*                  errhp,

                                                                 ub4                     flags);

 

13. OCIAttrGet()

用途:This call is used to get a particularattribute of a handle.

语法原型:

         Sword       OCIAttrGet(     CONST dvoid*           trgthndlp,

                                                        ub4                              trghndltyp,

                                                        dvoid*                         attributep,

                                                        ub4*                            sizep,

                                                        ub4                              attrtype,          

例如OCI_ATTR_ROWID,OCI_ATTR_DATA_SIZE

                                                        OCIError*                           errhp);

 

 

14. OCIAttrSet()

Purpose: This call is used to set a particularattribute of a handle or a descriptor.

语法原型:6个参数

         Sword     OCIAttrSet( dvoid*           trghndlp,

                                                 ub4                trghndltyp,

                                               dvoid*           attributep,

                                                 ub4                size,

                                                 ub4                attrtype,

                                                 OCIError*    errhp);

 

15. OCIParamGet()

用途:Returns a descriptor of a parameter specifiedby position in the describe handle or statement handle.

原型:

         sword OCIParamGet(           CONST  dvoid*                 hndlpp,

                                                       ub4                                        htype,

                                                        OCIError*                                     errhp,

                                                        dvoid**                                parmdpp,

                                                        ub4                                        pos );

 

16. OCIDescribeAny()

用途:Describes existing schema objects.

原型:

         Sword OCIDescribeAny (   OCISvcCtx*               svchp,

                                                                 OCIError*                           errhp,

                                                                 Dvoid*                        objptr,

                                                                 Ub4                             objnm_len,

                                                                 Ub1                             objptr_typ,

                                                                 Ub1                             info_level,

                                                                 Ub1                             objtyp,

                                                                 OCIDescribe*           dschp  );

 

17. OCILobGetLength()

用途:Gets the length of a LOB/FILE.

语法原型:

         Sword       OCILobGetLength(  OCISvcCtx*                svchp,

                                                                 OCIError*                            errhp,

                                                                 OCILobLocator*       locp,

                                                                 ub4*                            lenp);

 

18. OCILobRead()

用途:Reads a portion of a LOB/FILE, as specifiedby the call, into a buffer.

语法原型(Syntax):

         Sword       OCILobRead(   OCISvcCtx*                         svchp,

                                                        OCIError*                                     errhp,

                                                        OCILobLocator*                locp,

                                                        ub4*                                     amtp,

                                                        ub4*                                     offset,

                                                        dvoid*                                  bufp,

                                                        ub4                                       bufl,

                                                        dvoid*                                  ctxp,

                                                        OCICallbackLobRead        (cbfp)

                                                                                                       (dvoid*                       ctxp,

                                                                                                        CONST dvoid*         bufp,

                                                                                                        Ub4                           len,

                                                                                                        Ub1                           piece)

                                                        Ub2                                       csid,

                                                        Ub1                                       csfrm);

 

参数:

         amtp: On input, the number ofcharacters (for CLOBs or NCLOBs) or bytes ( for BLOBs and BFILEs) to be read.On output, the actual number of bytes or characters read. If the amount ofbytes to be read is larger than the buffer length it is assumed that LOB isbeing read in a streamed mode from the input offset until the end of

 

 

19. OCILobWrite()

用途:Writes a buffer into a BLOB.

语法原型:  12个参数

                   swrod     OCILobWrite(  OCISvcCtx*                         svchp,

                                                                 OCIError*                                     errhp,

                                                                 OCILobLocator*                locp,

                                                                 ub4*                                     amtp,

                                                                 ub4                                        offset,

                                                                 dvoid*                                  bufp,

                                                                 ub4                                        buflen,

                                                                 ub1                                        piece,

                                                                 dvoid*                                  ctxp,

                                                                 OCICallbackLobWrite       (cbfp)

                                                                                                       (/*_

                                                                                                       dvoid*      ctxp,

                                                                                                       dvoid*      bufp,

                                                                                                       ub4*         lenp,

                                                                                                       ub1*         piecep      */)

                                                                 ub2                                        csid,

                                                                 ub1                                        csfrm );

 

参数:

        

 

         OCILobLocator*    locp:为OCILobLocator的指针。

         Dvoid*                      ctxp: the context for the callback function. Can be NULL. 

20. OC

 

21. da

 

 

 

六、Oracle8i8.1.7的常用函数

1. OCIEnvCreate()函数

用途:Creates andinitializes an environment for OCI functions to work under.

原型:

         Sword       OCIEnvCreate(         OCIEnv**                            envhpp,

Ub4                             mode,

CONST      dvoid*      ctxp,

CONST      dvoid*      (*malocfp)

(dvoid*     ctxp,

Size_t     size),

CONST      dvoid*      (*ralocfp)

(dvoid*     ctxp,

Dvoid*      memptr,

Size_t     size),

CONST      void           (*mfreefp)

(dvoid*     ctxp,

Dvoid*      memptr),

                                                        Size_t                          xtramemesz,

                                                        Dvoid**                      usrmempp        );

 

 

 

 

 

 

 

七、OCI的句柄和描述符属性

1. dfds

2. d

 

1.      Service Context Handle Attributes 服务上下文句柄属性

OCI_ATTR_SESSOIN属性

Mode: Read/Write

Description:When read, returns the pointer to the authentication context attribute of theservice.

When changed, sets the authenticationcontext attribute of the service context.

Attribute Datatype:

OCISession** (Read) / OCISession*(Write)

2.       

 

1.

2.

3. Ser

4.

5.

6. 语句句柄属性

OCI_ATTR_ROWID

MODE:  READ

描述(Discription):  Returns the rowid of the current row inserted, updated or fetched in acharacter string format. If execute had been a multiple row operation then, len should contain he iteration numberof the row

程序片段:

OCIRowid*       pRowid= NULL;                 //声明获取ROWID的OCIRowid* 描述符

//分配ROWID描述符

nRet = OCIDescriptorAlloc(     (dvoid*)pEnvHdl,                        (dvoid**)&pRowid,                                                                                     (ub4)OCI_DTYPE_ROWID,       (size_t)0,

                                                        (dvoid**)0        );

//获取ROWID

nRet = OCIAttrGet(          (dvoid*)pStmtHdl,                      (ub4)OCI_HTYPE_STMT,                            

(dvoid*)&pRowid,                      (ub4*)0,                     

(ub4)OCI_ATTR_ROWID,      (OCIError*)pErrorHdl);

//获取当前获取到的行的ROWID

int   nSize =          sizeof(OCIRowid*);           //获取OCIRowid的大小

 

2.        

3.        

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值