Oracle determines whether it is a numeric or numeric string (sqlserver isnumeric)

Source: Internet
Author: User

Requirements:

If the field value is not a numeric or numeric string, update the field value''

1. Function Method (batch release is not allowed ):

[SQL]
  1. CreateOrReplaceFunctionIsNumber (p_in varchar2)ReturnBooleanAs
  2. I number;
  3. Begin
  4. I: = to_number (p_in );
  5. ReturnTrue;
  6. Exception
  7. WhenOthersThen
  8. ReturnFalse;
  9. End;

However, it seems that this can only be judged one by one and cannot be performed in batches.

2.

[SQL]
  1. SQL>SelectNvl2 (translate ('123','\ 100','\'),'IsCharacters','IsNumber ')FromDual;
  2. NVL2 (TRANSLATE ('123', '\ 1234567
  3. ------------------------------
  4. IsNumber
  5. SQL>SelectNvl2 (translate (333,'\ 100','\'),'IsCharacters','IsNumber ')FromDual;
  6. NVL2 (TRANSLATE (333, '\ 123456789
  7. ------------------------------
  8. IsNumber
  9. SQL>SelectNvl2 (translate ('Aaaaa','\ 100','\'),'IsCharacters','IsNumber ')FromDual;
  10. NVL2 (TRANSLATE ('Aaaaa', '\ 12345
  11. ------------------------------
  12. IsCharacters
  13. SQL>

3. It is said that batch query is required. You can check it out first, but you have not tried it:

[SQL]
  1. SelectDecode (nvl2 (translate (Column,'\ 100','\'),'0','1'),'1', Column ,'')FromDual;

I wrote:

[SQL]
  1. UpdateT_87_MtbufSetSpCode ='' WhereNvl2 (translate (SpCode,'\ 100','\'),'IsCharacters','IsNumber') ='IsCharacters ';

Add:

To_number (...) can only accept numbers such as 122 or numeric string '123456'. If 'aaa' is accepted, an error "invalid character" is returned ".

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.