Oracle
  Home arrow Oracle arrow Stepping through Sub-Queries in Oracle
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ORACLE

Stepping through Sub-Queries in Oracle
By: Jagadish Chatarji
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 21
    2006-11-07


    Table of Contents:
  • Stepping through Sub-Queries in Oracle
  • The simplest sub-query in Oracle
  • A sub-query with aggregate functions (or group functions) in Oracle
  • Designing sub-queries to deal with more than one table (or different tables)
  • An example of a nested sub-query (or multi-level sub-query)

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Stepping through Sub-Queries in Oracle
    ( Page 1 of 5 )

    This is the first article in a series concentrating on working with sub-queries in Oracle. Sub-queries really have tremendous depth. In this series I will show you several scenarios where they can be efficiently used to retrieve information from Oracle databases.

    As this is the first in series, I will be concentrating on the following topics:

    • How to work with a “dual” table.
    • How to analyze and identify the steps needed to deal with a sub-query.
    • How to frame queries for each of the identified steps.
    • How to combine all the framed queries and design a single command to retrieve the final output.

    A primer on the “dual” table in Oracle

    This section mainly explains the “dual” table in Oracle.  I shall use this table in a creative manner wherever required in this article as well as upcoming articles.  If you are already familiar with the "dual” table, feel free to skip to the next section.

    What is a “dual” table?  It is a simple table which is created/installed automatically during the installation of the Oracle database.  To understand it, let us consider the following SELECT statement:

    SELECT 123 FROM dual;

    The above statement simply returns 123.  Let us work with another statement:

    SQL> SELECT 10,20,'Jagadish Chatarji',3400 FROM dual;

    10    20    'JAGADISHCHATARJI' 3400                   

    ----- ----- ------------------ ----------------------

    10    20    Jagadish Chatarji  3400                  

    1 rows selected

    This returns any constant values you provide as columns.  So “dual” is just a convenience table.  It is simply a one column and one row table that exists as part of SYS user.  You can use the DESC command to display the structure of a “dual” table as follows:

    DESC dual;

    The above statement returns the following output:

    Name

    Null

    Type

    ----------------------

    -------------------------

    ------------------------

    DUMMY

     

    VARCHAR2(1)

    You can observe that there exists only one column named “dummy” in the "dual" table.  Similarly, you can even display all the rows in the "dual" table as follows:

    SQL> SELECT * FROM dual;

    DUMMY

    -----

    X    

    1 rows selected

    From the above, you can observe that there exists only one row with a dummy value of "x." 

    You don't really need to use the “dual” table at all.  It is only used when you want to add/include any constant values in your queries.  You can even do calculations as follows:

    SQL> SELECT 12 * 13 + 14 FROM dual;

    12*13+14              

    ----------------------

    170                   

    1 rows selected



     
     
    >>> More Oracle Articles          >>> More By Jagadish Chatarji
     

       

    ORACLE ARTICLES

    - Oracle's Turn to Play in the Sun
    - Implementing and Using Oracle`s Restore Poin...
    - Tuning PL/SQL Code
    - Debugging PL/SQL Code
    - Testing PL/SQL Code
    - Working With PL/SQL Code
    - Conditional Compilation for Oracle Database ...
    - Compile-Time Warnings for Oracle DB 10g
    - Compiling PL/SQL Code for an Oracle Database
    - Troubleshooting PL/SQL Code
    - Managing PL/SQL Code
    - Data Manipulation and More for HTML DB Appli...
    - Oracle Database Fundamentals
    - Adding Processes to HTML DB Applications
    - Adding Computations, Processes, and Validati...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT