Use compose and unistr to create audio sink characters

Source: Internet
Author: User

Many languages, including English, use accented character ). Because these characters do not belong to the ASCII character set, it is difficult to compile code that uses these characters if you do not view the Unicode value or use the Unicode editor and convert it into a known character set.

Oracle9i introduces the compose function, which accepts a string of Unicode characters and standardizes the text. This means that it can accept a letter and a combination of tags, such as 'A' (UNICODE character 0097) and Shen note (UNICODE character 0300 ), then create a separate character composed of two tags. Compose uses a special combination mark instead of the corresponding syllable mark in ASCII. The special combination mark it uses is part of the Unicode standard. The result of the above example should be the Unicode Character 00e0 (there is a lowercase Latin Letter 'A' of the Shen note ').

The most common characters in ANSI are:

· U + 0300: grave accent )(')

· U + 0301: acute accent )(')

· U + 0302: circumflex accent (^)

· U + 0303: Tilde )(~)

· U + 0308: vowels

Without special software or keyboard drivers, it is difficult to enter Unicode characters 0097 and 0300 on the keyboard. Therefore, one way to input Unicode sequences in plain ASCII text is to use the unistr function. This function accepts an ASCII string and then creates a sequence of Unicode characters in a national character set (typically installed as a 16-bit Unicode or UTF-8 character set. It uses a hexadecimal placeholder sequence to map any non-ASCII characters, similar to Java.

EnterAYou can use unistr ('A/123456') instead of entering characters in the code. This function works properly in any character set and any database with Unicode-based national character sets. Multiple character combinations can be placed in the function-ASCII and Unicode placeholders can be mixed in the unistr function. For example, you can use the unistr function as follows:

Select compose (unistr ('unless you are NAI/0308ve, meet me at the cafe/0301
Your Re/0301 Sume/0301. ') from dual;

When combining the output and compose of the unistr function, you can generate a Unicode character without looking for any value. For example:

Select 'it is true' if compose (unistr ('A/100') = unistr ('/00e0 ');

The compose function returns an nvarchar2 string, which is generally Unicode-based. If these characters are used locally and the result contains an implicit to_char, the database attempts to map Unicode characters to the local character set. Not all characters can be mapped. Some character combinations cannot work in compose because Unicode associations do not define them at the level used by Oracle.

To quickly check how characters are queried in a specific environment, you can run a script similar to the following script to see how the output composite characters are mapped. You may need to confirm the nls_lang settings to ensure that these characters are returned correctly:

Create or replace type hexrange_tbl as table of varchar2 (4 );
/
Show errors;

Create or replace function hexrange (N1 varchar2, N2 varchar2)
Return hexrange_tbl pipelined
Is
Begin
For I in to_number (N1, '000x') .. to_number (N2, '000x') loop
Pipe row (to_char (I, 'fm000x '));
End loop;
Return;
End hexrange;
/
Show errors;

Select column_value composer,
Compose (unistr ('A/'| column_value),
Compose (unistr ('C/'| column_value) c,
Compose (unistr ('E/'| column_value) e,
Compose (unistr ('I/' | column_value) I,
Compose (unistr ('n'/'| column_value) n,
Compose (unistr ('o/'| column_value) O,
Compose (unistr ('R/'| column_value) R,
Compose (unistr ('s/'| column_value) s,
Compose (unistr ('U/'| column_value) U,
Compose (unistr ('y/'| column_value) y
From table (hexrange ('20140901', '20160901') X;

Here is a short PL/SQL script, which uses compose and unistr to create a special effect, many SMS users, hackers, and spam senders use this effect to make it difficult to scan readable English text because it uses a random sequence of character-accent versions. I use dbms_random to randomly select a composite character that can be used by different characters, and then let the SQL statement combine and perform reverse conversion to generate the ANSI/Latin-1 output. This script uses the ename field of the EMP table in the code.

Set serveroutput on;
Declare
-- These combinations work under ANSI, at least
A_comb nvarchar2 (50): = unistr ('/0300/0301/0302/0303/0308/030 ');
C_comb nvarchar2 (50): = unistr ('/000000 ');
E_comb nvarchar2 (50): = unistr ('/0300/0301/123 ');
I _comb nvarchar2 (50): = unistr ('/0300/0301/123 ');
N_comb nvarchar2 (50): = unistr ('/000000 ');
O_comb nvarchar2 (50): = unistr ('/0300/0301/0302/0303/0308 ');
U_comb nvarchar2 (50): = unistr ('/0300/0301/123 ');
Y_comb nvarchar2 (50): = unistr ('/000000 ');
Rochelle idx integer;
Rochelle ename nvarchar2 (50 );
Ch nchar;
L_junk varchar2 (50 );
Begin
Dbms_random.initialize (to_char (sysdate, 'ssss '));
For row in (select ename from EMP) loop
Rochelle ename: = row. ename;
Rochelle junk: = NULL;
For I in 1 .. length (l_ename) loop
Ch: = substr (l_ename, I, 1 );
Case lower (CH)
When 'A' then
L_junk: = l_junk | compose (CH | substr (a_comb,
MoD (ABS (dbms_random.random), length (a_comb) + 1, 1 ));
When 'C' then
L_junk: = l_junk | compose (CH | substr (c_comb,
MoD (ABS (dbms_random.random), length (c_comb) + 1, 1 ));
When 'E' then
L_junk: = l_junk | compose (CH | substr (e_comb,
MoD (ABS (dbms_random.random), length (e_comb) + 1, 1 ));
When 'I 'then
L_junk: = l_junk | compose (CH | substr (I _comb,
MoD (ABS (dbms_random.random), length (I _comb) + 1, 1 ));
When 'n' then
L_junk: = l_junk | compose (CH | substr (n_comb,
MoD (ABS (dbms_random.random), length (n_comb) + 1, 1 ));
When 'O' then
L_junk: = l_junk | compose (CH | substr (o_comb,
MoD (ABS (dbms_random.random), length (o_comb) + 1, 1 ));
When 'U' then
L_junk: = l_junk | compose (CH | substr (u_comb,
MoD (ABS (dbms_random.random), length (u_comb) + 1, 1 ));
When 'y' then
L_junk: = l_junk | compose (CH | substr (y_comb,
MoD (ABS (dbms_random.random), length (y_comb) + 1, 1 ));
Else
L_junk: = l_junk | ch;
End case;
End loop;
Dbms_output.put_line (to_char (l_junk ));
End loop;
End;
/
Show errors;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.