Cast PLSQL Function Output as View

How to Cast PLSQL Function Output as View

An Oracle view is typically like a window to the output of a SQL statement, but sometimes, a single SQL isn’t sufficient to get you the result you want. You may need to do some procedural data manipulation before you get the output you want. Does this mean, you cannot use an Oracle view if […]

Read the Full Article →
Overlapping Ranges in a Table

Stop Overlapping Ranges in a Table

Range-based definition of values is a common business scenario, as in the case of mortgage pre-payment penalty charges depending on "pre-payment amount" slabs, or incentives for a dealer depending on "business generated" slabs. A necessary validation is such cases is that the slabs should have no overlaps: each discrete value should match no more than […]

Read the Full Article →
PL/SQL Signature

What is the Signature of a PLSQL Program?

In interviews for PLSQL developers, I usually ask a question of the form: If you write a procedure to do <specific operation>, what will be the signature of such a procedure? In response, the developer often veers off into describing the logic/body of the procedure, which is not what was asked. If you’re among those […]

Read the Full Article →
LEAD LAG Analytic Functions

Using LEAD/LAG to Place a Value within Extents

Take a table with the structure {<Category>, <Extent>}– say, a GRADE_MASTER table with two columns: {GRADE_CODE, SCORE_UPTO}. For examination scores in the range 0-100, GRADE_MASTER specifies the extent of score up to which a certain grade applies. To find the grade for a given the examination score, the SQL needs to compare the EXTENT values […]

Read the Full Article →
Oracle schema record count

Find Number of Rows in Each Table in a Schema

How will you find out the number of rows in each table in a schema in Oracle? Here are two approaches with their pros and cons.

Read the Full Article →
ORA-55610: Invalid DDL statement on history-tracked table

ORA-55610: Invalid DDL statement on history-tracked table

If you have got Oracle Total Recall enabled on a table, and now want to truncate or drop the table, you are in for a problem. Clearly enough, Oracle does not allow you to do so because it has flashback archive enabled. How do you get around this problem?

Read the Full Article →
Oracle Total Recall

Oracle Total Recall for Tracking History

Oracle 11g Flashback Data Archive (Oracle Total Recall), essentially 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 […]

Read the Full Article →
MULTISET Operations on Nested Table of Objects

How to Perform MULTISET Operations on Nested Table of Objects

We’ve seen the easy working of MULTISET operations on nested tables of simple types (i.e. collections of text, numbers). And we’ve seen the problem with extending MULTISET operations to nested tables of complex types (i.e. those based on OBJECTs with multiple attributes). PL/SQL code when run with MULTISET operations on complex collections throws up the […]

Read the Full Article →
MULTISET Operations

MULTISET Operations: Combining Nested Tables Made Easy

Set operators (UNION, INTERSECT, MINUS) have long been available in basic SQL to process data in tables, but for data in PL/SQL nested tables, we’d earlier have to go through the ritual of traversing through the collections in a loop, doing a row-by-row comparison. Oracle 10G onwards, MULTISET features have made possible single-step set operations […]

Read the Full Article →
Delete Old Data from Database Schema

How to Delete Old Data from the Entire Schema

We may want to slim down a database schema, pruning old data from all tables, for a number of reasons. Let’s say to set up the test environment for a data migration project, a replica of the legacy database schema has been created. The legacy database schema has millions of records spanning multiple years, but […]

Read the Full Article →