lib.c:
#include <stdlib.h>
#include <string.h>
char *converte( char *text ) {
int i;
for (i=0; text[i]!='\0'; i++) {
text[i]=tolower(text[i]);
}
return text;
}
gcc -c lib.c
make -f $ORACLE_HOME/rdbms/demo/demo_rdbms.mk extproc_callback \
SHARED_LIBNAME=lib.so \
OBJS=lib.o
The library is ready, now we only need to show Oracle as there. In SQLPlus we create Bilbioteca like this:
sql> CREATE OR REPLACE LIBRARY lib AS '/oracle/9.2.0/lib/lib.so'
sql> /
sql> CREATE OR REPLACE FUNCTION "CONVERTE" (cstr VARCHAR2)
2 return varchar2 as external
3 library lib
4 name "converte"
5 language c
6 parameters (cstr string);
The Language Parameter Defined the language in which this function was written and parameters parameters indicates what type of data oracle must send to it, in the case a string C (cstr).
To use our new function, we can make a simple test within SQLPlus:
SQL without the function:
SQL> select status from v$session where status='ACTIVE';
STATUS
--------
ACTIVE
ACTIVE
ACTIVE
ACTIVE
ACTIVE
ACTIVE
ACTIVE
ACTIVE
ACTIVE
ACTIVE
ACTIVE
11 rows selected.
SQL com a função:
SQL> select converte(status) from v$session where status='ACTIVE';
CONVERTE(STATUS)
active
active
active
active
active
active
active
active
active
active
active
11 rows selected.