在oracle里面引用外部的C语言编写的过程

1、首先编写下面的代码:

#include	<stdio.h>
#include	<stdlib.h>
#include	<string.h>
#include	<errno.h>
#include	<fcntl.h>
#include	<unistd.h>
#include	<sys/types.h>
#include	<sys/stat.h>


int	strtime2num(char *tstr)
{
    struct tm m;
        
    if (tstr==NULL)
      	return 0;
    m.tm_year = atoi(tstr)-1900;
    m.tm_mon = atoi(tstr+5)-1;
    m.tm_mday = atoi(tstr+8);
    m.tm_hour = atoi(tstr+11);
    m.tm_min = atoi(tstr+14);
    m.tm_sec = atoi(tstr+17);
    return(mktime(&m));
}

 

编译选项,solaris下的cc编译,其他平台可以自行处理:

test_func.o : test_func.c
	cc -g -xarch=v9 -o ${SYNCSVRDIR}/test_func.o -c $(SYNCSVRDIR)/test_func.c

test_func.so: test_func.o
	cc -G -Kpic -xarch=v9 -o test_func.so test_func.o 

 

关键记得把这个so放到server运行的机器上去,比方说放到:/database/oracle/product/10.2.0/Db_1/lib/test_func.so。在oracle里面创建函数:

 

create or replace library MYLIB as '/database/oracle/product/10.2.0/Db_1/lib/test_func.so';


CREATE OR REPLACE FUNCTION mytest1(a varchar2) RETURN binary_integer AS
LANGUAGE C NAME "strtime2num"
LIBRARY MYLIB PARAMETERS (a STRING,RETURN int);

 

好了,试试:

select mytest1('2006-12-01 00:00:00') from dual;
 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值