Oracle Chinese Digital to Arabic numerals

Source: Internet
Author: User

CREATE OR REPLACE FUNCTION chi2num (chivalue in VARCHAR2) RETURN number is

TYPE MAP is TABLE of Binary_integer INDEX by VARCHAR2 (10);
Ling_jiu_map map;
Shibaiqian_map map;
Wanyizhao_map map;
--Temporary variables
I INT: = 0; --' Temporary variable
K INT: = 0; --Temporary variables
X INT: = 0; --Temporary variables
STR VARCHAR2 (100): = "; --Temporary variables
TMP INT: = 0; --Temporary variables
TMP2 INT: = 0; --Temporary variables
Integer_part VARCHAR2 (100): = "; --integral part of digital form
Float_part VARCHAR2 (100): = "; --digital form of small part
ReturnValue number: = 0; --Return value
BEGIN
--Initialize Array
Ling_jiu_map (' 0 '): = 0;
Ling_jiu_map (' one '): = 1;
Ling_jiu_map (' two '): = 2;
Ling_jiu_map (' three '): = 3;
Ling_jiu_map (' four '): = 4;
Ling_jiu_map (' five '): = 5;
Ling_jiu_map (' six '): = 6;
Ling_jiu_map (' seven '): = 7;
Ling_jiu_map (' eight '): = 8;
Ling_jiu_map (' IX '): = 9;
Shibaiqian_map ("): = 0;
Shibaiqian_map (' ten '): = 1;
Shibaiqian_map (' hundred '): = 2;
Shibaiqian_map (' thousand '): = 3;
Wanyizhao_map ("): = 0;
Wanyizhao_map (' million '): = 1;
Wanyizhao_map (' billion '): = 2;
Wanyizhao_map (' Mega '): = 3;

str: = Regexp_replace (Chivalue, ' ^ Ten ', ' 10 ');
str: = Regexp_replace (str, ' 10 ', ' 10 ');
--splitting a number into integers and floating-point numbers two numeric arrays
I: = INSTR (str, ' point ', 1);

IF i = 0 Then
Integer_part: = SUBSTR (str, 1);
ELSE
Integer_part: = SUBSTR (str, 1, i-1);
Float_part: = SUBSTR (str, i + 1);
END IF;

--Integral type part
x: = LENGTH (Integer_part);
str: = ';
TMP: = 0;
TMP2: = 0;

  for K in 1 ... x LOOP
    str: = SUBSTR (Integer_part, K, 1);
 
    if str in (' million ', ' billion ', ' Mega ') then
     --when it hits trillions of megabytes
       tmp        : = tmp + TMP2;
      returnvalue: = returnvalue + tmp * POWER (10000, Wanyizhao_map (str));
      tmp        : = 0;
      tmp2       : = 0;
    elsif str in (' Ten ', ' hundred ', ' thousand ') then
     --when encountering Chichong
  & nbsp;   tmp : = tmp + TMP2 * POWER (Shibaiqian_map (str));
      TMP2: = 0;
    ELSE
     --When a number is encountered
      TMP2: = Ling_jiu_map (str);
    END IF;
  END LOOP;

--Finally, no less than the number of thousands of digits added to the integer
TMP: = tmp + TMP2;
ReturnValue: = returnvalue + tmp;

IF Float_part is isn't NULL then
--Calculate the part of a small number
K: = 0;
TMP: = ';

For k in 1.. LENGTH (Float_part) LOOP
TMP: = TMP | | Ling_jiu_map (SUBSTR (Float_part, K, 1));
END LOOP;

ReturnValue: = ReturnValue | | '. ' | | tmp
END IF;

RETURN returnvalue;
END;

650) this.width=650; "title=" 001.png "src=" http://s4.51cto.com/wyfs02/M01/7F/78/ Wkiom1cfzlmw6ryhaaa-0intar0455.png "alt=" Wkiom1cfzlmw6ryhaaa-0intar0455.png "/>

This article is from the "struggling small snail" blog, please be sure to keep this source http://sparkkang.blog.51cto.com/11242173/1768030

Oracle Chinese Digital to Arabic numerals

Related Article

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.