TABLE OF CONTENTS
Overview Structured Query Language (SQL) is an implementation of a "data sublanguage" used in almost all relational database systems. SQL was developed by IBM in the early 1970s for use in System R, and is "de facto" standard, as well as an ISO and ANSI standard. In common usage, SQL supports four types of SQL statements: Queries: This type of SQL statement implements the standard relational operations such as SELECTION, PROJECTION and JOIN. The SELECT statement forms the basis for many other SQL operations. You can use SELECT statements to query tables, cre
'); // -->
ate views, in subqueries, or when creating a table defined as the result set of query. Data Manipulation Language (DML): DML statements are used to allow data in the database to be added, amended or deleted. DML functionality is provided by the use of INSERT, UPDATE and DELETE statements. Data Definition Language (DDL): This is the language that allows for objects to be created or altered. Provided below are a few example Oracle DDL statements: Data Control Language (DCL): This is the language that allows for transaction control. Provided below are a few example Oracle DCL statements: The development of SQL is governed by standards. A major revision of the SQL standard was completed in 1992, called SQL2. SQL3 is a newer revision that supports object extensions and will be partially implemented starting with Oracle8.
How can I transform a subquery involving the IN clause to a Join? Original statement: New statement: SELECT e.empno, e.ename FROM emp e, dept d WHERE d.loc = 'CHICAGO' AND d.deptno = e.deptno;
How can I transform a statement involving an OR condition to a UNION ALL? Original statement: New Statement:
How do I eliminate duplicate values in a table? Provided below are four methods for identifying or removing duplicate rows from a table: Method 1: Method 2: Method 3: Method 4: NOTE: If you where to create an index on the joined fields in the inner loop, it may be possible to eliminate N^2 operations as there would be no need to loop through the entire table on each pass be a record.
How can I get a count of the different data values in a column?
How can I get count/sum RANGES of data values in a column? A value "x" will be between values "y" and "z" if: GREATEST(x,y)=LEAST(x,z).
How can I get the time difference between two date columns? Method 1: (Very long-winded. A more efficient version is indicated in Method 2.) Method 2: (Thanks to Chris Hunt, http://www.extracon.com/, for providing me with this much easier and efficient SQL query to produce the same results!)
Can I retrieve only the Nth row from a table? Method 1: Method 2: NOTE: Always remember that there is no explicit order in a relational database.
Can I retrieve only rows X to Y from a table?
Can I retrieve EVERY Nth row from a table? Method 1: Method 2: Using Dynamic Views: (available in Oracle7.2 and higher)
Retrieve the TOP N Rows from a table? Method 1: Starting with Oracle8i, you can have an inner-query with an ORDER BY clause Method 2: The following workaround will work with prior releases.
Is it possible to dump/examine the exact content of a database column? [TABLE]
Can I code a MATRIX Report using SQL?
Tree-structured (hierarchical) queries NOTE: Using the "EMP" table from the SCOTT/TIGER schema makes a great test table since it has a "self-referencing" relation. (The MGR column contains the employee number of the "current" employee's boss. The LEVEL pseudo-column is an indication of hwo deep in the tree you are. Oracle can handle queries with a depth up to 255 levels. The "START WITH" clause is used to specify the start of the tree. More than one record can match the starting condition. One disadvantage of having a "CONNECT BY PRIOR" clause is that you cannot perform a JOIN to other tables.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Oracle Development Solutions - SQL, J2EE, XML, SOA |
| About Us | Contact Us | For Advertisers | For Business Partners | Site Index | RSS |
|
|
|
|||||||