谁知道如何在 Firebird 3 中将数字格式转换为带有千位分隔符的 varchar ?像oracle to_char() 从双选择 to_char(1234325234234.55,'999G999G999G999G999D00' ) nn -- 1 234 325 234 234,55
最佳答案
在这里,这可能会有所帮助。抱歉西类牙评论,我为我的工作编写了它。
干杯!
SET TERM ^ ;
create or alter procedure FN_FORMATEA_NUMERO_MILES (
PVALOR numeric(14,2))
returns (
NUMERO_FORMATEADO varchar(20))
as
declare variable VDECIMALES varchar(2);
declare variable VENTEROS varchar(20);
declare variable VNUMERO_BASE varchar(20);
declare variable VCONTEO smallint;
declare variable VDIGITOS smallint;
begin
/* Convierte el numero a caracter */
vnumero_base = trim(cast(pvalor as varchar(20)));
/* Separa el segmendo decimal del segmento de enteros */
vdecimales = substring(vnumero_base from position('.', vnumero_base) + 1 for 2);
venteros = substring(vnumero_base from 1 for position('.', vnumero_base) - 1);
/* Inicializa el resultado */
numero_formateado = '.' || vdecimales;
/* Integra los enteros en grupos de 3 */
vconteo = char_length(venteros);
vdigitos = 0;
while (vconteo > 0) do
begin
numero_formateado = substring(venteros from vconteo for 1) || numero_formateado;
vconteo = vconteo - 1;
vdigitos = vdigitos + 1;
if ((vdigitos = 3) and (vconteo > 0) and (substring(venteros from vconteo for 1) <> '-')) then
begin
vdigitos = 0;
numero_formateado = ',' || numero_formateado;
end
end
/* Regresa el numero formateado */
suspend;
end^
SET TERM ; ^
/* Existing privileges on this procedure */
GRANT EXECUTE ON PROCEDURE FN_FORMATEA_NUMERO_MILES TO SYSDBA;
关于sql - 如何将数字格式化为带有千位分隔符的varchar?像oracle to_char(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51427933/