<?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>Oracle Tips and Techniques &#187; SQL Tutorial</title>
	<atom:link href="http://www.oraclecity.com/category/sql-tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.oraclecity.com</link>
	<description>Oracle 11g, Oracle 10g, PL/SQL, Oracle Enterprise Manager 11g Grid Control, Oracle Performance Tuning, Microsoft SQL Server and T-SQL</description>
	<lastBuildDate>Thu, 12 Jan 2012 11:36:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>SQL Tutorial</title>
		<link>http://www.oraclecity.com/sql-tutorial/sql-tutorial/</link>
		<comments>http://www.oraclecity.com/sql-tutorial/sql-tutorial/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 13:55:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL Tutorial]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sql cursor]]></category>

		<guid isPermaLink="false">http://www.oraclecity.com/?p=26</guid>
		<description><![CDATA[Learn Oracle SQL: A very useful Oracle SQL Tutorial. This tutorial will teach you Oracle SQL - step by step - with loads of example.]]></description>
			<content:encoded><![CDATA[<p align="left">
<h1><span style="font-size: x-large; font-family: Times New Roman;">SQL Tutorial</span><span style="font-size: medium; font-family: Times New Roman;"> </span></h1>
<p align="left">
<p align="left"><span style="font-size: large; font-family: Times New Roman;"><strong>SQL the Language</strong></span></p>
<hr />
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;">Today Structured Query Lannguage or simply SQL is the standard query language for all  relational<br />
databases such as Oracle, Microsoft SQL Server, DB2, Sybase, MySQL and Microsoft Access.  Any<br />
modern relational database that you may be using, it is bound to support SQL as it&#8217;s  standard<br />
data qyery and manupulating language. It may differ slightly depending on the kind of  Database<br />
it needs to access (i.e. Oracle and SQL Server release their own SQL) but they all follow  the<br />
industry accepted standards cimpiled by ANSI and ISO.</p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;">SQL is definitely the most commonly used language in any oracle installtion. Be it  through plain<br />
SQL statements or through Oracle&#8217;s PL/SQL (Programming Language extention of SQL) or  embedded<br />
in C, C++, Java. Whatever programming language you use, as soon as you need to manipulate<br />
or process relational data you will need some form of SQL to rectrive and manipulate the  data.</p>
<p></span></div>
<div>
<p><span style="font-size: medium; font-family: Times New Roman;"> </span></div>
<p><span style="font-size: medium; font-family: Times New Roman;">The aim of this tutorial is  to give a hands-on knowledge of this powerfull but still so simple<br />
language to the beginers as well as to the experienced programmers who likes to revise  their<br />
understanding periodically. The totorial includes lots of example which are used by  developers<br />
and managers alike for their day to day functions in developing and supporting commercial<br />
databases.</span></p>
<p><span style="font-size: large; font-family: Times New Roman;"><strong>A few words on Oracle</strong></span><span style="font-size: medium; font-family: Times New Roman;"><br />
</span></p>
<hr />
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;">Oracle is a relational database and factually speaking it is the most popular and most  widely<br />
installed for commercial purpose databases for medium to large businesses. I am not saying  that<br />
it can not be used for small business but I think there are much cheaper alternative in  the<br />
market for that purpose. But when it comes to scale and performance and ease of  maintenance<br />
as well as trained man-power I think Oracle is in the fore front among the league.</p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;">Oracle database server is nothing but a combination of different services which works  together<br />
as a single database management system. Oracle is a relational database management system<br />
(RDBMS) because it stores data in relational model which make it faster to query and  maniputale.</p>
<p></span></div>
<p><span style="font-size: medium; font-family: Times New Roman;">Oracle stores data in an  object called Table. There are different types of objects in oracle<br />
such as</span></p>
<p>Table<br />
Index<br />
Contraint<br />
Procedure<br />
Function<br />
Package<br />
Trigger<br />
Sequence</p>
<p>All these objects are logically stored in Oracle logical structures such as Tables,  Segments, Extents<br />
and Blobks.</p>
<p>Physically all these logical data are stored in o/s files called Oracle Data files.  These files are<br />
stored in o/s level in some directory which varies in different implementations.</p>
<p><span style="font-size: large; font-family: Times New Roman;"><strong>Basic Requirement</strong></span><span style="font-size: medium; font-family: Times New Roman;"><br />
</span></p>
<hr />
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;">To be able to run SQL you will need to be able login to some Oracle database located in  your local<br />
machine or in a remote machine where you are able to connect.</p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;">To be able to run the queries given in this tutorial you will need to create two tables  named<br />
Students and Majors. Then you will need to Insert data into these two tables using the  data files<br />
and SQL*Loader scripts.</span></div>
<div><span id="more-26"></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;"></p>
<p></span></div>
<p><span style="font-size: medium; font-family: Times New Roman;">Create sample Tables and Data  used in this guide using the link below:</span></p>
<p>&lt;&lt; Tutorial Sample table and data &gt;&gt;</p>
<p><strong><span style="font-size: large; font-family: Times New Roman;"><img title="More..." src="http://www.oraclecity.com/wp-includes/js/tinymce/plugins/wordpress/img/trans.gif" alt="" /></span></strong></p>
<p><strong><span style="font-size: large; font-family: Times New Roman;">Data Types<br />
</span></strong></p>
<hr />
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;">Any information stored in a computer is stored in some data type that the computer can  understand.<br />
A programming language which accesses these stored information need to understand thess  data types.</p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;">In SQL the most commonly used data types are:</p>
<p></span></div>
<p>CHAR &#8211; fixed length character data<br />
VARCHAR2 &#8211; variable length character data<br />
NUMBER (p,s) &#8211; Number with with precision p and scale s.<br />
DATE &#8211; a valid date<br />
TIMESTAMP &#8211; date and time inclusing hours, minutes, seconds and mil. seconds</p>
<p>There are other data types which are are widely used such as</p>
<p>TIMESTAMP WITH TIME ZONE<br />
TIMESTAMP WITH LOCAL TIME ZONE<br />
RAW<br />
LONG<br />
LONG RAW<br />
ROWID<br />
BLOB<br />
CBLOB<br />
BFILE<br />
and<br />
more&#8230;</p>
<p><span style="font-size: large; font-family: Times New Roman;"><strong>Relational Operators</strong></span></p>
<hr />
<table border="1" width="50%">
<tbody>
<tr>
<td width="30%" align="center"><span style="font-size: medium; font-family: Times New Roman;">=</span></td>
<td width="70%"><span style="font-size: medium; font-family: Times New Roman;">Equal Operator</span></td>
</tr>
<tr>
<td width="30%" align="center">&lt;</td>
<td width="70%"><span style="font-size: medium; font-family: Times New Roman;">Less Than Operator</span></td>
</tr>
<tr>
<td width="30%" align="center">&gt;</td>
<td width="70%"><span style="font-size: medium; font-family: Times New Roman;">Greater Than Operator</span></td>
</tr>
<tr>
<td width="30%" align="center">&lt;=</td>
<td width="70%"><span style="font-size: medium; font-family: Times New Roman;">Less Than or Equal Operator</span></td>
</tr>
<tr>
<td width="30%" align="center">&gt;=</td>
<td width="70%"><span style="font-size: medium; font-family: Times New Roman;">Greater Than or Equal      Operator</span></td>
</tr>
<tr>
<td width="30%" align="center">&lt;&gt;</td>
<td width="70%"><span style="font-size: medium; font-family: Times New Roman;">Not Equal Operator</span></td>
</tr>
<tr>
<td width="30%" align="center">!=</td>
<td width="70%"><span style="font-size: medium; font-family: Times New Roman;">Not Equal Operator</span></td>
</tr>
<tr>
<td width="30%" align="center"><span style="font-size: medium; font-family: Times New Roman;">BETWEEN</span></td>
<td width="70%">B<span style="font-size: medium; font-family: Times New Roman;">etween Operator</span></td>
</tr>
<tr>
<td width="30%" align="center">NOT <span style="font-size: medium; font-family: Times New Roman;">BETWEEN</span></td>
<td width="70%"><span style="font-size: medium; font-family: Times New Roman;">Not Equal Operator</span></td>
</tr>
<tr>
<td width="30%" align="center"><span style="font-size: medium; font-family: Times New Roman;">IN</span></td>
<td width="70%"><span style="font-size: medium; font-family: Times New Roman;">IN Operator</span></td>
</tr>
<tr>
<td width="30%" align="center"><strong>NOT </strong><span style="font-size: medium; font-family: Times New Roman;">IN</span></td>
<td width="70%"><span style="font-size: medium; font-family: Times New Roman;">Not In Operator</span></td>
</tr>
<tr>
<td width="30%" align="center"><span style="font-size: medium; font-family: Times New Roman;">EXISTS</span></td>
<td width="70%"><span style="font-size: medium; font-family: Times New Roman;">Exists Operator</span></td>
</tr>
<tr>
<td width="30%" align="center">NOT <span style="font-size: medium; font-family: Times New Roman;">EXISTS</span></td>
<td width="70%"><span style="font-size: medium; font-family: Times New Roman;">Not Exists Operator</span></td>
</tr>
<tr>
<td width="30%" align="center"><span style="font-size: medium; font-family: Times New Roman;">LIKE</span></td>
<td width="70%"><span style="font-size: medium; font-family: Times New Roman;">Like Operator</span></td>
</tr>
<tr>
<td width="30%" align="center">NOT <span style="font-size: medium; font-family: Times New Roman;">LIKE</span></td>
<td width="70%"><span style="font-size: medium; font-family: Times New Roman;">Not Like Operator</span></td>
</tr>
<tr>
<td width="30%" align="center">OR</td>
<td width="70%"><span style="font-size: medium; font-family: Times New Roman;">Or operator</span></td>
</tr>
</tbody>
</table>
<p align="left">
<p align="left"><strong><span style="font-size: large; font-family: Times New Roman;">SET Operators</span></strong></p>
<p align="left">
<p><strong><span style="font-size: large; font-family: Times New Roman;"> </span></strong></p>
<hr />
<p align="left">
<p><span style="font-size: medium; font-family: Times New Roman;">Oracle provides facilities  for mathmatical SET operators in it&#8217;s SQL constructs.</span></p>
<div><span style="font-size: medium; font-family: Times New Roman;">Oracle SET operators are</p>
<p></span></div>
<table border="1" width="61%">
<tbody>
<tr>
<td width="30%" align="center"><span style="font-size: medium; font-family: Times New Roman;">UNION</span></td>
<td width="70%"><span style="font-size: medium; font-family: Times New Roman;">returns DISTINCT records      returned from 2 or more queries</span></td>
</tr>
<tr>
<td width="30%" align="center"><span style="font-size: medium; font-family: Times New Roman;">UNION ALL</span></td>
<td width="70%"><span style="font-size: medium; font-family: Times New Roman;">returns ALL records returned      from 2 or more queries</span></td>
</tr>
<tr>
<td width="30%" align="center"><span style="font-size: medium; font-family: Times New Roman;">INTERSECT</span></td>
<td width="70%"><span style="font-size: medium; font-family: Times New Roman;">returns only COMMON records      which are returned from each query</span></td>
</tr>
<tr>
<td width="30%" align="center"><span style="font-size: medium; font-family: Times New Roman;">MINUS</span></td>
<td width="70%"><span style="font-size: medium; font-family: Times New Roman;">reutrns all distinct records      from the first query which are no there in the second query</span></td>
</tr>
</tbody>
</table>
<hr />
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;">DML stands for Data Manipulative Language. SQL DML statements are:</p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;"><strong> </strong><strong>SELECT</strong></p>
<p></span></div>
<p align="left"><strong><span style="font-size: medium; font-family: Times New Roman;">UPDATE<br />
</span></strong></p>
<p align="left"><strong><span style="font-size: medium; font-family: Times New Roman;">INSERT<br />
</span></strong></p>
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;"><strong> </strong><strong>DELETE</strong></p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;">It is interesting to note that the SELECT statement does not actually manipulate any  data. But in<br />
Oracle books it is still classified as DML statements. Hence we too will refer it as DML.</p>
<p></span></div>
<p><span style="font-size: medium; font-family: Times New Roman;"><span style="font-size: large; font-family: Times New Roman;"><strong>SELECT Statements- Basic</strong></span></span></p>
<hr />
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;"><strong> </strong><strong>Basic Syntax:</strong></p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;"><em> </em><em>SELECT Col1, Col2, Col3<br />
FROM Table_name<br />
WHERE col1 = Some condition;</em></p>
<p></span></div>
<p><span style="font-size: medium; font-family: Times New Roman;">As the syntax suggests there  are three main clause in a SELECT statement which are</span></p>
<p><strong>SELECT</strong> &#8211; What are the information that you need to select</p>
<p><strong>FROM</strong> &#8211; From where do you want to select these information</p>
<p><strong>WHERE</strong> &#8211; What are the condtion that you want to use to filter query results</p>
<p>SELECT is the most frequently used statements in SQL. Whatever you want to do with your  data you will need<br />
to use this statement to look for them and check the values of the columns in your record.</p>
<div><span style="font-size: medium; font-family: Times New Roman;">
<dd> <span style="text-decoration: underline;"><strong>Selecting everything from a table</strong></span></dd>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;"><em> </em><em>SELECT * FROM studetns;</em></p>
<p></span></div>
<p><span style="font-size: medium; font-family: Times New Roman;">Executing the above query  will return all the records from Strudents table in your database.</span></p>
<p><strong><span style="text-decoration: underline;">Selecting selected columns from a table</span></strong></p>
<p>S<em>ELECT student_id, f_name, l_name FROM students;</em></p>
<p><em><br />
</em></p>
<div><span style="font-size: medium; font-family: Times New Roman;">The above query will return student_id, f_name and l_name columns only for all records  in the table.</p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;"><span style="text-decoration: underline;"><strong> </strong></span><span style="text-decoration: underline;"><strong>Example 1: Selecting data conditionally and use of &#8220;=&#8221; operator.<br />
</strong></span><br />
<em>SELECT * FROM students WHERE major_subject_id = 30;</em></p>
<p></span></div>
<p><span style="font-size: medium; font-family: Times New Roman;">The above query will select  only those students whose major_subject_id = 30. The query will returns<br />
records for student_ids 106, 107 and 113.</span></p>
<p><small><small><small><span style="text-decoration: underline;"><strong>Example 2: Using &lt; operator</strong></span></small></small></small></p>
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;"><em> </em><em>SELECT * FROM students WHERE major_subject_id &lt; 30;</em></p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;">The above query will return only those records whose major_subject_id is less than 30.</p>
<p></span></div>
<p><span style="font-size: medium; font-family: Times New Roman;"><span style="text-decoration: underline;"><strong>Example 3: Using &gt;  operator</strong></span></span></p>
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;"><em> </em><em>SELECT * FROM students WHERE major_subject_id &gt; 30;</em></p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;"><strong><span style="text-decoration: underline;"> </span></strong><strong><span style="text-decoration: underline;">Example 4: Using &gt; operator</span></strong></p>
<p></span></div>
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;"><em> </em><em>SELECT * FROM students WHERE major_subject_id &gt; 30;<br />
</em></p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;"><span style="text-decoration: underline;"><strong> </strong></span><span style="text-decoration: underline;"><strong>Example 5: Using &gt;= operator</strong></span></p>
<p></span></div>
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;"><em> </em><em>SELECT * FROM students WHERE major_subject_id &gt;= 30;</em></p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;"><span style="text-decoration: underline;"><strong> </strong></span><span style="text-decoration: underline;"><strong>Example 6: Using &gt; operator</strong></span></p>
<p></span></div>
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;"><em> </em><em>SELECT * FROM students WHERE major_subject_id &gt;= 30;<br />
</em></p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;"><span style="text-decoration: underline;"><strong> </strong></span><span style="text-decoration: underline;"><strong>Example 7: Using &lt;&gt; operator</strong></span></p>
<p></span></div>
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;"><em> </em><em>SELECT * FROM students WHERE major_subject_id &lt;&gt; 30;</em></p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;"><span style="text-decoration: underline;"><strong> </strong></span><span style="text-decoration: underline;"><strong>Example 8: Using != operator. </strong></span></p>
<p></span></div>
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;"><em> </em><em>SELECT * FROM students WHERE major_subject_id != 30;<br />
</em><br />
This operator is same as &lt;&gt; operator.</p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;"><span style="text-decoration: underline;"><strong> </strong></span><span style="text-decoration: underline;"><strong>Example 9: Using BETWEEN operator. </strong></span></p>
<p></span></div>
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;"><em> </em><em>SELECT * FROM students WHERE major_subject_id between 20 and 30;<br />
</em><br />
Note here that the lowest value should be the first in the BETWEEN condtion. If you  specify it<br />
like WHERE major_subject_id between 30 and 20 it will not return any record;</p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;"><span style="text-decoration: underline;"> </span><span style="text-decoration: underline;">Example 10: Using BETWEEN operator using date fields. </span></p>
<p></span></div>
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;"><em> </em><em>SELECT * FROM students WHERE dob BETWEEN &#8217;01-Jan-1973&#8242; AND &#8217;31-Dec-1973&#8242;;</em></p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;"><span style="text-decoration: underline;"><strong> </strong></span><span style="text-decoration: underline;"><strong>Example 11: Using BETWEEN operator using date fields. </strong></span></p>
<p></span></div>
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;"><em> </em><em>SELECT * FROM students WHERE dob NOT BETWEEN &#8217;01-Jan-1973&#8242; AND &#8217;31-Dec-1973&#8242;;<br />
</em></p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;"><span style="text-decoration: underline;"><strong> </strong></span><span style="text-decoration: underline;"><strong>Example 12: Using IN operator. </strong></span></p>
<p></span></div>
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;"><em> </em><em>SELECT * FROM students WHERE major_subject_id IN (10,20);<br />
SELECT * FROM students WHERE major_subject_id IN (10);<br />
SELECT * FROM students WHERE major_subject_id IN (10,20,30);<br />
</em></p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;"><span style="text-decoration: underline;"><strong> </strong></span><span style="text-decoration: underline;"><strong>Example 13: Using NOT IN operator. </strong></span></p>
<p></span></div>
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;"><em> </em><em>SELECT * FROM students WHERE major_subject_id NOT IN (10,20);<br />
SELECT * FROM students WHERE major_subject_id NOT IN (10);<br />
SELECT * FROM students WHERE major_subject_id NOT IN (10,20,30);<br />
</em></p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;"><span style="text-decoration: underline;"> </span><span style="text-decoration: underline;">Example 14: Using EXISTS operator. </span></p>
<p></span></div>
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;"><em> </em><em>SELECT * FROM students S<br />
WHERE EXISTS (SELECT 1 FROM majors m<br />
where m.subject_id = s.major_subject_id);<br />
</em></p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;"><span style="text-decoration: underline;"><strong> </strong></span><span style="text-decoration: underline;"><strong>Example 15: Using NOT EXISTS operator. </strong></span></p>
<p></span></div>
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;"><em> </em><em>SELECT * FROM students S<br />
WHERE NOT EXISTS (SELECT 1 FROM majors m<br />
where m.subject_id = s.major_subject_id);<br />
</em></p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;"><span style="text-decoration: underline;"><strong> </strong></span><span style="text-decoration: underline;"><strong>Example 16: Using LIKE operator. </strong></span></p>
<p></span></div>
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;"><em> </em><em>SELECT * FROM students WHERE f_name LIKE &#8216;S%&#8217;;</em></p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;">The above query will return only those records whose f_name start<br />
with &#8220;S&#8221;. Here &#8220;%&#8221; stands for all other values. So As long as the  first character in f_name<br />
column starts with &#8220;S&#8221;, the record will be returned.</p>
<p></span></div>
<p><span style="font-size: medium; font-family: Times New Roman;"><span style="text-decoration: underline;"><strong>Example 17: Using LIKE  operator. </strong></span></span></p>
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;"><em> </em><em>SELECT * FROM students WHERE f_name NOT LIKE &#8216;S%&#8217;;</em></p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;">The above query will return those records whose f_name DOES NOT start<br />
with &#8220;S&#8221;.</p>
<p></span></div>
<p><span style="font-size: medium; font-family: Times New Roman;"><span style="text-decoration: underline;"><strong>Example 18: Using OR  operator. </strong></span></span></p>
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;"><em> </em><em>SELECT * FROM students WHERE major_subject_id = 10 OR major_subject_id= 40;</em></p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;">The above query returns all records where major_subject_id equal 10 or 40.</p>
<p></span></div>
<p><span style="font-size: medium; font-family: Times New Roman;"><span style="font-size: large; font-family: Times New Roman;"><strong>SET Operators by example</strong></span></span></p>
<hr />
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;">1. Example of UNION</p>
<p></span></div>
<div>
<p><span style="font-size: medium; font-family: Times New Roman;"> </span></div>
<div><em> </em><em>SELECT * FROM students WHERE major_subject_id IN (30, 40)<br />
UNION<br />
SELECT * FROM students WHERE major_subject_id = 40;</em></div>
<div><em> </em><em>Reurns all disticnt records returned by the first and second query.</em></div>
<p><em>2. Example of UNION ALL</em></p>
<p><em>SELECT * FROM students WHERE major_subject_id IN (30, 40)<br />
UNION ALL<br />
SELECT * FROM students WHERE major_subject_id = 40;</em></p>
<p>Returns all recors combined from first and second query. From the above query you will  notice<br />
that you will get the records with major_subject_id twice.</p>
<p>3. Example of INTERSECT</p>
<p><em>SELECT * FROM students WHERE major_subject_id IN (30, 40)<br />
INTERSECT<br />
SELECT * FROM students WHERE major_subject_id = 40;<br />
</em><br />
Returns all records which must be returned from both queries. In the above example you  will get<br />
records for major_subject_id = 40 as the satisfies both first and second query.</p>
<p>4. Example of MINUS</p>
<p><em>SELECT * FROM students WHERE major_subject_id IN (30, 40)<br />
MINUS<br />
SELECT * FROM students WHERE major_subject_id = 40;<br />
</em><br />
Reutrns all those records fro the first query which are not there in the second query. AS  we can see above<br />
major_subject_id = 40 is returned by both queries, so they will nto be selected. After  removing<br />
major_subject_id = 40 from the first query we still have records for major_subject_id =  30;</p>
<p>So the result from the above query will be all records which satisfies major_subject_id  = 30;</p>
<h1><strong><span style="font-size: large; font-family: Times New Roman;">NULL Values</span></strong></h1>
<hr />
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;">NULL is a special value in Oracle which means nonthig or no value at all. NULL valued  need to be handled<br />
explicitly as they are not equl to Zero &#8220;0&#8243; or Blank Space &#8221; &#8220;.</p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;">Oracle Provides IS NULL and IS NOT NULL operators to work with NULL values.</p>
<p></span></div>
<p><span style="font-size: medium; font-family: Times New Roman;">For example if you want to  select all records from Students table who do not have any major assigned to the<br />
(meaning they have NULL in major_subject_id column) your query should look like this:</span></p>
<p><em>SELECT * FROM students WHERE major_subject_id IS NULL;</em></p>
<p>This will return only one record, that of David Armstrong who do not have any major  subject ID.</p>
<p>Now if you want to select all those reocrds who definitely have a major subject ID when  you can run the query</p>
<p><em>SELECT * FROM students WHERE major_subject_id IS NOT NULL;</em></p>
<p>The above record returns all records from Students table but David Armstrong. Because  his major subject ID is<br />
NULL and the above query clearly said to return only those records where major subject id  IS NOT NULL.</p>
<p><span style="font-size: large; font-family: Times New Roman;"><strong>SELECT Statements &#8211;  Advanced</strong></span></p>
<hr />
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;"><span style="text-decoration: underline;"><strong> </strong></span><span style="text-decoration: underline;"><strong>SELECT Statement with ORDER BY Clause:<br />
</strong></span><br />
ORDER BY clause is used to order/sort data in for particular order as specified in the  ORDER BY CLAUSE.<br />
If I want to order all the students returned by a query such that the oldest students (dob  value lowest<br />
or earliest) comes first then I can use the query</p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;"><em> </em><em>SELECT * FROM students<br />
WHERE (major_subject_id = 10 OR major_subject_id= 40)<br />
ORDER BY dob;<br />
</em><br />
The above query will return all return students whose major_subject_id is 10 or 40. Then  the result<br />
will be displayed where data is ordered by dob column.</p>
<p></span></div>
<p><span style="font-size: medium; font-family: Times New Roman;">Data can be ordered by  Ascending Order or Descending Order. The default is Ascending Order. In the above<br />
query I did not specify any order. So the result came in Ascending order.</span></p>
<p>To Specify the order I can use the following query:</p>
<p><em>SELECT * FROM students<br />
WHERE major_subject_id = 10 OR major_subject_id= 40<br />
ORDER BY dob asc;</em></p>
<p>ASC stands for Ascending.</p>
<p>To order data in Descending order I can use the query:</p>
<p><em>SELECT * FROM students<br />
WHERE major_subject_id = 10 OR major_subject_id= 40<br />
ORDER BY dob desc;</em></p>
<p>I can use Ascending Order and Descending Order together in the same query on different  columns as shown<br />
below</p>
<p><em>SELECT * FROM students<br />
WHERE major_subject_id = 10 OR major_subject_id= 40<br />
ORDER BY f_name asc, l_name desc;</em></p>
<p><span style="text-decoration: underline;"><strong>SELECT Statement with GROUP BY Clause:</strong></span></p>
<p>I can use the GROUP BY clause with a select statement to group all the returned data  together to<br />
display divided into groups. For example if I want to count the number of students and  group them by their<br />
major subjects I can use the query:</p>
<p><em>SELECT major_subject_id, count(*)<br />
FROM students<br />
WHERE major_subject_id IS NOT NULL<br />
GROUP BY major_subject_id;<br />
</em></p>
<p><span style="text-decoration: underline;"><strong>SELECT Statement with GROUP BY and HAVING Clause:</strong></span></p>
<p>Another clause that is usefull is the HAVING clause. In the example below the query  reutrns only thos<br />
subject_id&#8217;s where the number of studfent enrolled us greater than 4</p>
<div><em> </em><em>SELECT major_subject_id, COUNT (*)<br />
FROM students<br />
WHERE major_subject_id IS NOT NULL<br />
GROUP BY major_subject_id<br />
HAVING COUNT (*) &gt; 4;</em></div>
<div><em>
<dd> <span style="text-decoration: underline;"><strong>SELECT Statement with GROUP BY and ORDER BY Clause:</strong></span></dd>
<p> </em><em> </em><em> </em></div>
<p><em>It is possible to use GROUP BY and ORDER BY clauses in the same query as show below:</em></p>
<p><em>SELECT major_subject_id, COUNT (*)<br />
FROM students<br />
WHERE major_subject_id IS NOT NULL<br />
GROUP BY major_subject_id<br />
ORDER BY major_subject_id;</em></p>
<p>The above query will display the each major_subject_id&#8217;s and how many students are  enrolled in those<br />
subjects.</p>
<p><span style="text-decoration: underline;"><strong>SELECT Statement with GROUP BY and ORDER BY Clause:</strong></span></p>
<p>Example of GROUP BY, HAVING and ORDER BY Clauses all in the same query:</p>
<p><em>SELECT major_subject_id, COUNT (*)<br />
FROM students<br />
WHERE major_subject_id IS NOT NULL<br />
GROUP BY major_subject_id<br />
HAVING COUNT (*) &gt;= 4<br />
ORDER BY major_subject_id;<br />
</em></p>
<p><span style="text-decoration: underline;"><strong>SELECT Statement USING subquery:</strong></span></p>
<p>A SELECT Statement with a subquery is a query which uses the result of another query  (the sub query)<br />
as values in its WHERE clause. In the example below the subquery first finds the  subject_id for the Subject<br />
Biology, in this case the value is 10. The outer SELECT statement then uses the value from  the subquery<br />
to filter the data from the students table in its WHERE clause.</p>
<p><em>SELECT * FROM students<br />
WHERE major_subject_id<br />
IN ( SELECT subject_id<br />
FROM majors<br />
WHERE subject_name=&#8217;Biology&#8217;<br />
);</em></p>
<p>It is possible to use more than one column in a subquery as shown below:</p>
<div><em> </em><em>SELECT * FROM students<br />
WHERE (student_id, major_subject_id) in (<br />
SELECT student_id, major_subject_id<br />
FROM students<br />
WHERE major_subject_id=30);</em></div>
<div><em>
<dd> A SELECT query may have a multiple level of sub queries. The example below shows a query    where there are two sub<br />
sub query used by the outer query. Oracle supports enough level of sub queries which    should surely meet meet<br />
your requirement.</dd>
<p> </em><em> </em><em> </em></div>
<p><em><em>SELECT * FROM students<br />
WHERE major_subject_id in (<br />
SELECT subject_id<br />
FROM majors<br />
WHERE subject_name = (SELECT subject_name<br />
FROM majors<br />
WHERE subject_teacher = &#8216;Dr. Elms Somerfield&#8217;)) </em></em></p>
<p><span style="text-decoration: underline;"><strong>Co-Related Sub Queries</strong></span></p>
<p>A co-related subquery is a query where the outer query is executed first. Then for each  record returned by the<br />
outer query, the inner query is executed. In the example below the outer query first gets  student record from<br />
students table and then it executes the inner query once for each record returned by the  outer query. In the<br />
sub query the value of major_subject_id of the outer record is checked against the value  of subject_id of<br />
majors table. If the values match then only that record will be displayed to us. That is  why the record below<br />
will not return the student record which does not have a subject id assigned to it.</p>
<p><span style="font-family: Times New Roman;"><em><span style="font-size: medium;"><br />
</span><big>SELECT * FROM students s<br />
WHERE EXISTS<br />
(SELECT 1<br />
FROM majors m<br />
WHERE s.major_subject_id = m.subject_id);</big></em></span></p>
<p align="left">
<div>
<p><span style="font-size: medium; font-family: Times New Roman;"> </span></div>
<div><span style="font-size: medium; font-family: Times New Roman;"><span style="text-decoration: underline;"> </span><span style="text-decoration: underline;">In-Line Views</span></p>
<p></span></div>
<p><span style="font-size: medium; font-family: Times New Roman;">In a SQL query&#8217;s FROM clause  you can use the return values of another query as<br />
if they are a table. This technique helps to simplify SQL queries.</span></p>
<p>An example is:</p>
<p><em>SELECT *<br />
FROM students a, (SELECT * FROM majors) b<br />
WHERE a.major_subject_id = b.subject_id<br />
AND a.major_subject_id=10;<br />
</em></p>
<p><span style="font-size: large; font-family: Times New Roman;"><strong>JOINS</strong></span></p>
<hr />
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;">In SQL more than one table can be used in the FROM clause to select results from  different tables.<br />
The list of table in the FROM caluse could be quite long. Also there are old ways of<br />
writing joins and new ways of writing joins (ANSI SQL).</p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;">In Most of my DML statements I&#8217;ll use I old way joins which can be easily convered to  new JOIN types<br />
if you prefer so.</p>
<p></span></div>
<p><span style="font-size: medium; font-family: Times New Roman;"><span style="text-decoration: underline;"><strong>Inner Join or Equi  Joins</strong></span></span></p>
<p>Example 1: Joining two tables to display results from both tables.</p>
<p><em>SELECT subject_name, f_name, l_name<br />
FROM students s, majors m<br />
WHERE s.major_subject_id = m.subject_id<br />
and m.subject_name=&#8217;History&#8217;;<br />
</em><br />
In the above example students and majors tables are joined together. The joining condition  is<br />
specified in where clause as:</p>
<p><em>&#8220;WHERE s.major_subject_id = m.subject_id<br />
and m.subject_name=&#8217;History&#8217;&#8221;<br />
</em><br />
It means that display all the students whose major subject is History. We can get the same  information<br />
except the subject name from students atble if we query it with the major_subject_id. But  if you need<br />
the subject name in your displayed result then you must join the two tables.</p>
<p>Example 2: The query in example 1 can be re-written using the new ANSI JOIN as</p>
<p><em>SELECT subject_name, f_name, l_name<br />
FROM students s<br />
INNER JOIN majors m on<br />
s.major_subject_id = m.subject_id<br />
and m.subject_name=&#8217;History&#8217;;</em></p>
<p>Which will give the same result.</p>
<p><span style="text-decoration: underline;"><strong>Outer Join</strong></span></p>
<p>This Join is used to return data where the primary data source is there and there are  no secondary data<br />
source. In the Students and Majors example you will have noticed that the subject Social  Science was not taken<br />
by any student. So when you join Students and Majors tables with a simple equi join or  inner join you will<br />
get only those major subjects and their students which were taken by students with the  condition</p>
<p><em>students.major_subject_id = major.subject_id.</em></p>
<p>So to get all the Majors and the students who has taken those majors you will need to  use a SPEACIAL join<br />
called OUTER JOIN. In Oracle OUTER JOIN is denoted by &#8220;+&#8221;.</p>
<p>The query below will return all the Majors and students</p>
<p><em>SELECT subject_name, f_name, l_name<br />
FROM students s, majors m<br />
WHERE s.major_subject_id(+) = m.subject_id;<br />
</em></p>
<p>NOTE: It is important to note that you will need to put the &#8220;+&#8221; sign to the  column where there are no values.<br />
In the example above I have said s.major_subject_id(+) because I know that there are no  record which matches<br />
the subject_id for Social Science in Students table.</p>
<p>In new ANSI JOIN format it will look like this</p>
<p><em>SELECT subject_name, f_name, l_name<br />
FROM students s<br />
RIGHT JOIN majors m on<br />
s.major_subject_id = m.subject_id;<br />
</em><br />
The &#8220;RIGHT JOIN&#8221; means that return all records from the table on the right hand  side of the join condition<br />
(in this case Majors denoted as m) even if there are no corresponding values in the LEFT  table<br />
(in this case Students denoted as s).</p>
<p>Similarly there is a LEFT JOIN which means retrun everything from the right hand side  of the condition<br />
even if no corresponding value exists in the left hand side of the conditon. For example:</p>
<p><em>SELECT m.subject_name, f_name, l_name<br />
FROM students s<br />
LEFT JOIN majors m on<br />
s.major_subject_id = m.subject_id;<br />
</em><br />
The query above will David Armstrong&#8217;s record even though it does not have a major subject  ID.</p>
<p><span style="font-size: large; font-family: Times New Roman;"><strong>USING Oracle FUNCTIONS in  SQL</strong></span></p>
<hr />
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;"><span style="text-decoration: underline;"><strong> </strong></span><span style="text-decoration: underline;"><strong>NVL </strong></span></p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;">This is a Oracle supplied function used to handle null values.</p>
<p></span></div>
<p><span style="font-size: medium; font-family: Times New Roman;">In our Students table we know  that David Armstrong has a NULL major subject ID. If run the query</span></p>
<p><em>SELECT student_id, f_name, l_name, major_subject_id FROM students;</em></p>
<p>Then it will return all records from students table and will display a NULL for Davis&#8217;  major subject id.<br />
But we can replace the NULL value in the result and instead show a more value such as  &#8217;999&#8242;. To do that<br />
we will use NVL function as show below:</p>
<p><em>SELECT student_id, f_name, l_name, NVL(major_subject_id,&#8217;999&#8242;) FROM students;</em></p>
<p>In the above query the NVL function will check each returned value of major_subject_id.  If if finds the<br />
major_subject_id is NULL then it will replace it with 999 or whatever value you would like  to assign.</p>
<p>In the example below I am assigning major_subject_id = 20 to any record which has a  NULL major_subject_id.</p>
<div><em> </em><em>SELECT s.* FROM students s, majors m<br />
WHERE nvl(s.major_subject_id,&#8217;20&#8242;) = m.subject_id;</em></div>
<div><em> </em><em>So above query will returned David Armstrong&#8217;s record with subject_id 20 aissgned to  it.</em></div>
<p><em><span style="text-decoration: underline;"><strong>DECODE</strong></span></em></p>
<p>This function is used to replace a value from the returned result to make it for  usefull for your purpose. It<br />
is like an if-then-else construct.</p>
<p>Eor example If I run the query</p>
<p><em>SELECT f_name, l_name, major_subject_id<br />
FROM students;<br />
</em><br />
I&#8217;ll get all records from students table which will display major_subject_id as 10, 20, 30  etc as they are<br />
in the table.</p>
<p>But If I want to replace the value of major_subject_id 10 by &#8220;Biological  Sciences&#8221; and the rest of the values<br />
to be displayed as they are I can issue the command:</p>
<p><em>SELECT f_name, l_name,  DECODE(major_subject_id,10,&#8217;Biological Sciences&#8217;,  major_subject_id)<br />
FROM students;</em></p>
<p>It simply means that</p>
<p>if major_subject_id = 10 then<br />
display Biological Sciences<br />
else<br />
display whatever value is returned.<br />
end if;</p>
<p>The above query will display major_subject_id as Biological Sciences for all records  where major_subject_id=10.<br />
The &#8220;major_subject_id&#8221; after &#8220;&#8216;Biological Sciences&#8217;,&#8221; in the above  statement means display whatever is there<br />
in the table (statement in the ELSE condition).</p>
<p>It is possible to large number of values in decode statement. For example</p>
<p><em>SELECT f_name, l_name, DECODE(major_subject_id,10,&#8217;Biological Sciences&#8217;, 20,  &#8216;Chemical Sciences&#8217;, major_subject_id)<br />
FROM students.<br />
</em><br />
It simply means that</p>
<p>if major_subject_id = 10 then<br />
display Biological Sciences<br />
elsif major_subject_id = 20 then<br />
display Chemical Sciences<br />
else<br />
display whatever value is returned.<br />
end if;</p>
<p><span style="text-decoration: underline;"><strong>CASE</strong></span></p>
<p>Case is another form of if-then-else construct.<br />
<em><br />
SELECT CASE major_subject_id<br />
WHEN 10 THEN<br />
&#8216;Biological Sciences&#8217;<br />
WHEN 20 THEN<br />
&#8216;Chemical Sciences&#8217;<br />
ELSE<br />
&#8216;Other Subject&#8217;<br />
end Subject<br />
FROM students;<br />
</em><br />
The above query means that</p>
<p>if major_subject_id = 10 then<br />
display Biological Sciences<br />
elsif major_subject_id = 20 then<br />
display Chemical Sciences<br />
else<br />
display Other Subject<br />
end if;</p>
<p><span style="text-decoration: underline;"><strong>TO_DATE</strong></span></p>
<p>This is a very powerfull robust Oracle function that you will find yourself using in  your day to day work.<br />
So it is very important you understand this function as much as possible.</p>
<p>In the basic form it&#8217;s syntax looks like this:</p>
<p>TO_DATE(DateInString, Format).</p>
<p>Example of TO_DATE Function</p>
<div><em> </em><em>SELECT TO_DATE(&#8217;01-DEC-2009&#8242;,&#8217;DD-MON-YYYY&#8217;) from dual;</em></div>
<div><em> </em><em>SELECT TO_DATE(&#8216;DEC-01-2009&#8242;,&#8217;MON-DD-YYYY&#8217;) from dual;</em></div>
<p><em>SELECT TO_DATE(&#8217;01-12-2009&#8242;,&#8217;DD-MM-YYYY&#8217;) from dual;</em></p>
<p><em>SELECT TO_DATE(&#8217;12-01-2009&#8242;,&#8217;MM-DD-YYYY&#8217;) from dual;</em></p>
<p><em>SELECT TO_DATE(&#8217;01-DEC-2009 10:30.11&#8242;,&#8217;DD-MON-YYYY HH:MI:SS&#8217;) from dual;</em></p>
<p><em>SELECT TO_DATE(&#8217;01-DEC-2009 14:30.11&#8242;,&#8217;DD-MON-YYYY HH24:MI:SS&#8217;) from dual;</em></p>
<p><em>In the above explample notice that I am using a table called &#8220;dual&#8221;. This  is a special table provided<br />
in Oracle to satisfy the need for a table in a SELECT statement. By now is is clear that  any SELECT query<br />
we write uses a table from where to select the data. But there are some situation where  you don&#8217;t have<br />
the table. For example you want to display the Oracle system date. There is no such table  which stored<br />
this information. But you can use SYSDATE to do that in your select statement. But without  a table how can<br />
you write your SELECT statement. This is where the special table called &#8220;dual&#8221;  comes in.</em></p>
<p>If you say</p>
<p><em>SELECT sysdate FROM dual;</em></p>
<p>It will display the Oracle system date and you did not used any actal table in your  SELECT statement. In<br />
the examples below you will see many examples of the usefullness of this table.</p>
<p><strong><span style="text-decoration: underline;">TO_CHAR</span></strong></p>
<p>This is also a very powerfull robust Oracle function that you will find yourself using  in your day to day work.<br />
The function is generally used for DatE formatting and Number formatting.</p>
<p><strong>Date Formating &lt;TO_CHAR(date)&gt;</strong></p>
<p><strong>Basic Syntax: </strong></p>
<p><em>TO_CHAR(date1, format_mask).</em></p>
<p>The TO_CHAR (date) function takes a date as input parameter and convert it into  CHARACTER and display the<br />
result as specified in the market mask.</p>
<p>Acceptable format masks:</p>
<p>D<br />
DD<br />
DDD<br />
DY<br />
DAY</p>
<p>MM<br />
MON<br />
MONTH</p>
<p>Y<br />
YY<br />
YYY<br />
YYYY<br />
RR<br />
RRRR<br />
HH<br />
HH24</p>
<p>MI<br />
SS<br />
SSSSS<br />
FF<br />
AM<br />
PM</p>
<p>Example using these format masks.</p>
<div><em> </em><em>SELECT TO_CHAR(sysdate, &#8216;d&#8217; ) from dual;</em></div>
<div><em> </em><em>SELECT TO_CHAR(sysdate, &#8216;dd&#8217; ) from dual;</em></div>
<p><em>SELECT TO_CHAR(sysdate, &#8216;ddd&#8217; ) from dual;</em></p>
<p><em>SELECT TO_CHAR(sysdate, &#8216;Dy&#8217; ) from dual;</em></p>
<p><em>SELECT TO_CHAR(sysdate, &#8216;Day&#8217; ) from dual;</em></p>
<p><em>SELECT TO_CHAR(sysdate, &#8216;mm&#8217; ) from dual;</em></p>
<p><em>SELECT TO_CHAR(sysdate, &#8216;YY&#8217; ) from dual;</em></p>
<p><em>SELECT TO_CHAR(sysdate, &#8216;RR&#8217; ) from dual;</em></p>
<p><em>SELECT TO_CHAR(sysdate, &#8216;YYYY&#8217; ) from dual;</em></p>
<p><em>SELECT TO_CHAR(sysdate, &#8216;RRRR&#8217; ) from dual;</em></p>
<p><em>SELECT TO_CHAR(sysdate,&#8217;DD-MON-YYYY&#8217;) from dual;</em></p>
<p><em>SELECT TO_CHAR(sysdate,&#8217;DD-Mon-YYYY&#8217;) from dual;</em></p>
<p><em>SELECT TO_CHAR(sysdate,&#8217;DD-MONTH-YYYY&#8217;) from dual;</em></p>
<p><em>SELECT TO_CHAR(sysdate,&#8217;DD-MON-YYYY hh24&#8242;) from dual;</em></p>
<p><em>SELECT TO_CHAR(sysdate,&#8217;DD-MON-YYYY hh24:mi&#8217;) from dual;</em></p>
<p><em>SELECT TO_CHAR(sysdate,&#8217;DD-MON-YYYY hh24:mi:ss&#8217;) from dual;</em></p>
<p><em>SELECT TO_CHAR(sysdate,&#8217;MON-DD-YYYY&#8217;) from dual;</em></p>
<p><em>SELECT TO_CHAR(sysdate,&#8217;MM-DD-YYYY&#8217;) from dual;</em></p>
<p><em>SELECT TO_CHAR(sysdate,&#8217;MONTH-DD-YYYY&#8217;) from dual;</em></p>
<p><em>SELECT TO_CHAR(sysdate,&#8217;YYYY-Mon-DD&#8217;) from dual;</em></p>
<p><em>SELECT TO_CHAR(sysdate,&#8217;YYYY-MON-DD&#8217;) from dual;</em></p>
<p><em>SELECT TO_CHAR(sysdate,&#8217;YYYY-MM-DD&#8217;) from dual;</em></p>
<p><em><br />
</em></p>
<div><strong> </strong><strong>Number Formatting &lt;TO_CHAR(number)&gt;</strong></div>
<div><strong> </strong><strong>Basic Syntax:</strong></div>
<p><strong><em>TO_CHAR(number1, format_mask).</em></strong></p>
<p><strong>The TO_CHAR (number) function takes a number as input parameter and convert it into  CHARACTER and display the<br />
result as specified in the market mask.</strong></p>
<p>Some example are here:</p>
<div><em> </em><em>select to_char(&#8217;1234560&#8242;,&#8217;$99,99,9999&#8242;) from dual;</em></div>
<div><em> </em><em>select to_char(&#8217;1234560&#8242;,&#8217;$99,99,9999.99&#8242;) from dual;</em></div>
<p><em>select to_char(&#8217;1234560.789&#8242;,&#8217;$99,99,9999.9&#8242;) from dual;</em></p>
<p><em>select to_char(&#8217;1234560.789&#8242;,&#8217;$99,99,9999.99&#8242;) from dual;</em></p>
<p><em>select to_char(&#8217;1234560.789&#8242;,&#8217;$99,99,9999.990&#8242;) from dual;</em></p>
<p><em>select to_char(&#8217;1234560.789&#8242;,&#8217;$99,99,9999.9900&#8242;) from dual;</em></p>
<p><em>select to_char(&#8217;1234560.789&#8242;,&#8217;$99,99,9999.99000&#8242;) from dual;</em></p>
<p><span style="text-decoration: underline;"><em><strong>UPPER</strong></em></span></p>
<p>Basic Syntax:</p>
<p><em>UPPER (char);</em></p>
<p>This function accept a character string as input parameter and convert the string  letters<br />
into upper case charcters. In will ignore numbers if there are any in the input string.</p>
<p>Example;</p>
<div><em> </em><em>select upper(&#8216;te12St&#8217;) from dual;</em></div>
<div><em> </em><em>select upper(&#8216;test&#8217;) from dual;</em></div>
<p><em>select upper(&#8216;test&#8217;) from dual;</em></p>
<p><span style="text-decoration: underline;"><em><strong>LOWER</strong></em></span></p>
<p>Basic Syntax:</p>
<p><em>LOWER (char);</em></p>
<p>This function accept a character string as input parameter and convert the string  letters<br />
into lower case charcters. In will ignore numbers if there are any in the input string.</p>
<p>Example;</p>
<div><em> </em><em>select upper(&#8216;TE12st&#8217;) from dual;</em></div>
<div><em> </em><em>select upper(&#8216;TesT&#8217;) from dual;</em></div>
<p><em>select upper(&#8216;Test&#8217;) from dual;</em></p>
<p><span style="text-decoration: underline;"><em><strong>SUBSTR</strong></em></span></p>
<p>Basic Syntax:<br />
<em>SUBSTR (strin1, pos1, pos2);<br />
</em><br />
pos1 &#8211; is the start of the string<br />
pos2 &#8211; is the number of characters starting from pos1. If no pos2 is specified then the  function<br />
will return the all the remaining characters starting from pos1.</p>
<p>Some example:</p>
<div><em> </em><em>SELECT SUBSTR(&#8216;ABCDEFGH&#8217;, 2, 3) from dual; will return BCD.</em></div>
<div><em> </em><em>SELECT SUBSTR(&#8216;ABCDEFGH&#8217;, 5, 3) from dual; will return EFG.</em></div>
<p><em>SELECT SUBSTR(&#8216;ABCDEFGH&#8217;, 1, 5) from dual; will return ABCDE.</em></p>
<p><em>SELECT SUBSTR(&#8216;ABCDEFGH&#8217;, 3, 15) from dual; will return CDEFGH.</em></p>
<p><em>SELECT SUBSTR(&#8216;ABCDEFGH&#8217;, 5) from dual; will return EFGH.</em></p>
<p><em><br />
</em></p>
<p align="left"><span style="font-size: medium; font-family: Times New Roman;"><span style="text-decoration: underline;"><strong>INSTR<br />
</strong></span><br />
Basic Syntax:</span></p>
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;"><em> </em><em>INSTR (string1, string2, start_position, nth occurance);<br />
</em><br />
This function returns the starting position of string2 in string1. The search starts at  start_position<br />
and looks for the nth occurance of the string2.</p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;">Suppose String1=&#8217;CORRUPTION CONTROL COORDINATOR&#8217;;</p>
<p></span></div>
<p><span style="font-size: medium; font-family: Times New Roman;">Example 1:</span></p>
<p><em>SELECT INSTR(&#8216;CORRUPTION CONTROL COORDINATOR&#8217;,'CO&#8217;, 1, 1) from dual; </em></p>
<p align="left">
<div><span style="font-size: medium; font-family: Times New Roman;">will return 1. The function is looking</p>
<p></span></div>
<div><span style="font-size: medium; font-family: Times New Roman;">for the string2 value &#8220;CO&#8221; in string1 &#8211; starting at position 1. It is lokking  for the first occurance which<br />
is at position 1. So the return value is 1.</p>
<p></span></div>
<p><span style="font-size: medium; font-family: Times New Roman;">Example 1:</span></p>
<p><em>SELECT INSTR(&#8216;CORRUPTION CONTROL COORDINATOR&#8217;,'CO&#8217;, 1, 2) from dual; </em>will return  12.</p>
<p>It looks for the string2 value &#8220;CO&#8221; in string1 &#8211; starting at position 1. It  is lokking for the 2nd occurance<br />
which is at position 12 (CONTROL). So the return value is 12.</p>
<p>Example 2:<br />
<em>SELECT INSTR(&#8216;CORRUPTION CONTROL COORDINATOR&#8217;,'CO&#8217;, 8, 2) </em>from dual;will return 20.</p>
<p>It looks for the string2 value &#8220;CO&#8221; in string1 &#8211; starting at position 8. It  is lokking for the 2nd occurance<br />
which is at position 20 (COORDINATOR). So the return value is 20.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oraclecity.com/sql-tutorial/sql-tutorial/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

