ASCII (Transact-SQL)

傳回字元運算式最左側字元的 ASCII 字碼值。

適用於:SQL Server (SQL Server 2008 透過目前版本)、Windows Azure SQL 資料庫 (初始版本,透過目前版本)。

主題連結圖示 Transact-SQL 語法慣例

語法

ASCII ( character_expression )

引數

  • character_expression
    這是一個 char 或 varchar 類型的運算式

傳回類型

int

範例

下列範例假設 ASCII 字元集,且會傳回 Du monde entier 字串中每個字元的 ASCII 值和 CHAR 字元。

SET TEXTSIZE 0;
SET NOCOUNT ON;
-- Create the variables for the current character string position 
-- and for the character string.
DECLARE @position int, @string char(15);
-- Initialize the variables.
SET @position = 1;
SET @string = 'Du monde entier';
WHILE @position <= DATALENGTH(@string)
   BEGIN
   SELECT ASCII(SUBSTRING(@string, @position, 1)),
      CHAR(ASCII(SUBSTRING(@string, @position, 1)))
    SET @position = @position + 1
   END;
SET NOCOUNT OFF;
GO

以下為結果集:

----------- - 
68          D 
              
----------- - 
117         u 
              
----------- - 
32            
              
----------- - 
109         m 
              
----------- - 
111         o 
              
----------- - 
110         n 
              
----------- - 
100         d 
              
----------- - 
101         e 
              
----------- - 
32            
              
----------- - 
101         e 
              
----------- - 
110         n 
              
----------- - 
116         t 
              
----------- - 
105         i 
              
----------- - 
101         e 
              
----------- - 
114         r

請參閱

參考

字串函數 (Transact-SQL)