云日志服务 LTS-字符串函数:string_format函数

时间:2024-01-25 20:23:05

string_format函数

返回以Java的String.format方式格式化的字符串。

语法:string_format(str, Object... args)

表28 参数说明

参数名称

描述

类型

是否必选

str

原始字符串。

String

args

参数。

String/Integer/Long/Boolean/Double

返回值类型:String类型

示例:SELECT STRING_FORMAT('My name is %s and I am %d years old.', 'name', age)

表29 查询分析结果

类型

场景

查询语句

STRING_FORMAT('My name is %s and I am %d years old.', 'Tom', 25)

返回结果

My name is Tom and I am 25 years old.

%d:Output integer.

%f:Output floating point number.

%s:Output character string.

%n:Output newline character.

%c:Output Characters

%b:Output bool type

%e:Output Exponential Type

%tc:Output Date and time information

%tF:Output format is YYY-MM-DD.

%tr:Output in HH:MM:SS PM format

可以参考Java的String.format获取更多的细节

support.huaweicloud.com/usermanual-lts/lts_07_0093.html