在SQL中将字符串转换为HEX [英] Converting a String to HEX in SQL

查看:749
本文介绍了在SQL中将字符串转换为HEX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法将真正的字符串转换为SQL中的十六进制值。我正在寻找一些对Informix友好的东西,但我显然更喜欢一些与数据库无关的东西。

I'm looking for a way to transform a genuine string into it's hexadecimal value in SQL. I'm looking something that is Informix-friendly but I would obviously prefer something database-neutral

这里是我现在使用的select:

Here is the select I am using now:

SELECT SomeStringColumn from SomeTable

这里是我想要使用的select:
SELECT Some(SomeStringColumn)from SomeTable

Here is the select I would like to use: SELECT hex( SomeStringColumn ) from SomeTable

不幸的是,没有那么简单... Informix给了我这样的信息:
数字转换错误字符

Unfortunately nothing is that simple... Informix gives me that message: Character to numeric conversion error

有什么想法?

Any idea?

推荐答案

您可以使用Cast和fn_varbintohexstr?

Can you use Cast and the fn_varbintohexstr?

SELECT master.dbo.fn_varbintohexstr(CAST(SomeStringColumn AS varbinary)) 
FROM SomeTable

我不确定您是否拥有该功能在你的数据库系统中,它在MS-SQL中。

I'm not sure if you have that function in your database system, it is in MS-SQL.

我在我的SQL服务器MMC中的一个表上试过它:

I just tried it in my SQL server MMC on one of my tables:

SELECT     master.dbo.fn_varbintohexstr(CAST(Addr1 AS VARBINARY)) AS Expr1
FROM         Customer

。可能我在MS-SQL上知道的master.dbo.fn_varbintohexstr可能类似于informix hex()函数,所以可能试试:

This worked as expected. possibly what I know as master.dbo.fn_varbintohexstr on MS-SQL, might be similar to informix hex() function, so possibly try:

SELECT     hex(CAST(Addr1 AS VARBINARY)) AS Expr1
FROM         Customer

这篇关于在SQL中将字符串转换为HEX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆