Skip to main content

Posts

Non-Equijoins and Self-Joins in Oracle SQL

Non-Equijoins and Self-Joins in Oracle SQL Non-Equijoins and Self-Joins in Oracle SQL: Complete Guide Most joins in SQL use the equality operator. However, many real-world business requirements demand joining tables using conditions other than equality. This comprehensive guide covers two advanced and powerful join techniques: Non-Equijoins and Self-Joins . Learning Objectives By the end of this guide you will be able to write Non-Equijoins using range operators, perform Self-Joins for hierarchical data, understand performance implications, avoid common mistakes, and apply best practices in real Oracle environments. 1. Understanding Non-Equijoins A Non-Equijoin is a join that uses a comparison operator other than the equals sign. This includes > , < , >= , <= , BETWEEN , and <> . When Should You Use Non-Equijoins? Non-Equijoins are required when relationships between data are based on ranges rather than exact matches. Common business scenarios ...
Recent posts

Oracle SQL Implicit Conversion and ROWNUM Explained

Oracle SQL Implicit Conversion and ROWNUM Explained Oracle SQL: Implicit Conversion and ROWNUM Explained Oracle SQL is very flexible, but this flexibility can sometimes lead to unexpected results. Two areas where developers often face surprises are Implicit Conversion and ROWNUM . This guide explains both concepts clearly with practical examples. 1. Implicit Conversion in Oracle SQL Oracle automatically converts data types when it can. This is called implicit conversion . While convenient, it can cause performance problems and incorrect results if not understood properly. Common Implicit Conversion Scenarios Example 1: VARCHAR2 to NUMBER CREATE TABLE employees ( emp_id VARCHAR2(10), salary NUMBER ); -- This works because Oracle converts '101' to number SELECT * FROM employees WHERE emp_id = 101; Oracle converts the string '101' to number 101 to compare with the column. However, this can prevent index usage in some cases. Example ...

Oracle SQL Relational Database Concepts: Tables, Keys and Relationships

Oracle SQL: Relational Database Concepts Explained Oracle SQL: Relational Database Concepts Explained Relational databases are the foundation of modern data management systems. Oracle Database, being one of the most powerful and widely used relational database management systems in the world, is built entirely on relational database principles. If you want to truly master Oracle SQL, you must first develop a strong understanding of these fundamental concepts. In this detailed guide, we will explore every important concept step by step with clear explanations, realistic tables, practical Oracle SQL examples, diagrams, and best practices. By the end of this article, you will have a solid foundation to design efficient databases and write better SQL queries. 1. What is a Relational Database? A relational database is a type of database that stores and organizes data in the form of tables. These tables are connected to each other through well-defined relationships. The term...

Oracle SQL MERGE Statement and Advanced DML Patterns

Oracle SQL MERGE Statement and Advanced DML Patterns Oracle SQL MERGE Statement and Advanced DML Patterns MERGE solves the common "upsert" problem — when you have a source of data and need to update matching rows in a target table while inserting rows that do not yet exist, all in a single efficient operation. This guide covers the full MERGE syntax, the optional DELETE clause inside WHEN MATCHED, how to make WHEN clauses optional, proper use of DEFAULT values, the explicit DEFAULT keyword, and important rules around multi-row DML and constraint checking. In this post MERGE syntax and semantics • WHEN MATCHED with optional DELETE • Optional WHEN clauses • DEFAULT values and the DEFAULT keyword • Multi-row DML constraint behavior • Practice questions 1. MERGE — the combined INSERT/UPDATE statement MERGE solves the "upsert" problem — when you have new data in a staging table and want to update existing rows in the target while inserting new ones. ...

Oracle SQL Advanced Subqueries: Scalar, WITH Clause and DML Subqueries

Oracle SQL Advanced Subqueries: Scalar, WITH Clause and DML Subqueries Oracle SQL Advanced Subqueries: Scalar, WITH Clause and DML Subqueries — 1Z0-071 Exam Guide Advanced subqueries build on the basic subquery patterns from Chapter 8. Chapters 16 and 17 go deeper — scalar subqueries in unexpected places, the WITH clause for reusable query blocks, and subqueries used as the target of INSERT, UPDATE, and DELETE statements. These are not the most common exam questions, but they do appear — and candidates who haven't studied them lose marks that are relatively easy to pick up. In this post Scalar subqueries in SELECT and ORDER BY • Multiple-column subqueries • Pairwise vs non-pairwise comparisons • The WITH clause • Using subqueries as targets for UPDATE, INSERT, and DELETE • Practice questions 1. Scalar subqueries — one value in unexpected places A scalar subquery returns exactly one row and one column — a single value. What makes it useful is where it can be pla...

Oracle SQL SELECT Fundamentals: Columns, Aliases, DISTINCT and Expressions

Oracle SQL SELECT Statement Fundamentals: Complete Guide Oracle SQL SELECT Statement Fundamentals: Complete Guide The SELECT statement is the foundation of every SQL query in Oracle. Whether you are retrieving data, performing calculations, or transforming results, understanding SELECT mechanics is essential for writing clear, efficient, and maintainable queries. Learning Objectives By the end of this guide you will master SELECT syntax, understand column aliases, DISTINCT behavior, arithmetic expressions, string concatenation, operator precedence, and best practices that professionals use every day. 1. SELECT Statement Structure and Mandatory Clauses Only two clauses are mandatory. The remaining clauses are optional and must appear in a fixed order. Clause Required? Purpose SELECT Yes Columns or expressions to retrieve FROM Yes Table(s) to retrieve from WHERE No Filter rows before grouping GROUP BY No Collapse rows into groups HAVING No Filter groups after ...

Oracle SQL Data Dictionary Views: USER_, ALL_ and DBA_

Oracle SQL Data Dictionary Views: Complete Guide Oracle SQL Data Dictionary Views: Complete Guide The data dictionary is Oracle’s internal repository of metadata — information about every object in the database. It contains details about tables, columns, constraints, indexes, views, sequences, and much more. Querying the data dictionary is one of the most practical skills for any Oracle developer or DBA. Learning Objectives By the end of this guide you will understand the three main view families (USER_, ALL_, DBA_), know the most important dictionary views, master object naming rules, learn how to use the DUAL table, and explore dynamic performance views. 1. What the Data Dictionary Is The data dictionary consists of read-only tables and views maintained automatically by Oracle. It stores metadata about all database objects. You query it using regular SELECT statements, but you cannot modify it directly — Oracle updates it whenever you run DDL statements. -- Examp...