返回字符串的函数

返回字符串的函数

说明

示例

CHR

将 ASCII 代码转换为一个字符的字符串

CHR(67) 返回 C

CURRENT_USER

返回在连接时指定的登录 ID

 

DAYNAME

返回与指定日期对应的是星期几

 

RTRIM

删除字符串末尾的空格

RTRIM('ABC ') 返回 'ABC'

TRIM

删除字符串的前导和末尾空格

TRIM(' ABC ') 返回 'ABC'

LTRIM

删除字符串的前导空格

LTRIM(' ABC') 返回 'ABC'

UPPER

将字符串的每个字母更改为大写

UPPER('Allen') 返回 'ALLEN'

LOWER

将字符串的每个字母更改为小写

LOWER('Allen') 返回 'allen'

LEFT

返回字符串最左侧的字符

LEFT('Mattson',3) 返回 'Mat'

MONTHNAME

返回日历月份的名称

 

RIGHT

返回字符串最右侧的字符

RIGHT('Mattson',4) 返回 'tson'

SUBSTR

SUBSTRING

返回字符串的子字符串,含字符串的参数,要提取的第一个字符和要提取的字符数(可选)

SUBSTR('Conrad',2,3) 返回 'onr'
SUBSTR('Conrad',2)
返回 'onrad'

SPACE

生成空格字符串

SPACE(5) 返回 '     '

STRVAL

将任何类型的值转换为字符串

STRVAL('Woltman') 返回 'Woltman'
STRVAL(5 * 3)
返回 '15'
STRVAL(4 = 5)
返回 'False'
STRVAL(DATE '2028-12-25')

返回 '2028-12-25'

TIME

TIMEVAL

以字符串的形式返回当天的时间

在晚上 9:49,TIME() 返回 21:49:00

USERNAME

USER

返回在连接时指定的登录 ID

 

注释  TIME() 函数已弃用。请改为使用 SQL 标准 CURRENT_TIME

示例

复制
SELECT CHR(67) + SPACE(1) + CHR(70) FROM Salespeople

SELECT RTRIM(' ' + Salespeople.Salesperson_ID) AS agg FROM Salespeople

SELECT TRIM(SPACE(1) + Salespeople.Salesperson_ID) AS agg FROM Salespeople

SELECT LTRIM(' ' + Salespeople.Salesperson_ID) AS agg FROM Salespeople

SELECT UPPER(Salespeople.Salesperson) AS agg FROM Salespeople

SELECT LOWER(Salespeople.Salesperson) AS agg FROM Salespeople

SELECT LEFT(Salespeople.Salesperson, 5) AS agg FROM Salespeople

SELECT RIGHT(Salespeople.Salesperson, 7) AS agg FROM Salespeople

SELECT SUBSTR(Salespeople.Salesperson_ID, 2, 2) + 
   SUBSTR(Salespeople.Salesperson_ID, 4, 2) AS agg FROM Salespeople

SELECT SUBSTR(Salespeople.Salesperson_ID, 2) + 
   SUBSTR(Salespeople.Salesperson_ID, 4) AS agg FROM Salespeople

SELECT SPACE(2) + Salespeople.Salesperson_ID AS Salesperson_ID FROM Salespeople

SELECT STRVAL('60506') AS agg FROM Sales_Data WHERE Sales_Data.Invoice = 1