目錄
- 1、空格字串函式:space
- 2、space函式與split函式結合,得到陣列;
- 3、如何產生1-100的連續的數字?
1、空格字串函式:space
語法: space(int n)
回傳值: string
說明:回傳長度為n的空格字串
舉例:
hive> select space(10) from dual;
hive> select length(space(10)) from dual;
10
2、space函式與split函式結合,得到陣列;
space函式與split函式結合,可以得到空格字串陣列
舉例:
hive>select split(space(10), '');
[" "," "," "," "," "," "," "," "," "," ",""]
3、如何產生1-100的連續的數字?
結合space函式與split函式,posexplode函式,lateral view函式獲得
實作方法一:
select
id_start+pos as id
from(
select
1 as id_start,
100 as id_end
) m lateral view posexplode(split(space(id_end-id_start), '')) t as pos, val
實作方法二:
select
row_number() over() as id
from
(select split(space(99), ' ') as x) t
lateral view
explode(x) ex;
備注:explode(x)和posexplode()均為炸裂函式,區別在于explode炸出一個值,posexplode不僅炸出一個值還附帶索引號;
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/433334.html
標籤:其他
上一篇:【歷史上的今天】2 月 26 日:施樂 Alto 設計師出生;ATM 機獲得專利;Clearview AI 被盜取 30 億張照片
