The use of database programming--translate

Source: Internet
Author: User




1.translate syntax
Translate (STRING,FROM_STR,TO_STR)
2. Explanation: Each character of the string from_str that exists in a string string is replaced from left to right with each character of the string to_str, and if there is no corresponding, it is replaced with NULL in the string. case-sensitive; to_str cannot be empty;
Example 1:select translate (' project group 24355translate ', ' 234 ', ' @#$ ') from dual; ------------------------------Project group @$ #55translate * * At this time equals @ replaced 2, #替换了3, $ replaced 4
If the length of the FROM_STR is greater than the length of to_str, then there is no corresponding on the string that will be replaced with an empty example 2:select translate (' project group 24355translate ', ' 234 project group ', ' @#$ ') from dual ;       ------------------------------ @$ #55translate * * "project group" three words were deleted in the string because there was no correspondence, or were replaced with an empty one. If the length of the TO_STR is greater than the length of from_str, there is no effect and no exception occurs
Example 3:select translate (' project group 24355translate ', ' 234 ', ' @# $sdfsdfsdf ') from dual; ------------------------------Project group @$ #55translate * * results have no effect
Related applications: 1. Determine whether a string is all numbers sometimes in the processing of a field, the essence of the requirement to fill in the numbers, because the historical data filled with inadequate specifications, resulting in a lot of Chinese or English unqualified garbage data, how to determine whether it is a number? Use replace+translate begin if replace (Translate (' project group requires 321789a8 ', ' 0123456789 ', ' @ '), ' @ ', ') is              Null then Dbms_output.put_line (' This is a number ');              else Dbms_output.put_line (' This is not a number ');        End If; End
Result: This is not a number.




1.translate syntax
Translate (STRING,FROM_STR,TO_STR)
2. Explanation: Each character of the string from_str that exists in a string string is replaced from left to right with each character of the string to_str, and if there is no corresponding, it is replaced with NULL in the string. case-sensitive; to_str cannot be empty;
Example 1:select translate (' project group 24355translate ', ' 234 ', ' @#$ ') from dual; ------------------------------Project group @$ #55translate * * At this time equals @ replaced 2, #替换了3, $ replaced 4
If the length of the FROM_STR is greater than the length of to_str, then there is no corresponding on the string that will be replaced with an empty example 2:select translate (' project group 24355translate ', ' 234 project group ', ' @#$ ') from dual ;       ------------------------------ @$ #55translate * * "project group" three words were deleted in the string because there was no correspondence, or were replaced with an empty one. If the length of the TO_STR is greater than the length of from_str, there is no effect and no exception occurs
Example 3:select translate (' project group 24355translate ', ' 234 ', ' @# $sdfsdfsdf ') from dual; ------------------------------Project group @$ #55translate * * results have no effect
Related applications: 1. Determine whether a string is all numbers sometimes in the processing of a field, the essence of the requirement to fill in the numbers, because the historical data filled with inadequate specifications, resulting in a lot of Chinese or English unqualified garbage data, how to determine whether it is a number? Use replace+translate begin if replace (Translate (' project group requires 321789a8 ', ' 0123456789 ', ' @ '), ' @ ', ') is              Null then Dbms_output.put_line (' This is a number ');              else Dbms_output.put_line (' This is not a number ');        End If; End
Result: This is not a number.


The use of database programming--translate

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.