A mixed approach to Chinese and English characters

Source: Internet
Author: User
Tags mixed

When 1,txt files are imported into SQL

303410001401??????? 4-t LANG and Yue IG? 0220??? 011840628900000?? Bpo
303410001501??????? Landau in ER? 0220??? 011840628900000?? Bpo
303410001601??????? The LANG 6-t the Han ig? 0220??? 011840628900000?? Bpo

There is a TXT file to import SQL, there is a fixed data format, because there is no obvious definition of the character, the guide into a column, and then in the SQL interception separation, there are the following problems:

The length of the data structure given is a single-byte length, but the use of substring () in SQL is only one, in some requirements because the Chinese character is no fixed position, such as only one will affect the correctness of the following data

Workaround: Cast (substring (CAST (col001 as varbinary (1000), 39,4) as char () as time_id

The first is to convert the field to varbinary type, so that the Chinese characters are also 2 bits, interception will meet the fixed format requirements, and then back to the character type.

2,sql table exported to txt

Use CAST (????? as char (20)) to qualify

3, take the length

Len () Chinese characters are only 1 digits

Use Datalength () Kanji to count 2 digits



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.