MaxCompute SQL函式詳解 ODPS SQL函式詳解---之字串轉換相關函式
MaxCompute/ODPS SQL函式字串轉換函式
- concat 函式-拼接字串
回傳型別:string
語法:concat(型別 引數1,型別 引數2,型別 引數3);
concat(string str1 , string str2, string str3 …);
引數解釋:
引數1(str1):字串1
引數2(str2):字串2
引數3(str3):字串3
......
函式作用:將多個字串拼接成一個字串
舉例:將字串‘holle’、‘word’、‘!’ 三個字串拼接成一個字串

- substr/SUBSTRING 函式-截取字串
回傳型別:string
語法:substr(型別 引數1,型別 引數2,型別 引數3);
substr(string str, bigint start_position[, bigint length]);
SUBSTRING 函式與substr函式用法一致
引數解釋:
引數1(str):字串
引數2(start_position):字串開始位置
引數3(length):可有可無,有的情況下則是直接從開始位置取到最后一位,
無的情況下則取length長度字串
函式作用:獲取字串str從start_position位置開始,截取長度為length的字串,
如果沒有length引數則是截取字串str從start_position位置開始,截取到末尾,
舉例:從字串‘holle word’ 截取出字串

- COALESCE 函式-替換空值
回傳型別:string
語法:COALESCE(型別 引數1,型別 引數2,型別 引數3...);
COALESCE(string str1, string str2, string str3....);
引數解釋:
引數1(str1):字串1
引數2(str2):字串1
引數3(str3):字串1
......
函式作用:獲取第一個非空字串,或null;
當第一個引數為null時,則取第二個
當第二個引數也為null時,則取第三個
.......
舉例:

- length、lengthb 函式-字串長度
回傳型別:bigint
語法:length(型別 引數1);
lengthb(型別 引數1);
length(string str);
lengthb(string str)
引數解釋:
引數1(str1):字串1
函式作用:
length:回傳一個字串的長度
lengthb:回傳一個字串的位元組個數,一個中文字三個位元組
舉例:

- char_matchcount 函式
回傳型別:bigint
語法:char_matchcount (型別 引數1,型別 引數2);
char_matchcount(string str1, string str2);
引數解釋:
引數1(str1):字串1
引數2(str2):字串2
函式作用:字串str1在str2中有多少個?
舉例:

- md5函式
回傳型別:string
語法:md5(型別 引數1);
md5(string str);
引數解釋:
引數1(str):字串
函式作用:計算獲取字串str的md5值;
該函式可用于字串加密
舉例:計算字串’this md5’的md5值

- split_part函式
回傳型別:string
語法:split_part(型別 引數1,型別 引數2,型別 引數3);
split_part(string str, string separator, bigint num);
引數解釋:
引數1(str):字串
引數2(separator):分隔符
引數3(num):分割后的第幾個字串
函式作用:按照分隔符separator分割字串,然后回傳第num位置的字串
舉例:獲取字串‘aiughb|cada|jsdf’ 按分割符‘|’ 截取后的字串

- toupper、tolower函式-大小寫轉換
回傳型別:string
語法:toupper(型別 引數);
toupper(string str);
tolower(型別 引數);
tolower(string str);
引數解釋:
引數1(str):需要轉換大小寫的字串
函式作用:
toupper:將字串轉換成大寫
tolower:將字串轉換成小寫
舉例:

- trim、ltrim、rtrim函式-去除空格
回傳型別:string
語法:trim(型別 引數);
trim(string str);
ltrim(型別 引數);
ltrim(string str);
rtrim(型別 引數);
rtrim(string str);
引數解釋:
引數1(str):需要去空格的字串
函式作用:
trim:去除字串str的左邊與右邊空格,不能去中間空格
ltrim:去除字串str的左邊的空格
rtrim:去除字串str的右邊空格
舉例:

- reverse函式-反向輸出
回傳型別:string
語法:reverse(型別 引數);
reverse(string str);
引數解釋:
引數1(str):需要反向輸出的字串
函式作用:將字串str反向輸出
舉例:將字串‘dsagfsdaf’ 反向輸出

- repeat函式-重復字串
回傳型別:string
語法:repeat(型別 引數1,型別 引數2);
repeat(string str, bigint n);
引數解釋:
引數1(str):字串
引數2(n):出現n次
函式作用:回傳在字串str中重復過n次的字串
舉例:將字串‘dsagfsdaf’ 反向輸出
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/423213.html
標籤:其他
