Mysql自定义函数

Mysql自定义函数分为两种
1. 简单的 如string相关的函数
2. 集合的 aggregate,如sum函数
创建函数的Mysql命令
CREATE [AGGREGATE] FUNCTION 函数名称 RETURNS {STRING|INTEGER|REAL|DECIMAL}
    SONAME 链接库的名称

笔记:
1.链接库似乎不能带路径
2.aggregate为集合

类型
描述

STRING
char *

INTEGER
64位int,__int64,unsigned __int64

REAL
double

DECIAML
还没完成,char*

UDF_INIT:

类型
名称
描述

my_bool
maybe_null
1 如果返回NULL

unsigned int
decimals
用在REAL函数

unsigned long
max_length
用于STRING函数

char *
ptr
函数数据的自由指针

my_bool
const_item
0时参数无关

UDF_ARGS:

类型
名称
描述

unsigned int
arg_count
参数个数

enum Item_result *
arg_type
参数类型

char **
args
参数

unsigned long *
lengths
参数长度

char *
maybe_null
当置1时,参数可以为NULL

char **
attributes
属性

unsigned long *
attribute_lengths
属性长度

模板
//For Mysql 5.0

my_bool MyTest_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{
}

void MyTest_deinit(UDF_INIT *initid)
{
}

//以下为不同情况的函数
longlong MyTest(UDF_INIT *initid, UDF_ARGS *args,char *is_null, char *error)
{
}

double MyTest(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
{
}

char* MyTest(UDF_INIT *initid, UDF_ARGS *args,char *result, unsigned long *length,char *is_null, char *error)
{
}


//END

//以下用于集合

void MyTest_clear(UDF_INIT *initid, char *is_null, char *error)
{
}

void MyTest_add(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
{
}

//END

如果有建议或疑问欢迎
我的blog是http://www.henhenxo.com/list/19.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值