本篇内容主要讲解“PostgreSQL的dump函数有什么作用”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“PostgreSQL的dump函数有什么作用”吧!
成都创新互联公司是专业的北镇网站建设公司,北镇接单;提供成都网站建设、做网站,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行北镇网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
Oracle提供了dump函数显示字段的十六进制值,PostgreSQL可通过to_hex函数来进行模拟.
Oracle
测试脚本:
TEST-orcl@DESKTOP-V430TU3>CREATE TABLE t_dumpdemo(description varchar(200)); Table created. TEST-orcl@DESKTOP-V430TU3> TEST-orcl@DESKTOP-V430TU3>INSERT INTO t_dumpdemo VALUES('中文'); 1 row created. TEST-orcl@DESKTOP-V430TU3>INSERT INTO t_dumpdemo VALUES('ABCDE'); 1 row created. TEST-orcl@DESKTOP-V430TU3> TEST-orcl@DESKTOP-V430TU3>SELECT * FROM t_dumpdemo; DESCRIPTION -------------------------------------------------------------------------------- 中文 ABCDE
dump十六进制值
TEST-orcl@DESKTOP-V430TU3>select dump(description,1016) from t_dumpdemo; DUMP(DESCRIPTION,1016) -------------------------------------------------------------------------------- Typ=1 Len=4 CharacterSet=ZHS16GBK: d6,d0,ce,c4 Typ=1 Len=5 CharacterSet=ZHS16GBK: 41,42,43,44,45
数据库是用GBK编码,因此’中文’字符编码为GBK编码.
PG
创建dump函数
[local]:5432 pg12@testdb=# CREATE OR REPLACE FUNCTION dump(anynonarray) RETURNS TEXT pg12@testdb-# LANGUAGE plpgsql pg12@testdb-# AS pg12@testdb-# $function$ pg12@testdb$# DECLARE pg12@testdb$# v_hexstr TEXT; pg12@testdb$# v_hexbyte TEXT; pg12@testdb$# v_tmp TEXT; pg12@testdb$# i INT; pg12@testdb$# v_len INT; pg12@testdb$# BEGIN pg12@testdb$# SELECT octet_length($1) into v_len; pg12@testdb$# v_hexstr := 'Len=' || v_len || ' '; pg12@testdb$# v_tmp := ','; pg12@testdb$# FOR i in 1..v_len LOOP pg12@testdb$# select to_hex(get_byte($1::bytea, i-1)) into v_hexbyte; pg12@testdb$# if i = v_len then pg12@testdb$# v_tmp := ''; pg12@testdb$# end if; pg12@testdb$# v_hexstr := v_hexstr || v_hexbyte || v_tmp; pg12@testdb$# END LOOP; pg12@testdb$# -- SELECT encode($1::bytea,'hex') into v_hexbyte; pg12@testdb$# -- v_hexstr := v_hexstr||','||v_hexbyte; pg12@testdb$# RETURN v_hexstr; pg12@testdb$# END; pg12@testdb$# $function$; CREATE FUNCTION Time: 3.621 ms
执行dump函数,显示十六进制值
[local]:5432 pg12@testdb=# select dump(description) from t_dumpdemo; dump ------------------------- Len=6 e4,b8,ad,e6,96,87 Len=5 41,42,43,44,45 (2 rows) Time: 1.337 ms
到此,相信大家对“PostgreSQL的dump函数有什么作用”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!