文档介绍:程序清单8-08:使用 LTRIM 函数删除字符变量中的起始空格。
DECLARE ***@string_to_trim varchar(60)
SET ***@string_to_trim = ' Five spaces are at the beginning of this
string.'
SELECT 'Here is the string without the leading spaces: ' +
LTRIM(***@string_to_trim
运行结果为:
------------------------------------------------------------------------
Here is the string without the leading spaces: Five spaces are at the beginning of this string.
程序清单8-09:使用 LEFT 函数返回字符串 abcdefg 最左边的 4 个字符。
SELECT LEFT('abcdefg',4)
运行结果为:
-------
abcd
程序清单8-10:使用可选的 start_location 参数从 notes 列的第五个字符开始查找"wonderful"。
USE pubs
SELECT CHARINDEX('wonderful', notes,5) FROM titles
WHERE title_id = 'TC3218'
运行结果为:
-----------
46
程序清单8-11:将指定的字符串的排列顺序颠倒。
select reverse(123), reverse(“abc”)
运行结果为:
----------------
321 cba
程序清单8-12:在第一个字符串(abcdef) 中删除从第二个位置(字符 b)开始的三个字符,然后在删除的起始位置插入第二个字符串,创建并返回一个字符串。
SELECT STUFF('abcdef', 2, 3, 'ijklmn')
运行结果为:
---------
aijklmnef