暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

oracle使用外部库函数

hbm8888 2025-06-08
80

p, li { white-space: pre-wrap; }

1、监听里有IPC协议

LISTENER =

(DESCRIPTION_LIST =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))

(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))

)

)


ADR_BASE_LISTENER = /u01/app/oracle

tnsnames.ora上添一个ipc名

EXTPROC01 =

(DESCRIPTION=

(ADDRESS=(PROTOCOL=ipc)(key=EXTPROC1521))

(CONNECT_DATA=(SERVICE_NAME=orcl))

)


2、创建一个语言

cat test.c

#include <stdio.h>

test(n)

int n;

{

int lucky_money;

lucky_money=100*n;

return (lucky_money);

}

生成动态so库,需要添加-fPIC -shared两个参数

gcc -o libtest.so -fPIC -shared test.c


3、把外部库复制到ORACLE_HOME目录下,修改权限

[root@ora11 ~]# cp libtest.so /u01/app/oracle/product/11.2.0/dbhome_1/bin/


[root@ora11 ~]# cd /u01/app/oracle/product/11.2.0/dbhome_1/bin/

[root@ora11 bin]# chown oracle:oinstall libtest.so

[root@ora11 bin]# ll libtest.so

-rwxr-xr-x 1 oracle oinstall 7880 May 12 07:45 libtest.so


4、创建library

create or replace library test_code as '/u01/app/oracle/product/11.2.0/dbhome_1/bin/libtest.so'

/

用户赋外部表执行权限

grant EXECUTE on sys.test_code to test; 给test


4、创建内部函数

create or replace function func_test

(x binary_integer)

return binary_integer

as language C

library sys.test_code

name "test";

/


5、验证

set serveroutput on

var lucky_money number;

var amount number;

exec :lucky_money :=8888;

exec :amount := func_test(8888);

print amount;

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论