你需要使用 regexp_extract 功能和保持匹配 regular expression 并提取值。 Regular expression:lanes=>"(.*?)" //literal match for lanes=>" and capture until next following occurance " and keep it in first capture groupExample:with cte as (--sample data select stack(2,string('lanes=>"2","txt_mid"=>"0"'), string('"is_in"=>"parksville"'))as(c1)) select regexp_extract(c1,'lanes=>"(.*?)"',1)lanes, regexp_extract(c1,'"txt_mid"=>"(.*?)"',1)txt_mid from cte;Result: ``` lanes txt_mid 2 0
如果要为丢失的数据记录设置空值,则使用case when then语句检查字段的长度(如果0有) `null` 记录的值。
1条答案
按热度按时间7bsow1i61#
你需要使用
regexp_extract
功能和保持匹配regular expression
并提取值。Regular expression:
lanes=>"(.*?)" //literal match for lanes=>" and capture until next following occurance " and keep it in first capture group
Example:
with cte as (--sample data select stack(2,string('lanes=>"2","txt_mid"=>"0"'), string('"is_in"=>"parksville"'))as(c1)) select regexp_extract(c1,'lanes=>"(.*?)"',1)lanes, regexp_extract(c1,'"txt_mid"=>"(.*?)"',1)txt_mid from cte;
Result:
```lanes txt_mid
2 0