mysql binary如何使用_MySQL中的binary类型使用操作

本文主要向大家介绍了mysql数据库之mysql的binary类型操作,通过具体的内容向大家展现,希望对大家学习mysql数据库有所帮助。

示例数据表:

create table test_bin (

bin_id binary(16) not null

) engine=innodb;

插入数据(内容是一个32位的uuid字符串值):

insert into test_bin(bin_id) values(unhex(‘fa34e10293cb42848573a4e39937f479‘));

insert into test_bin(bin_id) values(unhex(?));

insert into test_bin(bin_id) values(x‘fa34e10293cb42848573a4e39937f479‘);

查询数据:

select hex(bin_id) as bin_id from test_bin;

select hex(bin_id) as bin_id from test_bin where bin_id = unhex(‘fa34e10293cb42848573a4e39937f479‘);

select hex(bin_id) as bin_id from test_bin where bin_id = unhex(?);

select hex(bin_id) as bin_id from test_bin where bin_id = x‘fa34e10293cb42848573a4e39937f479‘;

查询结果:

bin_id

--------------------------

fa34e10293cb42848573a4e39937f479

备注:使用mysql内置的 uuid() 创建一个函数返回 binary(16)类型的uuid值

create function uu_id() returns binary(16) return unhex(replace(uuid(),‘-‘,‘‘));

create function uu_id() returns binary(16) return unhex(reverse(replace(uuid(),‘-‘,‘‘)));

使用:

insert into test_bin(bin_id) values(uu_id());

范例1:

connection conn = null;

statement stat = null;

resultset rs = null;

try {

conn = jdbcutils.getconnection(map);

string sql = "select hex(recid) as recid,stdname as stdname ,hex(resid) as resid from jyyt";

stat = conn.createstatement();

rs = stat.executequery(sql);

while (rs.next()) {

string recid = rs.getstring("recid");

string staname = rs.getstring("stdname");

string resid = rs.getstring("resid");

system.out.println(recid + "---" + staname + "---" + resid);

}

} catch (sqlexception e) {

e.printstacktrace();

} finally {

jdbcutils.closeconnection(conn, stat, rs);

}

范例2:

select

y.unitid as unitid,

y.unitname as unitname,

y.warningtype as warningtype

from

gxjt_yj as y

left join md_org as m on m.recid = y.unitid

left join pms_company_info as p on m.recid = p.unitid

where

hex(m.parents) like '%66f7b47c80000101d5e8abf15cd9da73%'

and y.warningtype = 'registration_different'

未使用hex()函数:

c00fb1afd4845691f8c86b8d5cd2285e.png

使用hex()函数:

b50d98530a726c4ed79b7a838fdc0e62.png

补充知识:【mysql】如何使用navicat查看mysql数据库中varbinary变量内容?

环境

navicat软件版本:navicat premium 11.1.13(64-bit)

mysql数据库版本:5.7

问题的提出

如题。

步骤

解决方法很简单,备忘。

1、数据库表的设计如下,表中photo变量类型为varbinary。

4d04c12e61a2b329b4166b4b6b6e50eb.png

2、navicat软件显示为乱码,如下。

e910d1f51e6034b6f964fad9e81afcad.png

3、右键“保存数据为”,保存为1.txt。文件名随便起。

66c3dc9f99363c688196f34a8c5d9467.png

4、用ue打开,显示如下。

fa8f5710fe9fdb30d79e1745099dea23.png

以上这篇mysql中的binary类型使用操作就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持萬仟网。

希望与广大网友互动??

点此进行留言吧!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值