人大金仓(KingBase)数据库自定义函数语句

1.直接上干货:

Ifnull 函数

CREATE OR REPLACE INTERNAL FUNCTION PUBLIC.IFNULL(CHARACTER VARYING, CHARACTER VARYING) 
 RETURNS CHARACTER VARYING
 LANGUAGE PLSQL
 IMMUTABLE STRICT
AS $function$
DECLARE
BEGIN
RETURN ISNULL($1,$2);
END;
$function$;

FIND_IN_SET 函数

CREATE OR REPLACE INTERNAL FUNCTION PUBLIC.FIND_IN_SET(CHARACTER VARYING, CHARACTER VARYING) 
 RETURNS CHARACTER VARYING
 LANGUAGE PLSQL
 IMMUTABLE STRICT
AS $function$
DECLARE
tokens varchar[];
BEGIN
tokens := sys_catalog.string_to_array($2, ',');
RETURN ISNULL(sys_catalog.array_position(tokens, $1),0) > 0;
END;
$function$;

JSON_EXTRACT 函数

CREATE OR REPLACE INTERNAL FUNCTION PUBLIC.JSON_EXTRACT(CHARACTER VARYING, CHARACTER VARYING) 
 RETURNS CHARACTER VARYING
 LANGUAGE PLSQL
 IMMUTABLE STRICT
AS $function$
DECLARE
BEGIN
RETURN sys_catalog.json_extract_path($1, sys_catalog.replace($2,'$.',''));
END;
$function$;

substring_index 函数

CREATE OR REPLACE INTERNAL FUNCTION PUBLIC.substring_index(CHARACTER VARYING, CHARACTER VARYING, INTEGER) 
 RETURNS CHARACTER VARYING
 LANGUAGE PLSQL
 IMMUTABLE STRICT
AS $function$
DECLARE
tokens varchar[];
length integer ;
indexnum integer;
BEGIN
tokens := sys_catalog.string_to_array($1, $2);
length := sys_catalog.array_upper(tokens, 1);
indexnum := length - ($3 * -1) + 1;
IF $3 >= 0 THEN
RETURN sys_catalog.array_to_string(tokens[1:$3], $2);
ELSE
RETURN sys_catalog.array_to_string(tokens[indexnum:length], $2);
END IF;
END;
$function$;


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值