本篇內(nèi)容主要講解“PostgreSQL的dump函數(shù)有什么作用”,感興趣的朋友不妨來看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“PostgreSQL的dump函數(shù)有什么作用”吧!
成都創(chuàng)新互聯(lián)公司是專業(yè)的北鎮(zhèn)網(wǎng)站建設(shè)公司,北鎮(zhèn)接單;提供成都網(wǎng)站建設(shè)、做網(wǎng)站,網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行北鎮(zhèn)網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!
Oracle提供了dump函數(shù)顯示字段的十六進(jìn)制值,PostgreSQL可通過to_hex函數(shù)來進(jìn)行模擬.
Oracle
測(cè)試腳本:
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十六進(jìn)制值
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
數(shù)據(jù)庫是用GBK編碼,因此’中文’字符編碼為GBK編碼.
PG
創(chuàng)建dump函數(shù)
[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
執(zhí)行dump函數(shù),顯示十六進(jìn)制值
[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
到此,相信大家對(duì)“PostgreSQL的dump函數(shù)有什么作用”有了更深的了解,不妨來實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!