SQL:在 TRIM 个前导字符后将 VARCHAR 转换为 BIGINT

SQL: Cast VARCHAR to BIGINT after TRIM leading characters

我有 VARCHAR ID,但需要 BIGINT ID。

-- have: ORG1234
--need: 1234

SELECT 
    CAST(TRIM('ORG' FROM ads_solutions_advertiser_id) AS BIGINT) AS num_id
FROM 
    tab

>>>
Syntax error: mismatched input 'CAST'. Expecting: <query>

关注了这个 tutorialSELECT TRIM('#! ' FROM ' #SQL Tutorial! ') AS TrimmedString;

解决此问题的最简单方法是什么?

trim 在 presto 中以不同的方式工作:

Removes leading and trailing whitespace from string.

您可以使用 replace:

replace(string, search)varchar
Removes all instances of search from string.

SELECT CAST(replace('ORG1234', 'ORG') AS BIGINT) AS num_id

输出:

num_id
1234