当前位置:网站首页>Pg/oracle database ASCII code to string custom function

Pg/oracle database ASCII code to string custom function

2022-06-11 08:17:00 Want Xiaoxin

pg ascii Code to string function

Here comes a message from ascii Code concatenated string , Convert to a string in the database

CREATE OR REPLACE FUNCTION dc_bill.f_xdo_to_assii(p_str character varying)
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
declare 
 resul varchar='';-- Define the return result 
    init Integer ;-- Definition   loop 
   strLength Integer;-- Define string length 
begin
	IF length(p_str)>0 then
	strLength :=length(p_str)-length(replace(p_str,',',''))+1;
	-- Calculate string length 
     FOR i in 1..strLength loop
      init=split_part(p_str,',',i);-- Split characters 
         resul:=resul||chr(init);--ascii Convert the string and splice it into a result 
    end loop;
    return resul;
    end if;
   return resul;
end; $function$
;

oracle ascii Code to string function

CREATE OR REPLACE FUNCTION DC_BILL.f_xdo_to_assii(p_str varchar)
  RETURN varchar AS
   resul varchar2(50):='';
  init varchar2(50);
 strLength  NUMBER;
BEGIN
	IF length(p_str)>0 then
	strLength :=length(p_str)-length(replace(p_str,',',''))+1;
	FOR i IN 1..strLength LOOP	
  init := chr(REGEXP_SUBSTR (p_str, '[^,]+', 1,i));
resul :=RESUL||init;
END LOOP;
 RETURN resul;
END IF;
RETURN resul;
END;

原网站

版权声明
本文为[Want Xiaoxin]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020513375930.html