您好,登錄后才能下訂單哦!
本篇內容主要講解“PostgreSQL的dump函數有什么作用”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“PostgreSQL的dump函數有什么作用”吧!
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函數有什么作用”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。