OCILIB has a strong PL/SQL support :
Stored procedures/functions calls, blocks declarations are done like regular SQL calls using OCI_Prepare(), OCI_Execute(), OCI_ExecuteStmt() and OCI_ExecuteStmtFmt() functions.
All PL/SQL statements must:
Binding Host arrays to PL/SQL tables is done with OCI_BindArrayXXX() calls
#include "ocilib.h" int main(void) { OCI_Connection *cn; OCI_Statement *st; int res = 0; if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT)) return EXIT_FAILURE; cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT); st = OCI_StatementCreate(cn); /* pl/sql call */ OCI_Prepare(st, MT("begin :res := trunc(sysdate+1)-trunc(sysdate-1); end;")); OCI_BindInt(st, MT(":res"), &res); OCI_Execute(st); printf("result : %i\n", res); OCI_Cleanup(); return EXIT_SUCCESS; }
#include "ocilib.h" #define SIZE_ARRAY 10 #define SIZE_NAME 20 #define SIZE_VALUE 100 int main(void) { OCI_Connection *cn; OCI_Statement *st; int i; char tab_names [SIZE_ARRAY][SIZE_NAME + 1]; char tab_values[SIZE_ARRAY][SIZE_VALUE + 1]; if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT)) return EXIT_FAILURE; cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT); st = OCI_StatementCreate(cn); /* set values */ for (i = 0; i < SIZE_ARRAY; i++) { sprintf(tab_names[i], "name %03d", i+1); sprintf(tab_values[i], "value %03d", i+1); } /* prepare call and bind local arrays */ OCI_Prepare(st, "BEGIN test.test(:tab_names, :tab_values); END;"); OCI_BindArrayOfStrings(st, ":tab_names", (char*) tab_names, SIZE_NAME , SIZE_ARRAY); OCI_BindArrayOfStrings(st, ":tab_values", (char*) tab_values, SIZE_VALUE, SIZE_ARRAY); /* execute */ OCI_Execute(st); /* cleanup */ OCI_Cleanup(); return EXIT_SUCCESS; }
#include "ocilib.h" int main(void) { OCI_Connection *cn; OCI_Statement *st; const dtext *p; if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT)) return EXIT_FAILURE; cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT); st = OCI_StatementCreate(cn); /* pl/sql call */ /* server output */ OCI_ServerEnableOutput(cn, 32000, 5, 255); OCI_ExecuteStmt(st, "begin " " dbms_output.put_line('First line'); " " dbms_output.put_line('Second line'); " " dbms_output.put_line('Third line'); " "end;" ); while (p = OCI_ServerGetOutput(cn)) { printf(p); printf("\n"); } OCI_Cleanup(); return EXIT_SUCCESS; }
Functions | |
OCI_EXPORT boolean OCI_API | OCI_ServerEnableOutput (OCI_Connection *con, unsigned int bufsize, unsigned int arrsize, unsigned int lnsize) |
Enable the server output. | |
OCI_EXPORT boolean OCI_API | OCI_ServerDisableOutput (OCI_Connection *con) |
Disable the server output. | |
OCI_EXPORT const dtext *OCI_API | OCI_ServerGetOutput (OCI_Connection *con) |
Retrieve one line of the server buffer. |
OCI_EXPORT boolean OCI_API OCI_ServerEnableOutput | ( | OCI_Connection * | con, | |
unsigned int | bufsize, | |||
unsigned int | arrsize, | |||
unsigned int | lnsize | |||
) |
Enable the server output.
con | - Connection handle | |
bufsize | - server buffer max size (server side) | |
arrsize | - number of lines to retrieve per server roundtrip | |
lnsize | - maximum size of one line |
Definition at line 1501 of file connection.c.
References OCI_BindArrayOfStrings(), OCI_BindSetNull(), OCI_BindUnsignedInt(), OCI_Execute(), OCI_GetBind(), OCI_Prepare(), OCI_ServerDisableOutput(), and OCI_StatementCreate().
OCI_EXPORT boolean OCI_API OCI_ServerDisableOutput | ( | OCI_Connection * | con | ) |
Disable the server output.
con | - Connection handle |
Definition at line 1609 of file connection.c.
References OCI_ExecuteStmt(), and OCI_StatementFree().
Referenced by OCI_ServerEnableOutput().
OCI_EXPORT const dtext* OCI_API OCI_ServerGetOutput | ( | OCI_Connection * | con | ) |
Retrieve one line of the server buffer.
con | - Connection handle |
Definition at line 1638 of file connection.c.
References OCI_Execute().