<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ORATraining Blog &#187; Oracle SQL</title>
	<atom:link href="http://www.oratraining.com/blog/category/oracle/database/oracle-sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.oratraining.com/blog</link>
	<description>Not just another Oracle Blog</description>
	<lastBuildDate>Tue, 25 May 2010 12:22:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Oracle SQL Quick reference</title>
		<link>http://www.oratraining.com/blog/2009/06/sq-quick-referenence/</link>
		<comments>http://www.oratraining.com/blog/2009/06/sq-quick-referenence/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 05:44:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Oracle SQL]]></category>

		<guid isPermaLink="false">http://www.oratraining.com/blog/?p=182</guid>
		<description><![CDATA[Oracle SQL Quick Reference 
SELECT Query Statement
SELECT [DISTINCT] {*, column [alias],&#8230;}
FROM table
WHERE condition(s)]
ORDER BY {column, exp, alias} [ASC&#124;DESC]]
NOTE: 
Avoid using DISTINCT with large table as it first does sorting of all the rows and then eliminates duplicate rows, so need a full table scan and thus it&#8217;s very slow.
 
ORDER BY is the last clause [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Oracle SQL Quick Reference</strong><strong> </strong></p>
<p><strong>SELECT Query Statement</strong></p>
<p>SELECT [DISTINCT] {*, column [alias],&#8230;}</p>
<p>FROM table</p>
<p>WHERE condition(s)]</p>
<p>ORDER BY {column, exp, alias} [ASC|DESC]]</p>
<p><strong><em>NOTE:</em></strong><em> </em></p>
<p><em>Avoid using DISTINCT with large table as it first does sorting of all the rows and then eliminates duplicate rows, so need a full table scan and thus it&#8217;s very slow.</em></p>
<p><em> </em></p>
<p><em>ORDER BY is the last clause to get executed and thus could see all the column aliases; You can sort by a columns that is not in SELECT list; Default sorting order is Ascending (ASC)</em></p>
<p><span id="more-182"></span></p>
<p><strong>Joins</strong></p>
<p><strong>Oracle proprietary syntax for version 8i and earlier</strong></p>
<p><strong>Cartesian Product</strong></p>
<p>SELECT table1.*, table2.*,[...]</p>
<p>FROM table1,table2[,...]</p>
<p><strong> </strong></p>
<p><strong>Equijoin(Simple joins or inner join)</strong></p>
<p>SELECT table1.*,table2.*</p>
<p>FROM table1,table2</p>
<p>WHERE table1.column = table2.column</p>
<p><strong> </strong></p>
<p><strong>Non-Equijoin</strong></p>
<p>SELECT table1.*, table2.*</p>
<p>FROM table1, table2</p>
<p>WHERE table1.column</p>
<p>BETWEEN table2.column1 AND table2.column2</p>
<p><strong> </strong></p>
<p><strong>Outer join</strong></p>
<p>SELECT table1.*,table2.*</p>
<p>FROM table1,table2</p>
<p>WHERE table1.column(+) = table2.column</p>
<p>SELECT table1.*,table2.*</p>
<p>FROM table1,table2</p>
<p>WHERE table1.column = table2.column(+)</p>
<p><strong> </strong></p>
<p><strong>Self join</strong></p>
<p>SELECT alias1.*,alias2.*</p>
<p>FROM table1 alias1,table1 alias2</p>
<p>WHERE alias1.column = alias2.column</p>
<p><strong>SQL: 1999 compliant syntax for version 9i</strong></p>
<p>SELECT table1.column, table2.column</p>
<p>FROM table1</p>
<p>[<strong>CROSS JOIN</strong> table2] |</p>
<p>[<strong>NATURAL JOIN</strong> table2] |</p>
<p>[<strong>JOIN</strong> table2 <strong>USING</strong> (column_name)] |</p>
<p>[<strong>JOIN</strong> table2</p>
<p><strong>ON</strong> (table1.column_name=table2.column_name)] |</p>
<p>[<strong>LEFT</strong>|<strong>RIGHT</strong>|<strong>FULL</strong> <strong>OUTER</strong> <strong>JOIN</strong> table2</p>
<p><strong>ON</strong> (table1.column_name=table2.column_name)];</p>
<p><strong> </strong></p>
<p><strong>Aggregation Selecting</strong></p>
<p>SELECT [column,] group_function(column),&#8230;</p>
<p>FROM table</p>
<p>[WHERE condition]</p>
<p>[GROUP BY group_by_expression]</p>
<p>[HAVING group_condition]</p>
<p>[ORDER BY column];</p>
<p><strong> </strong></p>
<p><strong>Group function</strong></p>
<p>AVG([DISTINCT|ALL]n)</p>
<p>COUNT(*|[DISTINCT|ALL]expr)</p>
<p>MAX([DISTINCT|ALL]expr)</p>
<p>MIN([DISTINCT|ALL]expr)</p>
<p>STDDEV([DISTINCT|ALL]n)</p>
<p>SUM([DISTINCT|ALL]n)</p>
<p>VARIANCE([DISTINCT|ALL]n)</p>
<p><strong> </strong></p>
<p><strong>NOTE:</strong></p>
<p><em>All columns in the SELECT list that are not in group functions must be in the GROUP BY clause; but GROUP BY column does not have to be in the SELECT list.</em></p>
<p><em> </em></p>
<p><em>You can not use group functions in the WHERE clause;You use the HAVING clause to restrict groups.</em></p>
<p><em>All group functions except count(*) ignores null values. The NVL function forces group functions to include null values.</em></p>
<p><strong> </strong></p>
<p><strong>Subquery</strong></p>
<p>SELECT select_list</p>
<p>FROM table</p>
<p>WHERE expr operator(SELECT    select_list</p>
<p>FROM      table);</p>
<p><strong>NOTE:</strong></p>
<p><em>The subquery(inner query) executes once before the main query</em></p>
<p><em> </em></p>
<p><em>The result of the subquery is used by the main query(outer query)</em></p>
<p><em> </em></p>
<p><em>The ORDER BY clause in the subquery is not needed unless you are performing TOP-N analysis.</em></p>
<p><strong>single-row comparison operators: </strong>Return only one row</p>
<p>=        &gt;     &gt;=    &lt;     &lt;=    &lt;&gt;</p>
<p><strong>multiple-row comparison operators: </strong>Return more than one row</p>
<p>IN         ANY             ALL</p>
<p><strong> </strong></p>
<p><strong>Multiple-column Subqueries</strong></p>
<p>SELECT column, column, &#8230;</p>
<p>FROM table</p>
<p>WHERE (column, column, &#8230;) IN</p>
<p>(SELECT column, column, &#8230;</p>
<p>FROM table</p>
<p>WHERE condition);</p>
<p><strong>Data Manipulation Statements (DML)</strong></p>
<p><strong>INSERT Statement(one row)</strong></p>
<p>INSERT INTO table [ (column [,column...])]</p>
<p>VALUES (value [,value...]);</p>
<p><strong> </strong></p>
<p><strong>INSERT Statement with Subquery</strong></p>
<p>INSERT INTO table [ column(, column) ]</p>
<p>subquery;</p>
<p><strong> </strong></p>
<p><strong>UPDATE Statement</strong></p>
<p>UPDATE table</p>
<p>SET column = value [, column = value,...]</p>
<p>[WHERE condition];</p>
<p><strong> </strong></p>
<p><strong>Updating with Multiple-column Subquery</strong></p>
<p>UPDATE table</p>
<p>SET (column, column,&#8230;) =</p>
<p>(SELECT column, column,&#8230;</p>
<p>FROM table</p>
<p>WHERE condition)</p>
<p>WHERE condition;</p>
<p><strong> </strong></p>
<p><strong>Deleting Rows with DELETE Statement</strong></p>
<p>DELETE [FROM] table</p>
<p>[WHERE condition];</p>
<p><strong> </strong></p>
<p><strong>Deleting Rows Based on Another Table</strong></p>
<p>DELETE FROM table</p>
<p>WHERE column = (SELECT column</p>
<p>FROM table</p>
<p>WHERE condition);</p>
<p><strong>MERGE statement</strong></p>
<p>MERGE INTO table_name table_aliase</p>
<p>USING (table|view|sub_query) alias</p>
<p>ON (join condition)</p>
<p>WHEN MATCHED THEN</p>
<p>UPDATE SET</p>
<p>col1 = col1_val,</p>
<p>col2 = col2_val</p>
<p>WHEN NOT MATCHED THEN</p>
<p>INSERT (column_list)</p>
<p>VALUES (column_values);</p>
<p><strong>NOTE:</strong></p>
<p>MERGE provides ability to conditionally update or insert data into a database table. It is useful in data warehousing applications. It avoids separate updates; increase performance and ease of use</p>
<p><strong> </strong></p>
<p><strong>Transaction Control Statements (TCL)</strong></p>
<p>COMMIT;</p>
<p>SAVEPOINT name;</p>
<p>ROLLBACK [TO SAVEPOINT name];</p>
<p><strong> </strong></p>
<p><strong>Displaying table structure</strong></p>
<p>DESC[RIBE] tablename</p>
<p><strong>Data Definition Statemetns (DDL)</strong></p>
<p><strong>CREATE TABLE Statement</strong></p>
<p>CREATE TABLE [schema.]table</p>
<p>(column datatype [DEFAULT expr] [,...]);</p>
<p><strong> </strong></p>
<p><strong>CREATE TABLE Statement with Subquery</strong></p>
<p>CREATE TABLE [schema.]table</p>
<p>[(column, column...)]</p>
<p>AS subquery;</p>
<p><strong>NOTE: </strong></p>
<p><em>When a table is created using existing table except &#8220;NOT NULL&#8221; constraint, no other constraints are copied. If condition satisfied even rows are copied.</em></p>
<p><em> </em></p>
<p><strong> </strong></p>
<p><strong>Datatype</strong></p>
<p>VARCHAR2(size)    CHAR(size)        NUMBER(p,s)       DATE</p>
<p>LONG              CLOB              RAW               LONG RAW</p>
<p>BLOB              BFILE             ROWID</p>
<p><strong> </strong></p>
<p><strong>ALTER TABLE Statement </strong></p>
<p><strong>Adding columns</strong></p>
<p>ALTER TABLE table_name</p>
<p>ADD (column datatype [DEFAULT expr]</p>
<p>[, column datatype]&#8230;);</p>
<p><strong> </strong></p>
<p><strong>Changing a column&#8217;s type, size and default value of a Table</strong></p>
<p>ALTER TABLE table_name</p>
<p>MODIFY (column datatype [DEFAULT expr]</p>
<p>[, column datatype]&#8230;);</p>
<p><strong>RENAMING table column: </strong>Supported by 9.2 and higher version only<strong> </strong></p>
<p>ALTER TABLE table_name</p>
<p>RENAME column_name to new_column_name;</p>
<p><strong> </strong></p>
<p><strong>Dropping a column</strong></p>
<p>ALTER TABLE table_name</p>
<p>DROP (column);</p>
<p><strong> </strong></p>
<p><strong>Dropping a Table</strong></p>
<p>DROP TABLE table_name;</p>
<p><strong> </strong></p>
<p><strong>Changing the Name of an Object</strong></p>
<p>RENAME old_name TO new_name;</p>
<p><strong> </strong></p>
<p><strong>Trancating a Table</strong></p>
<p>TRUNCATE TABLE table_name;</p>
<p><strong> </strong></p>
<p><strong>Adding Comments to a Table</strong></p>
<p>COMMENT ON TABLE table_name | COLUMN table.column</p>
<p>IS &#8216;text&#8217;;</p>
<p><strong> </strong></p>
<p><strong>Dropping a comment from a table</strong></p>
<p>COMMENT ON TABLE table_name | COLUMN table.column IS &#8221; ;</p>
<p><strong> </strong></p>
<p><strong>Data Dictionary</strong></p>
<p>ALL_OBJECTS       USER_OBJECTS</p>
<p>ALL_TABLES        USER_TABLES</p>
<p>ALL_CATALOG       USER_CATALOG or CAT</p>
<p>ALL_COL_COMMENTS USER_COL_COMMENTS</p>
<p>ALL_TAB_COMMENTS USER_TAB_COMMENTS</p>
<p><strong> </strong></p>
<p><strong>Defining Constraints</strong></p>
<p>CREATE TABLE [schema.]table</p>
<p>column datatype [DEFAULT expr][NOT NULL]</p>
<p>[column_constraint],&#8230;</p>
<p>[table_constraint][,...]);</p>
<p><strong> </strong></p>
<p><strong>Column constraint level</strong></p>
<p>column [CONSTRAINT constraint_name] constraint_type,</p>
<p><strong> </strong></p>
<p><strong>Constraint_type</strong></p>
<p>PRIMARY KEY REFERENCES table(column) UNIQUE</p>
<p>CHECK (condition)</p>
<p><strong> </strong></p>
<p><strong>Table constraint level</strong>(except NOT NULL)</p>
<p>column,&#8230;,[CONSTRAINT constraint_name]</p>
<p>constraint_type (column,&#8230;),</p>
<p><strong> </strong></p>
<p><strong>NOT NULL Constraint (Only Column Level)</strong></p>
<p>CONSTRAINT table[_column...]_nn NOT NULL &#8230;</p>
<p><strong> </strong></p>
<p><strong>UNIQUE Key Constraint</strong></p>
<p>CONSTRAINT table[_column..]_uk UNIQUE (column[,...])</p>
<p><strong> </strong></p>
<p><strong>PRIMARY Key Constraint</strong></p>
<p>CONSTRAINT table[_column..]_pk PRIMARY (column[,...])</p>
<p><strong> </strong></p>
<p><strong>NOTE: </strong></p>
<p><em>PRIMARY Key defined on more than column called &#8216;Composite Primary Key&#8217; and to define composite primary key you need table level constraint as two columns are involved.</em></p>
<p><strong> </strong></p>
<p><strong>FOREIGN Key Constraint</strong></p>
<p>CONSTRAINT table[_column..]_fk</p>
<p>FOREIGN KEY (column[,...])</p>
<p>REFERENCES table (column[,...])[ON DELETE CASCADE]</p>
<p>[ON DELETE SET NULL];</p>
<p><strong> </strong></p>
<p><strong>CHECK constraint</strong></p>
<p>CONSTRAINT table[_column..]_ck CHECK (condition)</p>
<p><strong> </strong></p>
<p><strong>Adding a Constraint</strong>(except NOT NULL)</p>
<p>ALTER TABLE table_name</p>
<p>ADD [CONSTRAINT constraint_name ] type (column);</p>
<p><strong> </strong></p>
<p><strong>Adding a NOT NULL constraint</strong></p>
<p>ALTER TABLE table_name</p>
<p>MODIFY (column datatype [DEFAULT expr]</p>
<p>[CONSTRAINT constraint_name_nn] NOT NULL);</p>
<p><strong> </strong></p>
<p><strong>Dropping a Constraint</strong></p>
<p>ALTER TABLE table_name</p>
<p>DROP CONSTRAINT constraint_name;</p>
<p>ALTER TABLE table_name</p>
<p>DROP PRIMARY KEY | UNIQUE (column) |</p>
<p>CONSTRAINT constraint_name [CASCADE];</p>
<p><strong> </strong></p>
<p><strong>Disabling Constraints</strong></p>
<p>ALTER TABLE table_name</p>
<p>DISABLE CONSTRAINT constraint_name [CASCADE];</p>
<p><strong> </strong></p>
<p><strong>Enabling Constraints</strong></p>
<p>ALTER TABLE table_name</p>
<p>ENABLE CONSTRAINT constraint_name;</p>
<p><strong>NOTE:</strong></p>
<p><em>A UNIQUE or PRIMARY KEY index is automatically created if you enable a UNIQUE key or PRIMARY KEY constraint.</em></p>
<p><strong> </strong></p>
<p><strong>Data Dictionary</strong></p>
<p>ALL_CONSTRAINTS        USER_CONSTRAINTS</p>
<p>ALL_CONS_COLUMNS        USER_CONS_COLUMNS</p>
<p><strong> </strong></p>
<p><strong>View</strong></p>
<p><strong>Creating or Modifying a View</strong></p>
<p>CREATE [OR REPLACE] [FORCE|NOFORCE] VIEW view</p>
<p>[(alias[, alias]&#8230;)]</p>
<p>AS subquery</p>
<p>[WITH CHECK OPTION [CONSTRAINT constraint_name]]</p>
<p>[WITH READ ONLY [CONSTRAINT constraint_name]];</p>
<p><strong>Top-N Analysis</strong></p>
<p>SELECT [column_list], ROWNUM</p>
<p>FROM  (SELECT [column_list]</p>
<p>FROM table_name</p>
<p>ORDER BY Top-N_column)</p>
<p>WHERE ROWNUM &lt;= N;</p>
<p><em> </em></p>
<p><strong>Removing a View</strong></p>
<p>DROP VIEW view;</p>
<p><strong>SEQUENCE</strong></p>
<p><strong>CREATE SEQUENCE Statement</strong></p>
<p>CREATE SEQUENCE sequence</p>
<p>[INCREMENT BY n]</p>
<p>[START WITH n]</p>
<p>[{MAXVALUE n| NOMAXVALUE}]</p>
<p>[{MINVALUE n| NOMINVALUE}]</p>
<p>[{CYCLE | NOCYCLE}]</p>
<p>[{CACHE [n|20]| NOCACHE}];</p>
<p><strong> </strong></p>
<p><strong>Pseudocolumns</strong></p>
<p>sequence.NEXTVAL        sequence.CURRVAL</p>
<p><strong> </strong></p>
<p><strong>Modifying a Sequence (No START WITH option)</strong></p>
<p>ALTER SEQUENCE sequence</p>
<p>[INCREMENT BY n]</p>
<p>[{MAXVALUE n| NOMAXVALUE}]</p>
<p>[{MINVALUE n| NOMINVALUE}]</p>
<p>[{CYCLE | NOCYCLE}]</p>
<p>[{CACHE [n|20]| NOCACHE}];</p>
<p><strong> </strong></p>
<p><strong>Removing a Sequence</strong></p>
<p>DROP SEQUENCE sequence;</p>
<p><strong> </strong></p>
<p><strong>Index</strong></p>
<p><strong>Creating an Index</strong></p>
<p>CREATE INDEX index</p>
<p>ON TABLE (column[,column]&#8230;);</p>
<p><strong> </strong></p>
<p><strong>Removing an Index</strong></p>
<p>DROP INDEX index;</p>
<p><strong> </strong></p>
<p><strong>Synoym</strong></p>
<p>CREATE [PUBLIC] SYNONYM synonym</p>
<p>FOR object;</p>
<p><strong>Removing Synonyms</strong></p>
<p>DROP SYNONYM synonym;</p>
<p><strong> </strong></p>
<p><strong>Data Dictionary</strong></p>
<p>ALL_VIEWS                     USER_VIEWS</p>
<p>ALL_SEQUENCES                 USER_SEQUENCES</p>
<p>ALL_INDEXES                   USER_INDEXES</p>
<p>ALL_IND_COLUMNS               USER_IND_COLUMNS</p>
<p><strong> </strong></p>
<p><strong>System Privileges (DBA)       User System Privileges</strong></p>
<p>CREATE USER                   CREATE SESION</p>
<p>DROP USER                     CREATE TABLE</p>
<p>DROP ANY TABLE                CREATE SEQUENCE</p>
<p>BACKUP ANY TABLE              CREATE VIEW</p>
<p>CREATE PROCEDURE</p>
<p><strong>Creating Users</strong></p>
<p>CREATE USER user</p>
<p>IDENTIFIED BY password;</p>
<p><strong> </strong></p>
<p><strong>Creating Roles</strong></p>
<p>CREATE ROLE role;</p>
<p><strong>Granting System Privileges</strong></p>
<p>GRANT privelges[,...] TO user[,...];</p>
<p>GRANT privelges TO role;</p>
<p>GRANT role TO user[,...];</p>
<p><strong> </strong></p>
<p><strong>Changing Password</strong></p>
<p>ALTER USER user IDENTIFIED BY new_password;</p>
<p><strong> </strong></p>
<p><strong>Dropping Users</strong></p>
<p>DROP USER user [CASCADE];</p>
<p><strong> </strong></p>
<p><strong>Dropping Roles</strong></p>
<p>DROP ROLE role;</p>
<p><strong> </strong></p>
<p><strong>Object Privileges</strong></p>
<p>Object      Table       View        Sequence          Procedure</p>
<p>ALTER         X                        X</p>
<p>DELETE        X          X</p>
<p>EXECUTE                                                  X</p>
<p>INDEX         X</p>
<p>INSERT        X          X</p>
<p>REFERENCES   X</p>
<p>SELECT        X          X             X</p>
<p>UPDATE        X          X</p>
<p><strong> </strong></p>
<p><strong>Object Privileges</strong></p>
<p>GRAND object_priv [(column)]</p>
<p>ON object</p>
<p>TO {user|role|PUBLIC}</p>
<p>[WITH GRANT OPTION];</p>
<p><strong> </strong></p>
<p><strong>Revoking Object Privileges</strong></p>
<p>REVOKE {privilege [,privilege...] | ALL}</p>
<p>ON object</p>
<p>FROM {user[,user...]|role|PUBLIC}</p>
<p>[CASCADE CONSTRAINTS];</p>
<p><strong> </strong></p>
<p><strong>Data Dictionary</strong></p>
<p>ROLE_SYS_PRIVS</p>
<p>ROLE_TAB_PRIVS                USER_ROLE_PRIVS</p>
<p>USER_TAB_PRIVS_MADE           USER_TAB_PRIVS_RECD</p>
<p>USER_COL_PRIVS_MADE           USER_COL_PRIVS_RECD</p>
<p><strong> </strong></p>
<p><strong>Database Links</strong></p>
<p>CREATE [PUBLIC] DATABASE LINK link_name</p>
<p>[CONNECT TO user_name IDENTIFIED BY password]</p>
<p>USING connection_string;</p>
<p><strong> </strong></p>
<p><strong>Single-Row Functions</strong></p>
<p><strong>Character Functions</strong></p>
<p>LOWER(column|expression)</p>
<p>UPPER(column|expression)</p>
<p>INITCAP(column|expression)</p>
<p>INSTR(column|expression,m)</p>
<p>CONCAT(column1|expression1,column2|expression2}</p>
<p>SUBSTR(column|expression,m,[n])</p>
<p>LENGTH(column|expression)</p>
<p>LPAD(column|expression,n,&#8217;string&#8217;)</p>
<p>RPAD(column|expression,n,&#8217;string&#8217;)</p>
<p>TRIM(&#8216;character&#8217; FROM column|expression)</p>
<p>REPLACE(&#8217;string1&#8242;, &#8217;string_to_replace&#8217;,[replacement_string])</p>
<p><strong> </strong></p>
<p><strong>Number Functions</strong></p>
<p>MOD(m,n)</p>
<p>ROUND(column|expression,n)</p>
<p>TRUNC(column|expression,n)</p>
<p><strong> </strong></p>
<p><strong>Date Functions</strong></p>
<p>MONTHS_BETWEEN(date1,date2)</p>
<p>ADD_MONTHS(date,n)</p>
<p>NEXT_DAY(date,&#8217;char&#8217;)</p>
<p>LAST_DAY(date)</p>
<p>ROUND(date[,'fmt'])</p>
<p>TRUNC(date[,'fmt'])</p>
<p><em>Arithmetic with Dates</em></p>
<ul type="disc">
<li>Add or subtract a number to or from a date for a resultant date value</li>
<li>Subtract two dates to find the number of days between those dates</li>
<li>Add hours to a date by dividing the number of hours by 24</li>
</ul>
<p><strong> </strong></p>
<p><strong>Conversion Functions</strong></p>
<p>TO_CHAR(number|date[,'fmt'])</p>
<p>TO_NUMBER(char[,'fmt'])</p>
<p>TO_DATE(char[,'fmt'])</p>
<p>NVL(expr1,expr2)</p>
<p>NVL2(expr1,expr2,expr3)</p>
<p>NULLIF(expr1,expr2)</p>
<p>COALESCE(expr1,expr2,&#8230;,exprn)</p>
<p><strong>Conditional Expressions: </strong>Provide the use of IF-THEN-ELSE logic within a SQL statement.</p>
<p>DECODE(col|expr,search1,result1</p>
<p>[,search2,result2,...,]</p>
<p>[,default])</p>
<p>CASE expr WHEN comparision_expr1 THEN return_expr1</p>
<p>[WHEN comparision_expr2 THEN return_expr2</p>
<p>WHEN comparision_exprn THEN return_exprn</p>
<p>ELSE else_expr]</p>
<p>END</p>
<p><em>Nesting Functions</em></p>
<ul>
<li>Single-row functions can be nested to any level</li>
<li>Nested functions are evaluated from deepest level to the least deep level</li>
<li>In below example, functions F1, F2 and then F3 gets executed</li>
</ul>
<p>F3(F2(F1(col,arg1),arg2),arg3)</p>
<p><strong>Operators</strong></p>
<p>Arithmetic        *     /     +     -</p>
<p>Comparison        =     &gt;     &gt;=    &lt;     &lt;=    &lt;&gt; or ^= or ~= or !=</p>
<p>BETWEEN&#8230;AND&#8230;, IN(set), LIKE, IS NULL</p>
<p>Concatenation     ||</p>
<p>Logical           AND   OR    NOT</p>
<p><strong>Rules of Precedence</strong></p>
<p>Order Evaluated         Operator</p>
<ul>
<li>1 Arithmetic operators &#8211; multiplication and division(* /)</li>
<li>2 Arithmetic operators &#8211; Addition, subtraction and Concatenation operator ( + &#8211; || )</li>
<li>3 Comparison conditions</li>
<li>4 IS [NOT] NULL, LIKE, [NOT] IN</li>
<li>5 [NOT] BETWEEN</li>
<li>6 NOT logical condition; ** Exponentiation</li>
<li>7 AND logical condition</li>
<li>8 OR logical condition</li>
</ul>
<p><strong>Notes</strong></p>
<ul>
<li>1) Use <strong>ESCAPE</strong> identifier to search for the actual % and _ symbols (Here, % denotes zero or many characters and _ denotes one character in search condition )</li>
</ul>
<p>Example: Get employee list having underscore (_) in last_name string</p>
<p>SELECT last_name</p>
<p>FROM EMPLOYEE</p>
<p>WHERE last_name LIKE &#8216;%\_%&#8217; ESCAPE &#8216;\&#8217;;</p>
<ul>
<li>2) <strong>DUAL</strong> is a dummy table you can use to view results from functions and calculations</li>
<li>3) <strong>SYSDATE</strong> is a function that returns: Date and Time</li>
<li>4) Inline view is a subquery with an alias that you can use within a SQL statement. A named subquery in the FROM clause of the main query is an example of an inline view. It is not a schema object.</li>
</ul>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.oratraining.com%2Fblog%2F2009%2F06%2Fsq-quick-referenence%2F&amp;linkname=Oracle%20SQL%20Quick%20reference"><img src="http://www.oratraining.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.oratraining.com/blog/2009/06/sq-quick-referenence/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
