DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Data Governance Essentials: Glossaries, Catalogs, and Lineage (Part 5)
  • How to Simplify Complex Conditions With Python's Match Statement
  • Modify JSON Data in Postgres and Hibernate 6
  • Practical Generators in Go 1.23 for Database Pagination

Trending

  • Caching 101: Theory, Algorithms, Tools, and Best Practices
  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 2: Understanding Neo4j
  • Prioritizing Cloud Security Risks: A Developer's Guide to Tackling Security Debt
  • Introduction to Retrieval Augmented Generation (RAG)
  1. DZone
  2. Data Engineering
  3. Data
  4. The Oracle Validate_Conversion Function

The Oracle Validate_Conversion Function

This feature reduces the complexity of the code that we write for data validation in SQL and PL/SQL code blocks and improves application performance.

By 
Emrah Mete user avatar
Emrah Mete
·
May. 16, 17 · Tutorial
Likes (7)
Comment
Save
Tweet
Share
10.2K Views

Join the DZone community and get the full member experience.

Join For Free

In this article, I will talk about Oracle 12c Release 2 with a new feature on the SQL side. 

Let's start with describing the validate_conversion function. We often encounter data type conversion problems in SQL and PL/SQL code that we write. When we encounter such situations, we often crash and end up in an uncontrolled situation. The validate_conversion function is running at the point where we have problems with data type conversions. The logic of the function is actually quite simple. We send two parameters to the function. The first one is the data to be converted, and the other is the type of data to be converted. The function returns 1 or 0 as a result of the given parameters. If there is no discrepancy between the data and the data type, 1 is returned. 0 is returned if there is an inconsistency between the data and the data type.

We can use the validate_conversion function to test the following data type conversions:

  • Number.

  • Date.

  • Timestamp.

  • Timestamp with time zone.

  • Binary_float.

  • Binary_double.

  • Interval day to second.

  • Interval year to month.

Now let's see some examples of how it is used.

select validate_conversion('test123' as number)                 test1 from dual;--0 
select validate_conversion(300 as number)                       test2 from dual;--1
select validate_conversion('01012017' as date,'mmddyyyy')       test3 from dual;--1
select validate_conversion('31012017' as date,'mmddyyyy')       test4 from dual;--0
select validate_conversion('31-jan-2017' as date,'dd-mon-yyyy') test5 from dual;--1

validate_conversion

Now, let's look at different forms of use.

SELECT *
FROM hr.employees emp
WHERE VALIDATE_CONVERSION(emp.employee_id AS NUMBER) = 1;

SELECT VALIDATE_CONVERSION(emp.employee_id AS NUMBER) emp_id_test,
employee_id
FROM hr.employees emp;

SELECT DECODE(VALIDATE_CONVERSION(emp.employee_id AS NUMBER),0,
'NOT NUMBER',1,'NUMBER','N/A') emp_id_test,employee_id
FROM hr.employees emp;

SELECT case when VALIDATE_CONVERSION(emp.employee_id AS NUMBER) = 1 
then 
emp.employee_id else -1 end emp_id_test,
employee_id
FROM hr.employees emp;

This feature, which comes with Oracle 12c R2, will reduce the complexity of the code we write for data validation in SQL and PL/SQL code blocks and improve our application performance. Native code support for data conversion is a significant development in this context.

Data (computing) Data Types

Opinions expressed by DZone contributors are their own.

Related

  • Data Governance Essentials: Glossaries, Catalogs, and Lineage (Part 5)
  • How to Simplify Complex Conditions With Python's Match Statement
  • Modify JSON Data in Postgres and Hibernate 6
  • Practical Generators in Go 1.23 for Database Pagination

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!