postgresql字符串转数字

规则

  1. 若字符串全是数字,则返回该数字值;
  2. 若字符串不全是数字,则返回空;

postgresql函数实现

CREATE OR REPLACE FUNCTION isnumeric(str character varying)
 RETURNS numeric
 LANGUAGE plpgsql
AS $function$ 
declare
p_str numeric;
begin 
	p_str := cast($1 as numeric);
    return p_str;
    exception when others then return null;
end;
$function$
;
--123
select isnumeric('123');
--null
select isnumeric('123木头人');

你可能感兴趣的:(greenplum,postgresql,postgresql)