如何在Teradata中将字符串转换为二进制?

时间:2021-09-05 22:49:48

I don't find any functions to convert string to binary in Teradata Database manual-SQL Reference -Functions and Operators. Cast string to byte does not work too.

我在Teradata Database手册-SQL Reference -Functions和Operators中找不到任何将字符串转换为二进制的函数。将字符串转换为字节也不起作用。

SELECT C1, C2 FROM table WHERE C1 < (cast( ('QREPI.\k'||'00'XC||'00'XC||'00'XC||'00'XC||'00' XC||'00'XC||'00'XC||'00'XC||'00'XC||'00'XC||'00'XC||'00'XC||'00'XC||' ..') as byte(24)) )); *** Failure 3532 Conversion between BYTE data and other types is illegal. Statement# 1, Info =0

SELECT C1,C2 FROM table WHERE C1 <(cast((''QREPI。\ k'||'00'XC || '00'XC ||'00'XC || '00'XC ||''XC | | '00'XC ||' 00'XC || '00'XC ||' 00'XC || '00'XC ||' 00'XC || '00'XC ||' 00'XC ||” ..')as byte(24)))); ***失败3532 BYTE数据与其他类型之间的转换是非法的。声明#1,信息= 0

Anybody knows if Teradata provides a way for the conversion?

有人知道Teradata是否提供转换方式?

Any comments are highly appreciated.

任何评论都非常感谢。

2 个解决方案

#1


If all you need is a literal, you can get a binary equivalent of your string like this:

如果你需要的只是一个文字,你可以得到一个二进制等价的字符串,如下所示:

SELECT C1, C2 FROM table
WHERE C1 < '51524550492e5c6b000000000000000000000000'xb

Otherwise, for data that is stored in your tables in hex it could be done within Teradata by writing a new UDF. Or you could export it to a file, transform it with a program, and load it back.

否则,对于以十六进制存储在表中的数据,可以通过编写新的UDF在Teradata中完成。或者您可以将其导出到文件,使用程序对其进行转换,然后将其加载回来。

#2


According to their blog you should be able to do it with implicit casting (but not explicit). I take that to mean something like:

根据他们的博客,您应该能够使用隐式转换(但不明确)。我认为这意味着:

SELECT C1, C2 
  FROM table 
  WHERE C1 < ('QREPI.\k'||'00'XC||'00'XC||'00'XC||'00'XC||'00'XC||
     '00'XC||'00'XC||'00'XC||'00'XC||'00'XC||'00'XC||'00'XC||'00'XC||' ..');

Have you tried that?

你试过吗?

#1


If all you need is a literal, you can get a binary equivalent of your string like this:

如果你需要的只是一个文字,你可以得到一个二进制等价的字符串,如下所示:

SELECT C1, C2 FROM table
WHERE C1 < '51524550492e5c6b000000000000000000000000'xb

Otherwise, for data that is stored in your tables in hex it could be done within Teradata by writing a new UDF. Or you could export it to a file, transform it with a program, and load it back.

否则,对于以十六进制存储在表中的数据,可以通过编写新的UDF在Teradata中完成。或者您可以将其导出到文件,使用程序对其进行转换,然后将其加载回来。

#2


According to their blog you should be able to do it with implicit casting (but not explicit). I take that to mean something like:

根据他们的博客,您应该能够使用隐式转换(但不明确)。我认为这意味着:

SELECT C1, C2 
  FROM table 
  WHERE C1 < ('QREPI.\k'||'00'XC||'00'XC||'00'XC||'00'XC||'00'XC||
     '00'XC||'00'XC||'00'XC||'00'XC||'00'XC||'00'XC||'00'XC||'00'XC||' ..');

Have you tried that?

你试过吗?