Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DB2- How to check if varchar field value has integers

Tags:

sql

db2

Is there an inbuilt DB2 function or any query to check if the character i have is a number? (I cannot use user defined functions)

like image 645
Andy Avatar asked May 07 '12 21:05

Andy


People also ask

How do I check if a column is numeric in SQL?

The ISNUMERIC() function tests whether an expression is numeric. This function returns 1 if the expression is numeric, otherwise it returns 0.

Is Numeric in Db2?

Numeric in Db2 database are columns with the following data types: smallint, integer/int, bigint, decimal/numeric, real, double, decfloat.

What is the use of VARCHAR in Db2?

The VARCHAR function returns a varying-length character string representation of one of the following values: An integer number if the first argument is a SMALLINT, INTEGER, or BIGINT. A decimal number if the first argument is a decimal number.

How do you check if a string contains a substring in Db2?

The Db2 INSTR() function finds a substring in a string and returns the position of the nth occurrence of the substring.


1 Answers

Doc Link

CASE
  WHEN LENGTH(RTRIM(TRANSLATE(test_str, '*', ' 0123456789'))) = 0 
  THEN 'All digits'
  ELSE 'No'
END
like image 74
xQbert Avatar answered Sep 19 '22 17:09

xQbert