Create a daughter character using Compose and Unistr

xiaoxiao2021-03-06  38

Many languages, including English, using the ACCENTED CHARACTER. Because these characters do not belong to the ASCII character set, if the Unicode editor does not use the Unicode editor and turn it into a known character set, it is difficult to write code using these characters.

Oracle9i introduces a Compose function that accepts a string of Unicode characters and rules its text. This means that it can accept one letter and a combination mark, such as 'A' (Unicode character 0097) and the gathering (Unicode character 0300), and then creates a separate character that is combined by two tags. Compose uses special combination tags without using the corresponding synciographs in ASCII, the special combination tags used are part of the Unicode standard. The result of the above example should be a Unicode character 00E0 (with a lowercase Latin letter 'A').

The most common combined characters in ANSI are:

· U 0300: GRAVE ACCENT (`)

· U 0301: Acute Accent (')

· U 0302: Circumflex Accent (^)

· U 0303: Tripate symbol (TILDE) (~)

· U 0308: Voncolic Voice

If there is no special software or keyboard driver, it is difficult to enter Unicode characters 0097 and 0300 on the keyboard. Therefore, one way to enter the Unicode sequence in pure ASCII text is to use the Unistr function. This function accepts a sequence of Unicode characters as a national character set (usually as a 16-bit Unicode or UTF-8 character set). It maps any non-ASCII characters using hexadecimal sequences, and the mapping mode is similar to JAVA.

To enter a sequence of a back a gathering combination character, you can use Unistr ('A / 0300') without trying to enter characters directly in the code. This function can operate normally under any character set and any database with Unicode-based national character set. Multiple combined characters can be placed in a function - you can use ASCII and Unicode placeholders in the UNISTR function. For example, you can use the Unistr function like this:

Select Compose (Unis "('unstr (' unstr ('unstr (' unstr ('unstr") from dual;

When the output of the Unistr function is combined with the Compose, you can generate a Unicode character without finding any value. E.g:

SELECT 'IT IS TRUE' IF Compose (Unistr ('A / 0300')) = Unistr ('/ 00e0');

The Compose function returns a nvarchar2 string, and the NVARCHAR2 string returns is usually Unicode. If you use these characters locally, when you have an implicit TO_CHAR in the result, the database will attempt to map the Unicode character to the local character set. Not all characters can be mapped, some characters are unable to work in Compose, because the Unicode Association does not define them at the level used by Oracle. To quickly check the characters in a specific environment, you can run a script similar to the following script to see how the output combination character is mapped. You may need to determine the NLS_LANG settings to make sure these characters return 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 ('a /' || column_value) A, 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 (Unis (' o / '|| column_value)) O, Compose (Unistr (' R / '|| Column_Value) R, Compose (Unis /' || COLUMN_VALUE)) S, Compose ('u /' || column_value) U, Compose (Unistr ('Y /' || Column_Value) Y from table (HEXRANGE ('0300', '0327'))

Look below, there is a small PL / SQL script here, this script uses Compose and Unistr to create a special effect, many SMS users, hackers and spam senders use this effect to make readable English text difficult to scan, because it Use a random sequence of the character stress version. I use dbms_random to randomly select a combined character that can be used by different characters, then let SQL combine and reverse conversion to generate ANSI / LATIN-1 output. This script uses the EMP table's ENAME field in your code.

Set ServerOutput on; Declare - THESE Combinations Work Under ANSI, AT Least A_COMB NVARCHAR2 (50): = Unis ('/ 0300/0301/0302/0303/0308 / 030a'); c_comb nvarchar2 (50): = Unistr (' / 0327 '); E_COMB NVARCHAR2 (50): = Unistr (' / 0300/0301/0302/0308 '); i_comb nvarchar2 (50): = Unistr (' / 0300/0301/0308 "); n_comb nvarchar2 (50) : = Unistr ('/ 0303'); o_comb nvarchar2 (50): = Unistr ('/ 0300/0308'); u_comb nvarchar2 (50): = Unistr ('/ 0300/0301/0302 / 0308 '); y_comb nvarchar2 (50): = unistr (' / 0301/0308 '); l_idx integer; l_ename nvarchar2 (50); ch nchar; l_junk varcha2 (50); begin dbms_random.initialize (to_char (sysdate,' sssss '); for row in (SELECT ENAME FROM EMP) LOOP L_ENAME: = row.ename; l_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 'Ten 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: =

转载请注明原文地址:https://www.9cbs.com/read-76501.html

New Post(0)