【发布时间】:2011-02-14 18:49:48
【问题描述】:
我正在使用 T-SQL 块来获取存储在数据库列中的 ascii 字符转储。我知道这很容易在 Oracle 中使用 DUMP() 函数完成。我对 SQL Server 语法不太熟悉,但我正在使用类似的东西。
SET NOCOUNT ON
-- Create the variables for the current character string position
-- and for the character string.
DECLARE @position int, @string char(15), @output char(1000), @output2 char(2000)
-- Initialize the variables.
SET @position = 1
SET @output2 = 'Start:'
SELECT @string = name from
location where location_type = 4405 and owner_id = 362
and location_id = 53183
WHILE @position <= DATALENGTH(@string)
BEGIN
SELECT @output = CAST(ASCII(SUBSTRING(@string, @position, 1)) AS CHAR)
+ ' ' + CHAR(ASCII(SUBSTRING(@string, @position, 1)))
PRINT @output
--SET @output2 = @output2 + '=' + @output
SET @position = @position + 1
END
--PRINT @output2
SET NOCOUNT OFF
GO
由于某种原因,如果我取消注释与@output2 相关的代码,它将无法正确打印@output2。 这个想法是将所有 ascii 值作为单行返回,而不是为每个字符获取一行。难道我做错了什么?
【问题讨论】:
-
你的意思是不会正确打印@output2?你有什么行为?
-
是否有一些控制字符写入到 Output2 并且无法打印?
-
@output2 将始终打印“开始:”,这是我将其初始化的内容。我不确定控制字符,因为这是我想要找出的。
标签: sql tsql sql-server-2008 dump