SQL 查询 TO_INTEGER substr
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8699582/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQL query TO_INTEGER substr
提问by Raguraman Thuraiyur
Please explain me how to understand the next query
请解释我如何理解下一个查询
TO_INTEGER(substr(NAME,1,length(NAME)-3))*100
回答by Srinivas Reddy Thatiparthy
You are taking a substring of NAME ,which happens to be integer in string form and converting it to integer and multiplying it with 100.
您正在获取 NAME 的子字符串,它恰好是字符串形式的整数,并将其转换为整数并乘以 100。
回答by Matten
For example, NAME is '1234CDE'
例如,NAME 是“1234CDE”
The innermost section takes a substring from the input value NAME, starting from position 1 and with a length of equal to the length of the original string minus 3:
最里面的部分从输入值 NAME 中获取一个子字符串,从位置 1 开始,长度等于原始字符串的长度减去 3:
substr(NAME,1,length(NAME)-3) -- >> '1234'
The outer function converts the extracted substring to integer:
外部函数将提取的子字符串转换为整数:
TO_INTEGER('1234') -- >> 1234 (as integer)
Lastly there's a simple multiplication:
最后是一个简单的乘法:
1234 * 100 -- >> 123400
so
所以
TO_INTEGER(substr('1234CDE',1,length('1234CDE')-3)) * 100 -- >> 123400