我在mssql中有这样一段代码
declare @byte1 binary(1)
declare @byte2 binary(1)
declare @smallint smallint
set @smallint = 675
set @byte1 = @smallint & 0xFF
set @byte2 = (@smallint & 0xFF00) / 0x100select @byte1 a, @byte2 b, @byte1+@byte2 c执行结果是:
a b c
0xA3 0x02 0xA302在mysql中我该怎么做才能得到正确结果呢?
declare @byte1 binary(1)
declare @byte2 binary(1)
declare @smallint smallint
set @smallint = 675
set @byte1 = @smallint & 0xFF
set @byte2 = (@smallint & 0xFF00) / 0x100select @byte1 a, @byte2 b, @byte1+@byte2 c执行结果是:
a b c
0xA3 0x02 0xA302在mysql中我该怎么做才能得到正确结果呢?
解决方案 »
- MySQL当表数据量极大时[单张表800万条记录],如何提高查询及更新速度?
- 为了建立索引,固定长度的01串在mysql表中用什么类型存储较好?谢谢
- 关于记录累加的问题
- windows下,最简单的mysql的数据库的备份和恢复。
- mysql如何使用索引的呢?
- .net 2005 中如何连接 my sql数据库
- mysql在行命令下操作命令错误就鸣叫,太恶心了吧?能去掉ma
- mssql->mysql 后为何出现'\r\n'字符
- About mySQL install(online hold)
- 急求mysql 断电后无法启动解决方法
- 我的MYSQL有非常多的TIME_WAIT链接
- 远程查询数据库,中文显示乱码!
我是想问怎样把它转换为mysql :)
问题说明越详细,回答也会越准确!参见如何提问。(提问的智慧)
在mysql中我这样写:
CREATE FUNCTION `Sint16ToBinary2`(small_int smallint) RETURNS binary(2)
BEGIN
declare byte1 binary(1);
declare byte2 binary(1);
set @byte1 = small_int & 0xFF;
set @byte2 = (small_int & 0xFF00) / 0x100;
RETURN ( @byte1 + @byte2) ;
END显然这里有错误,如下
mysql> set @a = Sint16ToBinary2(675);
1406 - Data too long for column 'Sint16ToBinary2' at row 1我想得到的结果,以675为例
set @byte1 = small_int & 0xFF; # 结果a3
set @byte2 = (small_int & 0xFF00) / 0x100; # 结果2需要得到a302,而不是 a3+2=a5.
BINARY和VARBINARY类类似于CHAR和VARCHAR,不同的是它们包含二进制字符串而不要非二进制字符串。也就是说,它们包含字节字符串而不是字符字符串。这说明它们没有字符集,并且排序和比较基于列值字节的数值值。sqlserver
binary(n)
固定长度的二进制数据,最大长度为 8000 字节。默认长度 = 1。存储大小是固定的,是在类型中声明的以字节为单位的长度。
使用char()函数来生成longblob数据
,nID int
,nLv tinyint
,nOtherID int
,iRate int) RETURNS longblob
BEGIN
return char(iPos&0xFF,
nID&0xFF,
(nID&0xFF00) / 0x100,
nLv&0xFF,
nOtherID&0xFF,
(nOtherID&0xFF00) / 0x100,
iRate&0xFF,
(iRate&0xFF00) / 0x100
);
END