英文:
What is the equivalent of the function Digits in Snowflake?
问题
Snowflake中的函数Digits的等价物是什么?
任何帮助都会感激不尽。
谢谢。
英文:
What is the Equivalent of the function Digits in Snowflake?
Any help is appreciated.
Thank you
答案1
得分: 1
如果这是来自DB2的digits()
DIGITS函数返回一个数字的绝对值的字符字符串表示。
那么类似这样:
REPLACE(ABS(<yourcol>), '.', '')
或者:
ARRAY_TO_STRING(SPLIT(ABS(<yourcol>), '.'), '')
如果您还希望在左侧填充零,则无法直接在Snowflake的SQL中确定小数的精度,因此您需要明确指定输出字符串的大小:
LPAD(REPLACE(ABS(<yourcol>), '.', ''), 10, '0')
英文:
If this is digits()
from DB2
>The DIGITS function returns a character string representation of the absolute value of a number.
Then something like:
REPLACE(ABS(<yourcol>), '.', '')
Or:
ARRAY_TO_STRING(SPLIT(ABS(<yourcol>), '.'),'')
If you are also wanting the left-padded zeros there isn't a way to determine precision of a decimal in snowflake directly in your SQL, so you will have to be specific about how large your output string should be.
LPAD(REPLACE(ABS(<yourcol>), '.', ''), 10, '0')
答案2
得分: 0
SELECT TRY_TO_NUMBER('abcd');--NULL
SELECT TRY_TO_NUMBER('700000001020577');--700000001020577
SELECT TRY_TO_NUMBER('1234.56');--1234
SELECT TRY_TO_NUMBER('0.56');--0
SELECT TRY_TO_NUMBER('a12#$');--NULL
SELECT IFF(TRY_TO_NUMBER('1234') IS NULL,FALSE,TRUE) --TRUE
SELECT IFF(TRY_TO_NUMBER('abcd') IS NULL,FALSE,TRUE)--FALSE
英文:
Please try this:
SELECT TRY_TO_NUMBER('abcd');--NULL
SELECT TRY_TO_NUMBER('700000001020577');--700000001020577
SELECT TRY_TO_NUMBER('1234.56');--1234
SELECT TRY_TO_NUMBER('0.56');--0
SELECT TRY_TO_NUMBER('a12#$');--NULL
SELECT IFF(TRY_TO_NUMBER('1234') IS NULL,FALSE,TRUE) --TRUE
SELECT IFF(TRY_TO_NUMBER('abcd') IS NULL,FALSE,TRUE)--FALSE
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论