postgresql , 字元集 , 漢字編碼 , 随機漢字 , chr , ascii , unicode
4e00 對應 19968
9fa5 對應 40869
一共 20901 個漢字
注意,為了保證能輸出所有的漢字,確定資料庫的編碼為utf8,否則會報類似錯誤。
例子
除了unicode的寫法,postgresql還提供了兩個函數,支援數值的寫法。
function
return type
description
example
result
ascii(string)
int
ascii code of the first character of the argument. for utf8 returns the unicode code point of the character. for other multibyte encodings, the argument must be an ascii character.
ascii('x')
120
chr(int)
text
character with the given code. for utf8 the argument is treated as a unicode code point. for other multibyte encodings the argument must designate an ascii character. the null (0) character is not allowed because text data types cannot store such bytes.
chr(65)
a
建立函數
使用函數,生成随機漢字
<a href="http://baike.baidu.com/item/unicode">http://baike.baidu.com/item/unicode</a>
<a href="http://unicode.org/charts/">http://unicode.org/charts/</a>
<a href="https://en.wikipedia.org/wiki/unicode">https://en.wikipedia.org/wiki/unicode</a>
<a href="https://github.com/digoal/blog/blob/master/201704/20170402_01.md">《postgresql 轉義、unicode、與sql注入》</a>
<a href="http://stackoverflow.com/questions/3970795/how-do-you-create-a-random-string-thats-suitable-for-a-session-id-in-postgresql">http://stackoverflow.com/questions/3970795/how-do-you-create-a-random-string-thats-suitable-for-a-session-id-in-postgresql</a>
<a href="https://www.postgresql.org/docs/9.6/static/functions-string.html">https://www.postgresql.org/docs/9.6/static/functions-string.html</a>