sql server 2008 - SQL convert string data in hexadecimal format into string text -


i have table has column x. x storing large text values in hex format. want convert hex raw , validate data. when using below query, getting part of text after running query not complete text. original text large....

select utl_raw.cast_to_varchar2(hextoraw(x)) table name  

i tried below query, no use extracts same

decalre @a varchar(max) select utl_raw.cast_to_varchar2(hextoraw(x)) new  table name. 

kindly let me know how can extract or see large text sql. sample query may helpful.

for ms-sql 2008 following stored proc convert hex string varchar(max):

if exists (select * dbo.sysobjects name = 'f_hextostr' , xtype = 'fn') drop function [dbo].[f_hextostr] go  create function [dbo].[f_hextostr] (@hexstring varchar(max)) returns varchar(max)   begin  declare @char1 char(1), @char2 char(1), @strlen int, @currpos int, @result varchar(max)  set @strlen=len(@hexstring)  set @currpos=1  set @result=''  while @currpos<@strlen   begin    set @char1=substring(@hexstring,@currpos,1)    set @char2=substring(@hexstring,@currpos+1,1)    if (@char1 between '0' , '9' or @char1 between 'a' , 'f')     , (@char2 between '0' , '9' or @char2 between 'a' , 'f')     set @result=@result+      char((ascii(@char1)-case when @char1 between '0' , '9' 48 else 55 end)*16+      ascii(@char2)-case when @char2 between '0' , '9' 48 else 55 end)    set @currpos = @currpos+2   end  return @result end go 

to use like:

select dbo.f_hextostr('0x3031323') 

or

select dbo.f_hextostr(x) mytable 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -