Use cursor to convert the format of specified fields in the data table in Oracle (pinyin to numbers)

Source: Internet
Author: User

Use cursor to convert the format of specified fields in the data table in Oracle (pinyin to numbers)

Application Scenario: Convert [sannanyinv] to [3 male and 1 female] In the NNDP field of the data table TB_USER.

Main Script: A cursor script + split string Function + pinyin to digital script

The procedure is as follows:

1. Creation type

2. Create the fn_splitString function (which splits the string into multiple records)

-- Fn_splitString function script code

Return splitTable is

Var_out splitTable;

Begin

-- Var_out.extend (1 );

Return var_out;

3. create function fn_getNumber (function is to convert a digit into a digit)

-- Fn_getNumber function script code

Create or replace function fn_getNumber (p_str in varchar2)

4. Run the conversion script to convert the specified fields in the data table to the required format)

-- Convert the content of a specified field from pinyin to a number in a data table using a cursor in Oracle.

Femalestring VARCHAR2 (20): = 'er'; -- defines the male pinyin delimiter.

Columnstring NVARCHAR2 (40): = ''; -- defines the string content retrieved from the data table field.

Cursor mycursor is select * from TB_USER where NNDP <> ''; -- query the records to be updated from the data table:

If mycursor % found then -- the cursor's found attribute determines whether a record exists

-- Obtain and process the field content

If mycursor1 % found then -- determines whether a record exists

Else

Dbms_output.put_line (resultstring); -- display the result

End;

Else

Appendix: Run

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.