Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
32
Добавлен:
16.04.2013
Размер:
4.96 Mб
Скачать

Passing Parameters to External C Procedures with Call Specifications

Table 8–2 (Cont.) External Datatype Mappings

 

 

If Mode is IN by

 

If Mode is IN

Reference or

External Datatype

RETURN by

or RETURN,

Reference,

Corresponding to

Specify in C

Specify in C

PL/SL Type

Prototype...

Prototype...

If Mode is IN OUT or OUT, Specify in C Prototype...

OCIDATE

OCIDate *

OCIDate *

OCIDate *

OCICOLL

OCIColl * or

OCIColl ** or

OCIColl ** or

 

OCIArray *,

OCIArray **, or

OCIArray **, or

 

or OCITable *

OCITable **

OCITable **

OCITYPE

OCIType *

OCIType *

OCIType *

TDO

OCIType *

OCIType *

OCIType *

ADT (final types)

dvoid*

dvoid*

dvoid*

ADT (non-final

dvoid*

dvoid*

dvoid**

types)

 

 

 

 

 

 

 

Composite object types are not self describing. Their description is stored in a Type Descriptor Object (TDO). Objects and indicator structs for objects have no predefined OCI datatype, but must use the datatypes generated by Oracle Database's Object Type Translator (OTT). The optional TDO argument for INDICATOR, and for composite objects, in general, has the C datatype, OCIType *.

OCICOLL for REF and collection arguments is optional and only exists for the sake of completeness. You cannot map REFs or collections onto any other datatype and vice versa.

BY VALUE/REFERENCE for IN and IN OUT Parameter Modes

If you specify BY VALUE, then scalar IN and RETURN arguments are passed by value (which is also the default). Alternatively, you may have them passed by reference by specifying BY REFERENCE.

By default, or if you specify BY REFERENCE, then scalar IN OUT, and OUT arguments are passed by reference. Specifying BY VALUE for IN OUT, and OUT arguments is not supported for C. The usefulness of the BY REFERENCE/VALUE clause is restricted to external datatypes that are, by default, passed by value. This is true for IN, and RETURN arguments of the following external types:

[UNSIGNED] CHAR

Calling External Procedures 8-23

Passing Parameters to External C Procedures with Call Specifications

[UNSIGNED] SHORT [UNSIGNED] INT [UNSIGNED] LONG SIZE_T

SB1

SB2

SB4

UB1

UB2

UB4

FLOAT

DOUBLE

All IN and RETURN arguments of external types not on this list, all IN OUT arguments, and all OUT arguments are passed by reference.

The PARAMETERS Clause

Generally, the PL/SQL subprogram that publishes an external procedure declares a list of formal parameters, as the following example shows:

Note: You may need to set up the following data structures for certain examples to work:

CREATE LIBRARY MathLib AS '/tmp/math.so';

CREATE OR REPLACE FUNCTION Interp_func (

/* Find the value of y at x degrees using Lagrange interpolation: */

xIN FLOAT,

yIN FLOAT) RETURN FLOAT AS

LANGUAGE C

NAME "Interp_func" LIBRARY MathLib;

Each formal parameter declaration specifies a name, parameter mode, and PL/SQL datatype (which maps to the default external datatype). That might be all the information the external procedure needs. If not, then you can provide more information using the PARAMETERS clause, which lets you specify the following:

Nondefault external datatypes

The current or maximum length of a parameter

8-24 Oracle Database Application Developer's Guide - Fundamentals

Соседние файлы в папке Oracle 10g