溫馨提示×

SUBSTR函數(shù)在SQL中的用法示例有哪些

sql
小樊
98
2024-08-18 13:32:34
欄目: 云計(jì)算

  1. 示例一:提取字符串中的子串
SELECT SUBSTR('Hello World', 1, 5) AS Result;

輸出結(jié)果為:Hello

  1. 示例二:獲取字段值的子串
SELECT SUBSTR(column_name, 3) AS Result
FROM table_name;
  1. 示例三:獲取字段值的子串,并指定長度
SELECT SUBSTR(column_name, 3, 5) AS Result
FROM table_name;
  1. 示例四:獲取字段值的子串,并根據(jù)條件篩選
SELECT SUBSTR(column_name, 3) AS Result
FROM table_name
WHERE column_name LIKE '%pattern%';
  1. 示例五:使用SUBSTR函數(shù)進(jìn)行字符串拼接
SELECT SUBSTR('Hello', 1, 3) || SUBSTR('World', 1, 3) AS Result;

輸出結(jié)果為:HelWor

0