当前位置:网站首页>SQL functions STR
SQL functions STR
2022-08-01 12:42:00 【The user 7741497】
SQL function STR
A function to convert a number to a string.
Outline
STR(number[,length[,decimals]])
parameter
number
- An expression that resolves to a number.It can be a field name, a number, or the result of other functions.If a field name is specified, a logical value is used.length
- optional - an integer specifying the total length of the desired output string, including all characters (numbers, decimal points, symbols, spaces).The default value is10
.decimals
- optional — an integer specifying the number of digits to the right of the decimal point to include.The default value is 0.
Description
STR
Converts a number to STRING
format, truncating the number based on the length and decimal value.The length parameter must be large enough to contain the entire integer portion of the number and, if a decimal is specified, the number of decimal places plus 1
(for the decimal point).If the length is not large enough, STR
will return an asterisk (*
) string equal to the length.
STR
Converts numbers to their canonical form before string conversion.Therefore, it performs arithmetic operations, removing leading and trailing zeros and leading plus signs from the number.
If the number
parameter is NULL
, STR
returns NULL
.If the number
parameter is an empty string (''
), STR
returns an empty string.STRING
spaces are reserved.
Example
In the following embedded SQL
example, STR
converts a number to a string:
/// d ##class(PHA.TEST.SQLFunction).Str()ClassMethodStr(){&sql(SELECT STR(123),STR(123,4),STR(+00123.45,3),STR(+00123.45,3,1),STR(+00123.45,5,1)INTO :v,:w,:x,:y,:z)if SQLCODE '= 0 {w !,"Error code ",SQLCODE} else {w !,"Resulting STR:",v,"string"w !,"Resulting STR:",w,"string"w !,"Resulting STR:",x,"string"w !,"Resulting STR:",y,"string"w !,"Resulting STR:",z,"string"}}
DHC-APP>d ##class(PHA.TEST.SQLFunction).Str()Resulting STR: 123 stringResulting STR: 123 stringResulting STR: 123 stringResulting STR:*** stringResulting STR:123.4 string
The first STR
function returns a string consisting of 7
leading spaces and the number 123
; the seven leading spaces are becauseThe default string length is 10
.The second STR
function returns the string "123"
; note the leading whitespace required to return a string of length 4
.The third STR
function returns the string “123”
; the number is put into canonical form, and the decimal defaults to 0
.The fourth STR
function returns "***"
because the string is not long enough to contain the entire number specified; the number of asterisks indicates the string length.The fifth STR
function returns "123.4"
; note that the length must be 5
to contain decimal digits.
边栏推荐
- Aeraki Mesh 正式成为 CNCF 沙箱项目
- 如何利用DevExpress控件绘制流程图?看完这篇文章就懂了!
- Alibaba Cloud Official Redis Development Specification
- R language fitting ARIMA model: use the auto.arima function in the forecast package to automatically search for the best parameter combination, model order (p, d, q), set the seasonal parameter to spe
- Audio and Video Technology Development Weekly | 256
- [Community Star Selection] Issue 24 August Update Plan | Keep writing, refuse to lie down!More original incentive packages, as well as Huawei WATCH FIT watches!
- 【面试高频题】难度 1.5/5,二分经典运用题
- Process sibling data into tree data
- Dapr 与 NestJs ,实战编写一个 Pub & Sub 装饰器
- 初级必备:单例模式的7个问题
猜你喜欢
STM32 CAN filter configuration details
Beyond Compare 4 trial period expires
[5 days countdown] to explore the secret behind the great quality promotion, gift waiting for you to take of $one thousand
Fault 007: The dexp derivative is inexplicably interrupted
Dameng replaces the officially authorized dm.key
英特尔全方位打造算力基础,助推“算”赋百业
稀疏表示--学习笔记
新一代超安全蜂窝电池, 思皓爱跑上市13.99万元起售
《MySQL核心知识》第6章:查询语句
win10系统重装,无法登录进行同步的情况下chrome数据恢复
随机推荐
sql中ddl和dml(数据库表与视图的区别)
实现集中式身份认证管理的案例
【倒计时5天】探索音画质量提升背后的秘密,千元大礼等你来拿
意大利普拉托华社将游行示威 盼解决安全问题
SQL函数 SQUARE
Audio and Video Technology Development Weekly | 256
R language fitting ARIMA model: use the auto.arima function in the forecast package to automatically search for the best parameter combination, model order (p, d, q), set the seasonal parameter to spe
Visualization of lag correlation of two time series data in R language: use the ccf function of the forecast package to draw the cross-correlation function, and analyze the lag correlation according t
2022 Go ecosystem rpc framework Benchmark
迁移学习冻结网络的方法:
【讲座分享】“营收“看金融
Process sibling data into tree data
大中型网站列表页翻页过多怎么优化?
2022 Go生态圈 rpc 框架 Benchmark
【面试高频题】难度 1.5/5,二分经典运用题
如何利用DevExpress控件绘制流程图?看完这篇文章就懂了!
How do programmers solve online problems gracefully?
Beyond Compare 4 试用期到期
Dameng replaces the officially authorized dm.key
安全又省钱,“15岁”老小区用上管道燃气