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

Passing Parameters to External C Procedures with Call Specifications

NAME "C_demoExternal"

LIBRARY SomeLib

WITH CONTEXT

PARAMETERS(CONTEXT, x INT, y STRING, z OCIDATE);

END;

CREATE OR REPLACE PACKAGE BODY Demo_pack AS

PROCEDURE plsToC_InBodyOld_proc (x BINARY_INTEGER, y VARCHAR2, z DATE) AS EXTERNAL

LANGUAGE C

NAME "C_InBodyOld" LIBRARY SomeLib WITH CONTEXT

PARAMETERS(CONTEXT, x INT, y STRING, z OCIDATE);

PROCEDURE plsToC_demoExternal_proc (x BINARY_INTEGER, y VARCHAR2, z DATE) AS LANGUAGE C

NAME "C_demoExternal" LIBRARY SomeLib

WITH CONTEXT

PARAMETERS(CONTEXT, x INT, y STRING, z OCIDATE);

PROCEDURE plsToC_InBody_proc (x BINARY_INTEGER, y VARCHAR2, z DATE) AS LANGUAGE C

NAME "C_InBody"

LIBRARY SomeLib WITH CONTEXT

PARAMETERS(CONTEXT, x INT, y STRING, z OCIDATE);

PROCEDURE plsToJ_InBody_proc (x BINARY_INTEGER, y VARCHAR2, z DATE) IS LANGUAGE JAVA

NAME 'pkg1.class4.J_InBody_meth(int,java.lang.String,java.sql.Date)';

END;

Passing Parameters to External C Procedures with Call Specifications

Call specifications allows a mapping between PL/SQL and C datatypes. See "Specifying Datatypes" for datatype mappings.

Passing parameters to an external C procedure is complicated by several circumstances:

The available set of PL/SQL datatypes does not correspond one-to-one with the set of C datatypes.

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

Passing Parameters to External C Procedures with Call Specifications

Unlike C, PL/SQL includes the RDBMS concept of nullity. Therefore, PL/SQL parameters can be NULL, whereas C parameters cannot.

The external procedure might need the current length or maximum length of

CHAR, LONG RAW, RAW, and VARCHAR2 parameters.

The external procedure might need character set information about CHAR, VARCHAR2, and CLOB parameters.

PL/SQL might need the current length, maximum length, or null status of values returned by the external procedure.

In the following sections, you learn how to specify a parameter list that deals with these circumstances.

Note: The maximum number of parameters that you can pass to a C external procedure is 128. However, if you pass float or double parameters by value, then the maximum is less than 128. How much less depends on the number of such parameters and your operating system. To get a rough estimate, count each float or double passed by value as two parameters.

Specifying Datatypes

Do not pass parameters to an external procedure directly. Instead, pass them to the PL/SQL subprogram that published the external procedure. Therefore, you must specify PL/SQL datatypes for the parameters. PL/SQL datatypes map to default external datatypes, as shown in Table 8–1.

Table 8–1 Parameter Datatype Mappings

PL/SQL Datatype

Supported External Types

Default External Type

 

 

 

BINARY_INTEGER

[UNSIGNED] CHAR

INT

BOOLEAN

[UNSIGNED] SHORT

 

PLS_INTEGER

[UNSIGNED] INT

 

 

[UNSIGNED] LONG

 

 

SB1, SB2, SB4

 

 

UB1, UB2, UB4

 

 

SIZE_T

 

Calling External Procedures 8-19

Passing Parameters to External C Procedures with Call Specifications

Table 8–1 (Cont.)

Parameter Datatype Mappings

 

 

 

 

PL/SQL Datatype

Supported External Types

Default External Type

 

 

 

NATURAL1

[UNSIGNED] CHAR

UNSIGNED INT

NATURALN1

[UNSIGNED] SHORT

 

POSITIVE1

[UNSIGNED] INT

 

POSITIVEN1

[UNSIGNED] LONG

 

SIGNTYPE1

SB1, SB2, SB4

 

 

UB1, UB2, UB4

 

 

SIZE_T

 

FLOAT

FLOAT

FLOAT

REAL

 

 

DOUBLE PRECISION

DOUBLE

DOUBLE

CHAR

STRING

STRING

CHARACTER

OCISTRING

 

LONG

 

 

NCHAR

 

 

NVARCHAR2

 

 

ROWID

 

 

VARCHAR

 

 

VARCHAR2

 

 

LONG RAW

RAW

RAW

RAW

OCIRAW

 

BFILE

OCILOBLOCATOR

OCILOBLOCATOR

BLOB

 

 

CLOB

 

 

NCLOB

 

 

NUMBER

OCINUMBER

OCINUMBER

DEC1

 

 

DECIMAL1

 

 

INT1

 

 

INTEGER1

 

 

NUMERIC1

 

 

SMALLINT1

 

 

DATE

OCIDATE

OCIDATE

TIMESTAMP

OCIDateTime

OCIDateTime

TIMESTAMP WITH TIME

ZONE

TIMESTAMP WITH LOCAL

TIME ZONE

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

Passing Parameters to External C Procedures with Call Specifications

Table 8–1 (Cont.) Parameter Datatype Mappings

PL/SQL Datatype

Supported External Types

Default External Type

 

 

 

INTERVAL DAY TO SECOND

OCIInterval

OCIInterval

INTERVAL YEAR TO MONTH

 

 

composite object types:

dvoid

dvoid

ADTs

 

 

composite object types:

OCICOLL

OCICOLL

collections (varrays,

 

 

nested tables)

 

 

1 This PL/SQL type will only compile if you use AS EXTERNAL in your callspec.

External Datatype Mappings

Each external datatype maps to a C datatype, and the datatype conversions are performed implicitly. To avoid errors when declaring C prototype parameters, refer to Table 8–2, which shows the C datatype to specify for a given external datatype and PL/SQL parameter mode. For example, if the external datatype of an OUT parameter is STRING, then specify the datatype char * in your C prototype.

Table 8–2 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...

CHAR

char

char *

char *

UNSIGNED CHAR

unsigned char

unsigned char *

unsigned char *

SHORT

short

short *

short *

UNSIGNED SHORT

unsigned

unsigned short

unsigned short

 

short

*

*

INT

int

int *

int *

UNSIGNED INT

unsigned int

unsigned int *

unsigned int *

LONG

long

long *

long *

UNSIGNED LONG

unsigned long

unsigned long *

unsigned long *

CHAR

char

char *

char *

Calling External Procedures 8-21

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...

UNSIGNED CHAR

unsigned char

unsigned char *

unsigned char *

SHORT

short

short *

short *

UNSIGNED SHORT

unsigned

unsigned short

unsigned short

 

short

*

*

INT

int

int *

int *

UNSIGNED INT

unsigned int

unsigned int *

unsigned int *

LONG

long

long *

long *

UNSIGNED LONG

unsigned long

unsigned long *

unsigned long *

SIZE_T

size_t

size_t *

size_t *

SB1

sb1

sb1 *

sb1 *

UB1

ub1

ub1 *

ub1 *

SB2

sb2

sb2 *

sb2 *

UB2

ub2

ub2 *

ub2 *

SB4

sb4

sb4 *

sb4 *

UB4

ub4

ub4 *

ub4 *

FLOAT

float

float *

float *

DOUBLE

double

double *

double *

STRING

char *

char *

char *

RAW

unsigned char

unsigned char *

unsigned char *

 

*

 

 

OCILOBLOCATOR

OCILobLocator

OCILobLocator

OCILobLocator

 

*

**

**

OCINUMBER

OCINumber *

OCINumber *

OCINumber *

OCISTRING

OCIString *

OCIString *

OCIString *

OCIRAW

OCIRaw *

OCIRaw *

OCIRaw *

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

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