Snowflake中函数Digits的等效函数是什么?

huangapple go评论67阅读模式
英文:

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(&lt;yourcol&gt;), &#39;.&#39;, &#39;&#39;)

Or:

ARRAY_TO_STRING(SPLIT(ABS(&lt;yourcol&gt;), &#39;.&#39;),&#39;&#39;)

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(&lt;yourcol&gt;), &#39;.&#39;, &#39;&#39;), 10, &#39;0&#39;)

答案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(&#39;abcd&#39;);--NULL
SELECT TRY_TO_NUMBER(&#39;700000001020577&#39;);--700000001020577
SELECT TRY_TO_NUMBER(&#39;1234.56&#39;);--1234
SELECT TRY_TO_NUMBER(&#39;0.56&#39;);--0
SELECT TRY_TO_NUMBER(&#39;a12#$&#39;);--NULL

SELECT IFF(TRY_TO_NUMBER(&#39;1234&#39;) IS NULL,FALSE,TRUE) --TRUE
SELECT IFF(TRY_TO_NUMBER(&#39;abcd&#39;) IS NULL,FALSE,TRUE)--FALSE

huangapple
  • 本文由 发表于 2020年1月6日 22:45:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/59614073.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定