翻譯頁面
本頁面由英文在 AI 協助下翻譯而成。若兩者有出入,請以英文版本為準。
REGEXP_SUBSTR
從輸入字串傳回符合指定模式的子字串。
另請參閱:
[SELECT] [ 正規表示式參考 ]
語法
SELECT REGEXP_SUBSTR(source, pattern) FROM <multipartIdentifier>;
引數
source
字串常值或字串資料行,您要依據由正規表示式(pattern)定義的模式從中擷取子字串。
pattern
要搜尋的正規表示式模式。
傳回值
傳回字串。
範例
依據正規表示式擷取子字串
- StackQL
- 結果
select name,
json_extract(properties, '$.storageProfile.imageReference.offer') as os,
regexp_substr(
json_extract(properties, '$.storageProfile.imageReference.exactVersion'),
'[0-9][0-9]\.[0-9][0-9]') as os_version
from azure.compute.virtual_machines
WHERE subscription_id = '273769f6-545f-45b2-8ab8-2f14ec5768dc';
|------|---------------|------------|
| name | os | os_version |
|------|---------------|------------|
| vm0 | UbuntuServer | 16.04 |
|------|---------------|------------|
| vm1 | UbuntuServer | 16.04 |
|------|---------------|------------|
| vm2 | UbuntuServer | 20.04 |
|------|---------------|------------|
如需詳細資訊,請參閱 https://github.com/nalgeon/sqlean/blob/main/docs/re.md。