codemonth.dk

One project every month - making stuff better ...

Chinese support added to parts of the plsql random data generator

For quite a while I have been wanting to add Chinese support to some of the dbms_random functions, and this last weekend I finally got some time to work a little bit on it. So now the library support Chinese output in functions in the core_random package, text_random package and location_random package.

In core_random you can produce simple random strings of Chinese characters:


SQL> select core_random.r_string(r_country => 'CN') from dual;

CORE_RANDOM.R_STRING(R_COUNTRY=>'CN')   
----------------------------------------------------------------------
黑畺壽甬臼出告爰欠夂色糹辛二甬戶司辰異 

SQL> 

In text random we can produce more "realistic" looking Chinese words, sentences and paragraphs.


SQL> select text_random.r_word(r_country => 'CN') from dual;

TEXT_RANDOM.R_WORD(R_COUNTRY=>'CN')                  
----------------------------------------------------------------------
小免      

SQL> select text_random.r_sentence(r_country => 'CN') from dual;

TEXT_RANDOM.R_SENTENCE(R_COUNTRY=>'CN')  
----------------------------------------------------------------------
厶 酉气鬼 未尞 羽爭才 斗古 有 爿 丁 馬女 需川夫 足東 戶寅 豕周 歹田.

SQL> select text_random.r_paragraph(r_country => 'CN') from dual;

TEXT_RANDOM.R_PARAGRAPH(R_COUNTRY=>'CN')    
---------------------------------------------------------------------------------------------------------------------------------------------------------
才兀 无玄 木鼠辟 豕 匕釆卓 从乇有 巤青未. 思 至矢 它戶 色尗 枼匹 廾而五 舁 重冏 天七 馬 枼麻岡. 廿复 敝彔 㓞祭 用禸 匕手 男 有我 氏牛車 后易 昔車眉 戔自 典元古 飛尹 卅禾. 

SQL> 

So we can create random Chinese sentences and more. Also you can now get Chinese in the location_random library. Just take a look at a few examples.


SQL> select location_random.r_street(r_country => 'CN') from dual;

LOCATION_RANDOM.R_STREET(R_COUNTRY=>'CN') 
----------------------------------------------------------
庚方道   

SQL> select location_random.r_address(r_country => 'CN') from dual;

LOCATION_RANDOM.R_ADDRESS(R_COUNTRY=>'CN')   
---------------------------------------------------------
403 攸典街   

SQL> select location_random.r_state(r_country => 'CN') from dual;

LOCATION_RANDOM.R_STATE(R_COUNTRY=>'CN')  
---------------------------------------------------------
云南省     

And the Chinese integration goes both ways. You can also use Chinese as input to some of the location functions. For instance to get a random Chinese city you can specify the short for of the province to get a city from that specific province.


SQL> select location_random.r_city(r_country => 'CN', r_state => '京') from dual;

LOCATION_RANDOM.R_CITY(R_COUNTRY=>'CN',R_STATE=>'京')  
----------------------------------------------------------
八宝山街道   

SQL> select location_random.r_city(r_country => 'CN', r_state => '辽') from dual;

LOCATION_RANDOM.R_CITY(R_COUNTRY=>'CN',R_STATE=>'辽')     
----------------------------------------------------------
鞍山市  

I will be slowly adding more Chinese support to functions where it actually makes sense.

Tagged in : DBMS_RANDOM, DBMS_SQL, ORDS