DBMS_REDEFINITION: Convert Non-Partitioned Table to Partitioned [pre 12.2]

DBMS_REDEFINITION to partition a table

DBMS_REDEFINITION

Oracle 12.2 has introduced a number of new features that ease partitioning, the most-awaited perhaps is the ALTER TABLE MODIFY syntax to convert a non-partitioned table to partitioned.

What do you do if your database version is pre-12.2? Partitioning a non-partitioned table in pre-12.2 databases is trickier, not impossible. Try DBMS_REDEFINITION: here’s how.

Read more

In Which Package Is This Procedure Placed?

Stored Procedures in Packages

“In which package is this procedure placed?”

Typical scenario: in a project’s design phase, procedureA is meant to be placed in packageX. During implementation, packages are refactored:  packageX gets split into packageY and packageZ. All goes well — the application gets deployed and is running merrily – till a change request comes in.

A new developer refers to the design documentation to understand the change request.

The design documentation should have been updated to reflect the new package structure — but it isn’t.

Read more

Storing XML Data in Oracle: Binary XML, Object-Relational, CLOB

Storing XML Data in Oracle

Oracle provides an abstract SQL data type called XMLType for storing XML data in the database. You can create an XMLType table,  or an XMLType column in a relational table, to persist XML data.

Different storage models are available in Oracle to best fit the nature of the XML data and its expected use. These are:

  • Binary XML storage
  • Structured storage (object-relational)
  • Unstructured XML storage (CLOB)

Here’s an overview of each of these XML storage models with the use cases the model is appropriate for.

Read more

DATE Format SQL for Dates Stored as Strings

Convert-VARCHAR2-to-DATE.jpg

It is well-acknowledged that attributes in the database should use the correct datatypes (numbers should go into NUMBER columns, dates into DATE columns, etc). Storing date values in VARCHAR2 columns is an open invitation for bugs and issues due to date format such as the one I’m about to describe. Besides, using string-type columns to represent dates rules out your ability to build upon features like range interval partitioning. Yes – ideally you should never have to convert VARCHAR2 to date.

It is equally well-acknowledged that we do not live in an ideal world. In some situations, we do not control the database design; we have to live with what exists and provide a solution to the problem.

This article addresses one such problem — how to compare two dates when they are stored as strings with different DATE formats.

Read more

Oracle Total Recall for Tracking History

Oracle Total Recall

Oracle 11g Flashback Data Archive (Oracle Total Recall), meant as a DBA tool to recover from logical corruptions and human errors, can be put to good use for another standard requirement in applications. Most applications need an audit trail or history of changes for important entities — say, the trail of changes to customer’s data needs to be tracked. Such requirements becomes trivial with Total Recall, eliminating a huge chunk of coding and testing effort.

Read more