Q
Problem solve Get help with specific problems with your technologies, process and projects.

# Numbers in a VARCHAR2 column

How do I query an Oracle table to find which rows contain numeric data in a column of type VARCHAR2?
See the earlier question on finding what rows contain valid dates for an explanation of the "run it up the flagpole and see who salutes" approach used in the function below.

```CREATE OR REPLACE FUNCTION  to_num
(
in_num_text  IN  VARCHAR2,
in_fmt_text  IN  VARCHAR2
DEFAULT NULL
)
RETURN  NUMBER

--  *******************
--  **  t o _ n u m  **
--  *******************

--  to_num returns the value of in_num_text if it is a number in
--    the format specified by in_fmt_text, NULL if it is not.
--  If in_fmt_text is omitted, to_num will return a number if
--    in_num_text is a number in ANY usual format, e.g. '5', '+5',
--    '5.00', '.5e1' all return 5.

IS
BEGIN
IF  in_fmt_text  IS NULL
THEN
RETURN  TO_NUMBER ( in_num_text );
ELSE
RETURN  TO_NUMBER ( in_num_text
, in_fmt_text
);
END IF;
EXCEPTION
WHEN OTHERS
THEN
RETURN  NULL;
END   to_num;
/

SELECT      '=>'          -- to make leading spaces clear
||  text
||  '<='
, to_num (text)
, to_num (text, '999.999')
FROM    number_test
ORDER BY
text;

'=>'||TEXT||'<='         TO_NUM(TEXT) TO_NUM(TEXT,'999.999')
------------------------ ------------ ----------------------
=> 1 <=                             1
=>\$10<=
=>+56<=                            56
=>2.3<=                           2.3                    2.3
=>4,000<=
=>5+6<=
=>7.888888<=                 7.888888
=>9.1e2<=                         910
=>MMIII<=
=><=
```

One important difference between TO_NUMBER and TO_DATE is that TO_DATE is always working with a particular format in mind. If you don't pass a format model to TO_DATE, it will use the system default. In other words, "SELECT TO_DATE (col_a) FROM table_x" will always result in an error if one row has '22-Dec-2003' and another has '2003-12-22' in col_a. TO_NUMBER, as shown above, is happy with such dissimilar formats as ' 1 ' and '9.1e2'.

#### Have a question for an expert?

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

#### Start the conversation

Send me notifications when other members comment.

## SearchDataManagement

• ### Swim DataFabric platform helps to understand edge streaming data

Swim released its new Swim DataFabric, which integrates with Microsoft Azure to help users organize and gain insights from ...

• ### Dremio Data Lake Engine 4.0 accelerates query performance

Dremio issues a new platform update, defining itself as data lake engine technology that looks to help users connect and query ...

• ### Weighing the use of third-party database administration tools

Database expert Chris Foot details the key reasons why DBAs should consider using third-party database administration to fill ...

• ### Qlik exec discusses AI and its role in the future of BI

The next major trend in business intelligence will be the increasing impact of augmented intelligence and machine learning, ...

• ### SAP BI platform stays strong due to cloud-based architecture

A cloud-native BI platform along with domain-specific applications that can be embedded to serve the needs of various industries ...

• ### Tableau 2019.3 highlighted by enhanced AI, new data catalog

Tableau released its third-quarter update Wednesday, featuring Explain Data, an enhanced augmented intelligence tool, and Tableau...

## SearchSAP

• ### SAP HANA database pivotal to SAP's past -- and future

In the last 20 years, SAP has gone from an ERP software vendor to a modern-day technology powerhouse. Analysts point to SAP HANA ...

• ### Navy sails SAP ERP systems to AWS GovCloud

The Navy consolidated 26 various ERP systems onto SAP HANA on the AWS GovCloud, leading to data reduction, lower TCO, and setting...

• ### SAP HANA application collects concussion data for real-time analysis

Protecht, an SAP HANA based system, enables teams in contact sports to measure and analyze data about hits though an IoT sensor ...

## SearchSQLServer

• ### SQL Server database design best practices and tips for DBAs

Good database design is a must to meet processing needs in SQL Server systems. In a webinar, consultant Koen Verbeeck offered ...

• ### SQL Server in Azure database choices and what they offer users

SQL Server databases can be moved to the Azure cloud in several different ways. Here's what you'll get from each of the options ...

• ### Using a LEFT OUTER JOIN vs. RIGHT OUTER JOIN in SQL

In this book excerpt, you'll learn LEFT OUTER JOIN vs. RIGHT OUTER JOIN techniques and find various examples for creating SQL ...

## TheServerSide.com

• ### Microsoft vs. IBM: A major shift in Java support

Once an afterthought in the Java community, Microsoft has seemingly overtaken IBM as the preeminent advocate among developers at ...

• ### Guide to practicing cloud-native development

In this guide, learn about cloud-native development -- what it is, how vendors try to exploit it and how to bring it to life with...

• ### Eclipse launches Che 7 IDE for Kubernetes development

The Eclipse Foundation has introduced Eclipse Che 7, a new version of the Eclipse Che cloud-based integrated development ...

## SearchDataCenter

• ### New Dell EPYC servers embrace AMD Rome chips

Dell EMC goes from Naples to Rome with a new line of EPYC servers, including Ready Solutions for high-performance computing and ...

• ### Can next-gen SIEM help cybersecurity initiatives?

More organizations are using SIEM, AI and cloud technology to minimize security breaches. Though despite interest, this ...

• ### IBM z15 mainframe secures data across multi-cloud environments

IBM unveiled the latest in its line of mainframes capable of processing 1 trillion web transactions a day. The IBM z15 ...

## SearchContentManagement

• ### Icelandair turns to headless CMS to improve CX

The right CMS makes a big difference for CX, so Icelandair moved off its on-premises content server to a headless CMS – with one ...

• ### Microsoft 365 Business update targets nonprofits

Microsoft announced this month that it is releasing new updates and offerings for nonprofits, addressing concerns customers had ...

• ### Nintex launches no-code workflow automation tool

Nintex has launched a no-code workflow automation tool, Workflow Generator, in an effort to bridge the gap between IT departments...

## SearchHRSoftware

• ### 10 ingredients in a killer employee experience strategy

Improving the employee experience is a must for modern organizations and their HR teams, but where should you start? Here are 10 ...

• ### SuccessFactors customers to see big Qualtrics impact

SuccessFactors is rethinking its HCM suite as it works to integrate Qualtrics into its applications. But HR managers are ...

• ### HiQ Labs vs LinkedIn case OKs robot monitoring of employees

A U.S. Court of Appeals ruled on the LinkedIn vs HiQ lawsuit, which could help shape how services gather information on social ...

Close