Oracle custom function to determine whether data is a numeric function, oracle Value

Source: Internet
Author: User

Oracle custom function to determine whether data is a numeric function, oracle Value

1 create or replace function isnumeric (str IN VARCHAR2) 2 return number 3 IS 4 v_str VARCHAR2 (1000); 5 BEGIN 6 IF str is null 7 THEN 8 RETURN 0; 9 ELSE10 v_str: = translate (str ,'. 0123456789 ','. '); 11 12 IF v_str = '. 'OR v_str =' +. 'OR v_str = '-. 'OR v_str IS NULL13 THEN14 RETURN str; 15 ELSE16 RETURN 0; 17 end if; 18 end if; 19 END isnumeric;

I. Syntax:
TRANSLATE (string, from_str, to_str)
Ii. Purpose
Replace each character in from_str with a string after the corresponding character in to_str. TRANSLATE Is a superset of the functions provided by REPLACE. If from_str is longer than to_str, extra characters in from_str instead of to_str will be deleted from the string because they do not have replacement characters. To_str cannot be blank. Oracle interprets the NULL String as NULL, and if any parameter in the TRANSLATE Is NULL, the result is also NULL.
Iii. Example
SQL code

1. select translate ('abcdefghj', 'abcdef', '123') FROM dual;
2. TRANSLATE (
3 .--------------
4. ghij 123456
5.
6. select translate ('abcdefghj', 'abcdefghj', '123') FROM dual;
7. TRANSL
8 .----------
9. 123456

Syntax: TRANSLATE (expr, from,)

Expr: represents a string of characters. from and to correspond one to one from left to right. If not, it is considered as a null value.

Example:

Select translate ('abcbbaadef ', 'ba',' # @ ') from dual (B will be replaced by #, and a will be replaced)

Select translate ('abcbbaadef ', 'bad',' # @ ') from dual (B will be replaced by #, a will be replaced by @, and d's value is null, will be removed)

Therefore, the results are as follows: @ # c ###@ def and @ # c ##@ ef.

 

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.