<?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>Dev Corner</title>
	<atom:link href="http://devcorner.georgievi.net/feed" rel="self" type="application/rss+xml" />
	<link>http://devcorner.georgievi.net</link>
	<description>Software Developer's Notepad</description>
	<lastBuildDate>Fri, 12 Aug 2011 20:03:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to store and order date and time in SQLite</title>
		<link>http://devcorner.georgievi.net/pages/database/store-time-sqlite</link>
		<comments>http://devcorner.georgievi.net/pages/database/store-time-sqlite#comments</comments>
		<pubDate>Fri, 12 Aug 2011 20:02:19 +0000</pubDate>
		<dc:creator>bateto</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[SQLite]]></category>
		<category><![CDATA[human readable]]></category>
		<category><![CDATA[order]]></category>
		<category><![CDATA[sql date time]]></category>
		<category><![CDATA[store]]></category>
		<category><![CDATA[system storage]]></category>

		<guid isPermaLink="false">http://devcorner.georgievi.net/?p=425</guid>
		<description><![CDATA[
In SQLite there is no class used for storing date and time. But there are still some handful functions, which are for working with time information.


1. How to get the current date and time ?



SELECT datetime(‘now’)




In this query the string &#8216;now&#8217;, is converted into the current date and time in the format YYYY-MM-DD HH:MM:SS. But [...]]]></description>
			<content:encoded><![CDATA[<p>
In SQLite there is no class used for storing date and time. But there are still some handful functions, which are for working with time information.
</p>
<p><span id="more-425"></span></p>
<h3>1. How to get the current date and time ?</h3>
<div class="wp_syntax">
<div class="code">
<pre class="sql" style="font-family:monospace;">
SELECT datetime(‘now’)
</pre>
</div>
</div>
<p>
In this query the string &#8216;now&#8217;, is converted into the current date and time in the format <em>YYYY-MM-DD HH:MM:SS</em>. But SQLite does not support date arithmetic for this format.
</p>
<h3>2. Receive the current time as an integer</h3>
<div class="wp_syntax">
<div class="code">
<pre class="sql" style="font-family:monospace;">
SELECT strftime('%s',’now’)
</pre>
</div>
</div>
<p>
This query uses the function strftime, which returns the current time as Unix Time – the passed seconds since 1970-01-01. Universal Coordinated Time (UTC) is used.  This is much more useful format, because it is an integer data, which is supported by SQLite data class. This means that arithmetical calculations could be made using the result from this query. Also, this data in this format could be easily ordered and stored. Even, if we want to store the moment, that a row is inserted in a table, we could use a column for the date and time, using a default value the result of this function.
</p>
<h3>3.	Get the result back</h3>
<div class="wp_syntax">
<div class="code">
<pre class="sql" style="font-family:monospace;">
SELECT datetime(strftime('%s',’now’),'localtime', 'unixepoch')
</pre>
</div>
</div>
<p>
This<br />
This query uses the function datetime to convert the integer result from the strftime function, which is time in  Universal Coordinated Time (UTC). So to set it to the system time the &#8216;localtime&#8217; modificator is used. The result of this reverting function is again in the human readable format &#8211; <em>YYYY-MM-DD HH:MM:SS</em>.
</p>
<p>
This are the steps that could be used, to emulate a date and time class in SQLite, which could be a great miss, if we want to use our database to store time information – a very frequent practice.</p>
]]></content:encoded>
			<wfw:commentRss>http://devcorner.georgievi.net/pages/database/store-time-sqlite/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>This Is the Perfect Solution for Stopping Spam [Comic]</title>
		<link>http://devcorner.georgievi.net/pages/uncategorized/this-is-the-perfect-solution-for-stopping-spam-comic</link>
		<comments>http://devcorner.georgievi.net/pages/uncategorized/this-is-the-perfect-solution-for-stopping-spam-comic#comments</comments>
		<pubDate>Tue, 24 May 2011 09:22:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[fun]]></category>

		<guid isPermaLink="false">http://devcorner.georgievi.net/?p=423</guid>
		<description><![CDATA[A nice comic:
This Is the Perfect Solution for Stopping Spam [Comic]
]]></description>
			<content:encoded><![CDATA[<p>A nice comic:</p>
<p><a title="This Is the Perfect Solution for Stopping Spam Comic at HowToGeek.com" href="http://www.howtogeek.com/howto/42413/this-is-the-perfect-solution-for-stopping-spam-comic/">This Is the Perfect Solution for Stopping Spam [Comic]</a></p>
]]></content:encoded>
			<wfw:commentRss>http://devcorner.georgievi.net/pages/uncategorized/this-is-the-perfect-solution-for-stopping-spam-comic/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Find the First image In WordPress Post or Page</title>
		<link>http://devcorner.georgievi.net/pages/wordpress/wordpress-development/find-first-image-wordpress-post-page</link>
		<comments>http://devcorner.georgievi.net/pages/wordpress/wordpress-development/find-first-image-wordpress-post-page#comments</comments>
		<pubDate>Sun, 15 May 2011 15:30:04 +0000</pubDate>
		<dc:creator>baobab</dc:creator>
				<category><![CDATA[WordPress Development]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[wordpress tips]]></category>

		<guid isPermaLink="false">http://devcorner.georgievi.net/?p=416</guid>
		<description><![CDATA[You need to add icons to your search results, archives or simply to enable the Facebook Open Graph protocol on your blog site. This task can be accomplished by extracting the URL of the first image, used in post. If you follow certain conventions, this can always be the post or page thumbnail. I have [...]]]></description>
			<content:encoded><![CDATA[<p>You need to add icons to your search results, archives or simply to enable the Facebook Open Graph protocol on your blog site. This task can be accomplished by extracting the URL of the first image, used in post. If you follow certain conventions, this can always be the post or page thumbnail. I have seen many solutions to this relatively simple problem. Unfortunately most of them are incorrect. Here is the right PHP code to get the first image URL from the post content.<span id="more-416"></span></p>
<pre>
&lt;?php

class com_bul7_wp_utils {

    // ...........

    public static function getFirstPostImage() {
          global $post;
          if (!preg_match('/<img[^&gt;]*src=([\'"])(.*?)\\1/i', $post->post_content, $matches)) {
              return NULL;
          }
          return $matches[2];
    }

    // ...........

}

?&gt;
</pre>
<p>The core of this technique is the regular expression that matches the first image in the post content.<br />
I haven&#8217;t used the preg_match_all function, but preg_match, because I need only the first matching tag.</p>
]]></content:encoded>
			<wfw:commentRss>http://devcorner.georgievi.net/pages/wordpress/wordpress-development/find-first-image-wordpress-post-page/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress plugin: Facebook Like Button and Open Graph For Dummies</title>
		<link>http://devcorner.georgievi.net/pages/wordpress/wp-plugins/facebook-like-button-for-dummies</link>
		<comments>http://devcorner.georgievi.net/pages/wordpress/wp-plugins/facebook-like-button-for-dummies#comments</comments>
		<pubDate>Wed, 11 May 2011 17:51:14 +0000</pubDate>
		<dc:creator>baobab</dc:creator>
				<category><![CDATA[WordPress Plugins]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[facebook like]]></category>
		<category><![CDATA[open graph]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[wordpress plugin]]></category>

		<guid isPermaLink="false">http://devcorner.georgievi.net/?p=407</guid>
		<description><![CDATA[There are many WordPress plugins that can add the Facebook button to your site. With this plugin you can not only add Like button. You can use different methods, customize the look and feel and enable the Facebook Open Graph protocol support.

Add Facebook Like button to the beginning or ending of a post or page.
Add [...]]]></description>
			<content:encoded><![CDATA[<p>There are many WordPress plugins that can add the Facebook button to your site. With this plugin you can not only add Like button. You can use different methods, customize the look and feel and enable the Facebook Open Graph protocol support.<span id="more-407"></span></p>
<ul>
<li>Add Facebook Like button to the beginning or ending of a post or page.</li>
<li>Add Facebook Like button to the beginning or ending of the post excerpt on archive pages.</li>
<li>Enable Open Graph protocol support for your blog.</li>
<li>Advanced users can select among number of options and customize the Open Graph protocol details.</li>
<li>Enable content filter as an alternative to the Open Graph protocol.</li>
</ul>
<p>You can download the latest version of the plugin <a href="http://wordpress.org/extend/plugins/facebook-like-button-for-dummies">here</a>.</p>
<p>= 1.0 =<br />
* OpenGraph: Automatic description &#8211; strip new lines and multiple spaces.<br />
* OpenGraph: Automatic description &#8211; configurable max description length.<br />
* OpenGraph: Automatic Image: Use configurable default image.<br />
* OpenGraph: Admins tag support.<br />
* OpenGraph: Configuration settings for enable/disable OpenGraph protocol support.</p>
<p>= 0.2=<br />
* OpenGraph: Automatic Image: Use first image from post<br />
* OpenGraph: Automatic description &#8211; Use &#8220;more&#8221; for description<br />
* OpenGraph: Automatic description &#8211; Generate automatic description, rounded to whole words with about 200 chars length.<br />
* OpenGprah: Automatic description show elipsis if too long.</p>
<p>= 0.1 =<br />
* OpenGraph protocol support<br />
* Setting: Disable all the Facebook Like buttons, automatically added by the plugin<br />
* Ability to automatically add Facebook Like button to Pages<br />
* Ability to automatically add Facebook Like button to Posts</p>
]]></content:encoded>
			<wfw:commentRss>http://devcorner.georgievi.net/pages/wordpress/wp-plugins/facebook-like-button-for-dummies/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FAQ: Facebook Import Comments to WordPress plugin</title>
		<link>http://devcorner.georgievi.net/pages/wordpress/wp-plugins/faq-facebook-import-comments</link>
		<comments>http://devcorner.georgievi.net/pages/wordpress/wp-plugins/faq-facebook-import-comments#comments</comments>
		<pubDate>Sat, 07 May 2011 13:52:43 +0000</pubDate>
		<dc:creator>baobab</dc:creator>
				<category><![CDATA[WordPress Plugins]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://devcorner.georgievi.net/?p=395</guid>
		<description><![CDATA[Frequently Asked Questions for Facebook Import Comments to WordPress plugin
Q. I have some ideas about the plugin. What to do?
A. Great! The plugin is distributed under the GPL license. Everyone can contribute to it. There are many types of contributions. For example:
* comments to existing features
* suggestions for new features
* ideas
* translations in different human [...]]]></description>
			<content:encoded><![CDATA[<h3>Frequently Asked Questions for Facebook Import Comments to WordPress plugin</h3>
<p>Q. I have some ideas about the plugin. What to do?</p>
<p>A. Great! The plugin is distributed under the GPL license. Everyone can contribute to it. There are many types of contributions. For example:<br />
* comments to existing features<br />
* suggestions for new features<br />
* ideas<br />
* translations in different human languages<br />
* direct code contribution</p>
<p>If you have critiques, please share your opinion with me. I would be glad to here your opinion. Maybe I am wrong, or maybe you. Who knows? <img src='http://devcorner.georgievi.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  Let&#8217;s make the world a better place &#8211; together.</p>
<p>Q. What happens if a Facebook user removes its comment for my blog post? What action I should take in this case?</p>
<p>A. Since version 1.1 of the plugin Import Mode control setting allows you to specify the plugin&#8217;s behavior in this case. By default when user removes a comment from facebook, it is also removed from the blog comment&#8217;s list. You can change this behavior by using the &#8220;Append new&#8221; option.</p>
<p>Q. Is the plugin aligned with the Facebook policies?</p>
<p>A. The plugin is aligned with all known Facebook policies and respects user rights. If you think there are some issues with Facebook policies and user rights, I would be glad to hear about them and introduce necessary changes.<br />
In addition some unique plugin features might be useful in this direction:<br />
* &#8220;Delete All Imported Facebook Comments&#8221;<br />
* Import Mode setting</p>
<p>Q. Can I separate comments comming from WordPress and from Facebook comments social plugin.</p>
<p>A. Yes, you modify your theme to visually and physically separate both types of comments. The plugin stores special value in the &#8220;comment_agent&#8221; database field which begins with &#8220;facebook-seo-comments&#8221;. You can use this fact to modify behavior and visual appearance.</p>
<p>Q. Why the plugin stores the comments into the WordPress database?</p>
<p>A. There are three reasons<br />
* The most important reason is performance. The WordPress database is used to cache Facebook API requests. The result is significant reduce in Facebook engine hits and reduced website traffic.<br />
* Improved user experience.<br />
* Seamless integration for comments posted through Facebook comments social plugin and WordPress comment features.</p>
]]></content:encoded>
			<wfw:commentRss>http://devcorner.georgievi.net/pages/wordpress/wp-plugins/faq-facebook-import-comments/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Facebook Import Comments to WordPress plugin</title>
		<link>http://devcorner.georgievi.net/pages/wordpress/wp-plugins/facebook-import-comments</link>
		<comments>http://devcorner.georgievi.net/pages/wordpress/wp-plugins/facebook-import-comments#comments</comments>
		<pubDate>Fri, 06 May 2011 05:34:57 +0000</pubDate>
		<dc:creator>baobab</dc:creator>
				<category><![CDATA[WordPress Plugins]]></category>

		<guid isPermaLink="false">http://devcorner.georgievi.net/?p=377</guid>
		<description><![CDATA[With the Facebook Import Comments WordPress plugin you can import in real time all the user generated content - the comments - into your WordPress blog.]]></description>
			<content:encoded><![CDATA[<p>Many sites are using the popular Facebook Comments Social Plugin. The Facebook Import Comments WordPress plugin allows comments generated by the blog visitors to be imported as WordPress comments.</p>
<p>Some visitors prefer to post comments to Facebook Social Plugin as these comments are becoming part of their social activity and are displayed on their wall.</p>
<p>Other visitors prefer not to use Facebook comments. They would like to post their comments to your WordPress blog.</p>
<p>The Facebook Import Comments combines both type of plugins and makes them part of your WordPress blog.</p>
<p>Search Engine Optimization (SEO) benefits should also be considered. Your site will be more dynamic and more attractive for spiders. As a result it will rate higher in search engine results. According to Facebook SEO (Search Engine Optimization) community is the reason for extending the Facebook Social Plugin to be extended to provide an interface for retrieving the comments.</p>
<p><strong>Author:</strong> Ivan Georgiev<br />
<strong>Download:</strong> <a href="http://wordpress.org/extend/plugins/facebook-import-comments/" title="Facebook Import Comments WordPress Plugin v.0.2" rel="download">Download From  WordPress.org</a></p>
<p>See also:<br />
  * The <a href="faq-facebook-import-comments" title="Facebook Import Comments to WordPress plugin Frequently Asked Questions">Frequently Asked Questions</a> page.</p>
<h3>Changelog</h3</p>
<p>= 1.1 =<br />
* New Feature: Import Mode which allows "append new" and "append new and delete missing" synchronization modes.<br />
* Workaround: WordPress uses global variable $id. In some themes and plugins this variable is overwritten and the function get_the_ID() returns incorrect result.<br />
* Changed default language settings: "Retrieve blog locale = No", "Retrieve additional locales = ''". Facebook fixed their API so locale parameter is not anymore required when querying the Facebook comments.</p>
<p>= 1.0 =<br />
* Language options for Facebook connection.<br />
* Protect plugin directory from browsing.</p>
<p>= 0.2.1 =<br />
* Description changed to more distinguishable.</p>
<p>= 0.2 =<br />
* Refresh Interval to reduce bandwidth consumption.</li>
<p>* Administrative interface</li>
<p>* Refresh Interval can be changed through the administrative interface.</li>
<p>* All imported comments can be removed through the administrative interface.</li>
<p>* The administrative interface displays the number of currently imported comments.</li>
]]></content:encoded>
			<wfw:commentRss>http://devcorner.georgievi.net/pages/wordpress/wp-plugins/facebook-import-comments/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Oracle PL/SQL Collections and Associative Arrays</title>
		<link>http://devcorner.georgievi.net/pages/database/oracle_database/oracle_plsql/plsql_collections</link>
		<comments>http://devcorner.georgievi.net/pages/database/oracle_database/oracle_plsql/plsql_collections#comments</comments>
		<pubDate>Thu, 10 Dec 2009 13:56:07 +0000</pubDate>
		<dc:creator>baobab</dc:creator>
				<category><![CDATA[PL/SQL]]></category>
		<category><![CDATA[associative arrays]]></category>
		<category><![CDATA[collections]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[oracle database]]></category>
		<category><![CDATA[oracle plsql]]></category>

		<guid isPermaLink="false">http://devcorner.georgievi.net/?p=370</guid>
		<description><![CDATA[Associative Arrays

DECLARE
  TYPE population_type IS TABLE OF NUMBER INDEX BY VARCHAR2&#40;64&#41;;
  country_population population_type;
  continent_population population_type;
  howmany NUMBER;
  which VARCHAR2&#40;64&#41;;
&#160;
BEGIN
  country_population&#40;'Greenland'&#41; := 100000;
  country_population&#40;'Iceland'&#41; := 750000;
  howmany := country_population&#40;'Greenland'&#41;;
&#160;
  continent_population&#40;'Australia'&#41; := 30000000;
  continent_population&#40;'Antarctica'&#41; := 1000; -- Creates new entry
  continent_population&#40;'Antarctica'&#41; := 1001; -- Replaces previous [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Associative Arrays</strong></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">DECLARE
  TYPE population_type <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">TABLE</span> OF NUMBER <span style="color: #993333; font-weight: bold;">INDEX</span> <span style="color: #993333; font-weight: bold;">BY</span> VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">64</span><span style="color: #66cc66;">&#41;</span>;
  country_population population_type;
  continent_population population_type;
  howmany NUMBER;
  which VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">64</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
BEGIN
  country_population<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Greenland'</span><span style="color: #66cc66;">&#41;</span> :<span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">100000</span>;
  country_population<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Iceland'</span><span style="color: #66cc66;">&#41;</span> :<span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">750000</span>;
  howmany :<span style="color: #66cc66;">=</span> country_population<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Greenland'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  continent_population<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Australia'</span><span style="color: #66cc66;">&#41;</span> :<span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">30000000</span>;
  continent_population<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Antarctica'</span><span style="color: #66cc66;">&#41;</span> :<span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1000</span>; <span style="color: #808080; font-style: italic;">-- Creates new entry</span>
  continent_population<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Antarctica'</span><span style="color: #66cc66;">&#41;</span> :<span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1001</span>; <span style="color: #808080; font-style: italic;">-- Replaces previous value</span>
  dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Count: '</span> <span style="color: #66cc66;">||</span> continent_population<span style="color: #66cc66;">.</span>count<span style="color: #66cc66;">&#41;</span>;
&nbsp;
  which :<span style="color: #66cc66;">=</span> continent_population<span style="color: #66cc66;">.</span>FIRST; <span style="color: #808080; font-style: italic;">-- Returns 'Antarctica'</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- as that comes first alphabetically.</span>
  which :<span style="color: #66cc66;">=</span> continent_population<span style="color: #66cc66;">.</span>LAST; <span style="color: #808080; font-style: italic;">-- Returns 'Australia'</span>
  howmany :<span style="color: #66cc66;">=</span> continent_population<span style="color: #66cc66;">&#40;</span>continent_population<span style="color: #66cc66;">.</span>LAST<span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">-- Returns the value corresponding to the last key, in this</span>
<span style="color: #808080; font-style: italic;">-- case the population of Australia.</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Traverse Continents Associative Array</span>
  dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Elements in continent_population: '</span> <span style="color: #66cc66;">||</span> continent_population<span style="color: #66cc66;">.</span>count<span style="color: #66cc66;">&#41;</span>;
  which :<span style="color: #66cc66;">=</span> continent_population<span style="color: #66cc66;">.</span>FIRST;
  WHILE which <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> LOOP
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span>which <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">': '</span> <span style="color: #66cc66;">||</span> continent_population<span style="color: #66cc66;">&#40;</span>which<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
    which :<span style="color: #66cc66;">=</span> continent_population<span style="color: #66cc66;">.</span>NEXT<span style="color: #66cc66;">&#40;</span>which<span style="color: #66cc66;">&#41;</span>;
  END LOOP;
  <span style="color: #808080; font-style: italic;">-- Outputs:</span>
  <span style="color: #808080; font-style: italic;">--   Count: 2</span>
  <span style="color: #808080; font-style: italic;">--   Elements in continent_population: 2</span>
  <span style="color: #808080; font-style: italic;">--   Antarctica: 1001</span>
  <span style="color: #808080; font-style: italic;">--   Australia: 30000000</span>
&nbsp;
END;</pre></div></div>

<p><strong>Extend Oracle PL/SQL Collection</strong></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">DECLARE
  TYPE CourseList <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">TABLE</span> OF VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>;
  courses CourseList :<span style="color: #66cc66;">=</span> CourseList<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
BEGIN
  dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Initial count= '</span> <span style="color: #66cc66;">||</span> courses<span style="color: #66cc66;">.</span>count <span style="color: #66cc66;">||</span>
                       <span style="color: #ff0000;">', first= '</span> <span style="color: #66cc66;">||</span> courses<span style="color: #66cc66;">.</span>first <span style="color: #66cc66;">||</span>
                       <span style="color: #ff0000;">', last= '</span> <span style="color: #66cc66;">||</span> courses<span style="color: #66cc66;">.</span>last <span style="color: #66cc66;">||</span>
                       <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;
  courses<span style="color: #66cc66;">.</span>extend<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span>;
  dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'After extend(5) count= '</span> <span style="color: #66cc66;">||</span> courses<span style="color: #66cc66;">.</span>count <span style="color: #66cc66;">||</span>
                       <span style="color: #ff0000;">', first= '</span> <span style="color: #66cc66;">||</span> courses<span style="color: #66cc66;">.</span>first <span style="color: #66cc66;">||</span>
                       <span style="color: #ff0000;">', last= '</span> <span style="color: #66cc66;">||</span> courses<span style="color: #66cc66;">.</span>last <span style="color: #66cc66;">||</span>
                       <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;
  dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'After extend(5) count: '</span> <span style="color: #66cc66;">||</span> courses<span style="color: #66cc66;">.</span>count<span style="color: #66cc66;">&#41;</span>;
&nbsp;
END;</pre></div></div>

<pre>
Initial count= 0, first= , last=
After extend(5) count= 5, first= 1, last= 5
After extend(5) count: 5
</pre>
]]></content:encoded>
			<wfw:commentRss>http://devcorner.georgievi.net/pages/database/oracle_database/oracle_plsql/plsql_collections/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle Database Multitable INSERT SQL</title>
		<link>http://devcorner.georgievi.net/pages/database/oracle_database/oracle_sql/sql_insert/oracle-multitable-insert</link>
		<comments>http://devcorner.georgievi.net/pages/database/oracle_database/oracle_sql/sql_insert/oracle-multitable-insert#comments</comments>
		<pubDate>Thu, 10 Dec 2009 09:30:56 +0000</pubDate>
		<dc:creator>baobab</dc:creator>
				<category><![CDATA[SQL INSERT]]></category>
		<category><![CDATA[oracle database]]></category>
		<category><![CDATA[oracle sql]]></category>
		<category><![CDATA[oracle sql insert]]></category>

		<guid isPermaLink="false">http://devcorner.georgievi.net/?p=362</guid>
		<description><![CDATA[Multitable INSERT SQL can insert simultaneously into more than one tables. You can also specify optional conditions which determine which values are inserted into which tables.

SELECT * FROM sales_input_table;
&#160;
PRODUCT_ID CUSTOMER_ID WEEKLY_ST  SALES_SUN  SALES_MON  SALES_TUE  SALES_WED SALES_THU  SALES_FRI  SALES_SAT
---------- ----------- --------- ---------- ---------- ---------- -------------------- ---------- ----------
    [...]]]></description>
			<content:encoded><![CDATA[<p>Multitable INSERT SQL can insert simultaneously into more than one tables. You can also specify optional conditions which determine which values are inserted into which tables.<span id="more-362"></span></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> sales_input_table;
&nbsp;
PRODUCT_ID CUSTOMER_ID WEEKLY_ST  SALES_SUN  SALES_MON  SALES_TUE  SALES_WED SALES_THU  SALES_FRI  SALES_SAT
<span style="color: #808080; font-style: italic;">---------- ----------- --------- ---------- ---------- ---------- -------------------- ---------- ----------</span>
       <span style="color: #cc66cc;">111</span>         <span style="color: #cc66cc;">222</span> 01<span style="color: #66cc66;">-</span>OCT<span style="color: #66cc66;">-</span>00        <span style="color: #cc66cc;">100</span>        <span style="color: #cc66cc;">200</span>        <span style="color: #cc66cc;">300</span>        <span style="color: #cc66cc;">400</span>       <span style="color: #cc66cc;">500</span>        <span style="color: #cc66cc;">600</span>        <span style="color: #cc66cc;">700</span>
       <span style="color: #cc66cc;">222</span>         <span style="color: #cc66cc;">333</span> 08<span style="color: #66cc66;">-</span>OCT<span style="color: #66cc66;">-</span>00        <span style="color: #cc66cc;">200</span>        <span style="color: #cc66cc;">300</span>        <span style="color: #cc66cc;">400</span>        <span style="color: #cc66cc;">500</span>       <span style="color: #cc66cc;">600</span>        <span style="color: #cc66cc;">700</span>        <span style="color: #cc66cc;">800</span>
       <span style="color: #cc66cc;">333</span>         <span style="color: #cc66cc;">444</span> <span style="color: #cc66cc;">15</span><span style="color: #66cc66;">-</span>OCT<span style="color: #66cc66;">-</span>00        <span style="color: #cc66cc;">300</span>        <span style="color: #cc66cc;">400</span>        <span style="color: #cc66cc;">500</span>        <span style="color: #cc66cc;">600</span>       <span style="color: #cc66cc;">700</span>        <span style="color: #cc66cc;">800</span>        <span style="color: #cc66cc;">900</span></pre></div></div>

<p>The multitable insert statement looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">ALL</span>
      <span style="color: #993333; font-weight: bold;">INTO</span> sales <span style="color: #66cc66;">&#40;</span>prod_id<span style="color: #66cc66;">,</span> cust_id<span style="color: #66cc66;">,</span> time_id<span style="color: #66cc66;">,</span> amount<span style="color: #66cc66;">&#41;</span>
      <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span>product_id<span style="color: #66cc66;">,</span> customer_id<span style="color: #66cc66;">,</span> weekly_start_date<span style="color: #66cc66;">,</span> sales_sun<span style="color: #66cc66;">&#41;</span>
      <span style="color: #993333; font-weight: bold;">INTO</span> sales <span style="color: #66cc66;">&#40;</span>prod_id<span style="color: #66cc66;">,</span> cust_id<span style="color: #66cc66;">,</span> time_id<span style="color: #66cc66;">,</span> amount<span style="color: #66cc66;">&#41;</span>
      <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span>product_id<span style="color: #66cc66;">,</span> customer_id<span style="color: #66cc66;">,</span> weekly_start_date<span style="color: #66cc66;">+</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> sales_mon<span style="color: #66cc66;">&#41;</span>
      <span style="color: #993333; font-weight: bold;">INTO</span> sales <span style="color: #66cc66;">&#40;</span>prod_id<span style="color: #66cc66;">,</span> cust_id<span style="color: #66cc66;">,</span> time_id<span style="color: #66cc66;">,</span> amount<span style="color: #66cc66;">&#41;</span>
      <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span>product_id<span style="color: #66cc66;">,</span> customer_id<span style="color: #66cc66;">,</span> weekly_start_date<span style="color: #66cc66;">+</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span> sales_tue<span style="color: #66cc66;">&#41;</span>
      <span style="color: #993333; font-weight: bold;">INTO</span> sales <span style="color: #66cc66;">&#40;</span>prod_id<span style="color: #66cc66;">,</span> cust_id<span style="color: #66cc66;">,</span> time_id<span style="color: #66cc66;">,</span> amount<span style="color: #66cc66;">&#41;</span>
      <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span>product_id<span style="color: #66cc66;">,</span> customer_id<span style="color: #66cc66;">,</span> weekly_start_date<span style="color: #66cc66;">+</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">,</span> sales_wed<span style="color: #66cc66;">&#41;</span>
      <span style="color: #993333; font-weight: bold;">INTO</span> sales <span style="color: #66cc66;">&#40;</span>prod_id<span style="color: #66cc66;">,</span> cust_id<span style="color: #66cc66;">,</span> time_id<span style="color: #66cc66;">,</span> amount<span style="color: #66cc66;">&#41;</span>
      <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span>product_id<span style="color: #66cc66;">,</span> customer_id<span style="color: #66cc66;">,</span> weekly_start_date<span style="color: #66cc66;">+</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">,</span> sales_thu<span style="color: #66cc66;">&#41;</span>
      <span style="color: #993333; font-weight: bold;">INTO</span> sales <span style="color: #66cc66;">&#40;</span>prod_id<span style="color: #66cc66;">,</span> cust_id<span style="color: #66cc66;">,</span> time_id<span style="color: #66cc66;">,</span> amount<span style="color: #66cc66;">&#41;</span>
      <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span>product_id<span style="color: #66cc66;">,</span> customer_id<span style="color: #66cc66;">,</span> weekly_start_date<span style="color: #66cc66;">+</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">,</span> sales_fri<span style="color: #66cc66;">&#41;</span>
      <span style="color: #993333; font-weight: bold;">INTO</span> sales <span style="color: #66cc66;">&#40;</span>prod_id<span style="color: #66cc66;">,</span> cust_id<span style="color: #66cc66;">,</span> time_id<span style="color: #66cc66;">,</span> amount<span style="color: #66cc66;">&#41;</span>
      <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span>product_id<span style="color: #66cc66;">,</span> customer_id<span style="color: #66cc66;">,</span> weekly_start_date<span style="color: #66cc66;">+</span><span style="color: #cc66cc;">6</span><span style="color: #66cc66;">,</span> sales_sat<span style="color: #66cc66;">&#41;</span>
   <span style="color: #993333; font-weight: bold;">SELECT</span> product_id<span style="color: #66cc66;">,</span> customer_id<span style="color: #66cc66;">,</span> weekly_start_date<span style="color: #66cc66;">,</span> sales_sun<span style="color: #66cc66;">,</span>
      sales_mon<span style="color: #66cc66;">,</span> sales_tue<span style="color: #66cc66;">,</span> sales_wed<span style="color: #66cc66;">,</span> sales_thu<span style="color: #66cc66;">,</span> sales_fri<span style="color: #66cc66;">,</span> sales_sat
      <span style="color: #993333; font-weight: bold;">FROM</span> sales_input_table;</pre></div></div>

<p>Assuming these are the only rows in the sales table, the contents now look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> sales
   <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> prod_id<span style="color: #66cc66;">,</span> cust_id<span style="color: #66cc66;">,</span> time_id;
&nbsp;
   PROD_ID    CUST_ID TIME_ID   C   PROMO_ID QUANTITY_SOLD     AMOUNT       COST
<span style="color: #808080; font-style: italic;">---------- ---------- --------- - ---------- ------------- ---------- ----------</span>
       <span style="color: #cc66cc;">111</span>        <span style="color: #cc66cc;">222</span> 01<span style="color: #66cc66;">-</span>OCT<span style="color: #66cc66;">-</span>00                                   <span style="color: #cc66cc;">100</span>
       <span style="color: #cc66cc;">111</span>        <span style="color: #cc66cc;">222</span> 02<span style="color: #66cc66;">-</span>OCT<span style="color: #66cc66;">-</span>00                                   <span style="color: #cc66cc;">200</span>
       <span style="color: #cc66cc;">111</span>        <span style="color: #cc66cc;">222</span> 03<span style="color: #66cc66;">-</span>OCT<span style="color: #66cc66;">-</span>00                                   <span style="color: #cc66cc;">300</span>
       <span style="color: #cc66cc;">111</span>        <span style="color: #cc66cc;">222</span> 04<span style="color: #66cc66;">-</span>OCT<span style="color: #66cc66;">-</span>00                                   <span style="color: #cc66cc;">400</span>
       <span style="color: #cc66cc;">111</span>        <span style="color: #cc66cc;">222</span> 05<span style="color: #66cc66;">-</span>OCT<span style="color: #66cc66;">-</span>00                                   <span style="color: #cc66cc;">500</span>
       <span style="color: #cc66cc;">111</span>        <span style="color: #cc66cc;">222</span> 06<span style="color: #66cc66;">-</span>OCT<span style="color: #66cc66;">-</span>00                                   <span style="color: #cc66cc;">600</span>
       <span style="color: #cc66cc;">111</span>        <span style="color: #cc66cc;">222</span> 07<span style="color: #66cc66;">-</span>OCT<span style="color: #66cc66;">-</span>00                                   <span style="color: #cc66cc;">700</span>
       <span style="color: #cc66cc;">222</span>        <span style="color: #cc66cc;">333</span> 08<span style="color: #66cc66;">-</span>OCT<span style="color: #66cc66;">-</span>00                                   <span style="color: #cc66cc;">200</span>
       <span style="color: #cc66cc;">222</span>        <span style="color: #cc66cc;">333</span> 09<span style="color: #66cc66;">-</span>OCT<span style="color: #66cc66;">-</span>00                                   <span style="color: #cc66cc;">300</span>
       <span style="color: #cc66cc;">222</span>        <span style="color: #cc66cc;">333</span> <span style="color: #cc66cc;">10</span><span style="color: #66cc66;">-</span>OCT<span style="color: #66cc66;">-</span>00                                   <span style="color: #cc66cc;">400</span>
       <span style="color: #cc66cc;">222</span>        <span style="color: #cc66cc;">333</span> <span style="color: #cc66cc;">11</span><span style="color: #66cc66;">-</span>OCT<span style="color: #66cc66;">-</span>00                                   <span style="color: #cc66cc;">500</span>
       <span style="color: #cc66cc;">222</span>        <span style="color: #cc66cc;">333</span> <span style="color: #cc66cc;">12</span><span style="color: #66cc66;">-</span>OCT<span style="color: #66cc66;">-</span>00                                   <span style="color: #cc66cc;">600</span>
       <span style="color: #cc66cc;">222</span>        <span style="color: #cc66cc;">333</span> <span style="color: #cc66cc;">13</span><span style="color: #66cc66;">-</span>OCT<span style="color: #66cc66;">-</span>00                                   <span style="color: #cc66cc;">700</span>
       <span style="color: #cc66cc;">222</span>        <span style="color: #cc66cc;">333</span> <span style="color: #cc66cc;">14</span><span style="color: #66cc66;">-</span>OCT<span style="color: #66cc66;">-</span>00                                   <span style="color: #cc66cc;">800</span>
       <span style="color: #cc66cc;">333</span>        <span style="color: #cc66cc;">444</span> <span style="color: #cc66cc;">15</span><span style="color: #66cc66;">-</span>OCT<span style="color: #66cc66;">-</span>00                                   <span style="color: #cc66cc;">300</span>
       <span style="color: #cc66cc;">333</span>        <span style="color: #cc66cc;">444</span> <span style="color: #cc66cc;">16</span><span style="color: #66cc66;">-</span>OCT<span style="color: #66cc66;">-</span>00                                   <span style="color: #cc66cc;">400</span>
       <span style="color: #cc66cc;">333</span>        <span style="color: #cc66cc;">444</span> <span style="color: #cc66cc;">17</span><span style="color: #66cc66;">-</span>OCT<span style="color: #66cc66;">-</span>00                                   <span style="color: #cc66cc;">500</span>
       <span style="color: #cc66cc;">333</span>        <span style="color: #cc66cc;">444</span> <span style="color: #cc66cc;">18</span><span style="color: #66cc66;">-</span>OCT<span style="color: #66cc66;">-</span>00                                   <span style="color: #cc66cc;">600</span>
       <span style="color: #cc66cc;">333</span>        <span style="color: #cc66cc;">444</span> <span style="color: #cc66cc;">19</span><span style="color: #66cc66;">-</span>OCT<span style="color: #66cc66;">-</span>00                                   <span style="color: #cc66cc;">700</span>
       <span style="color: #cc66cc;">333</span>        <span style="color: #cc66cc;">444</span> <span style="color: #cc66cc;">20</span><span style="color: #66cc66;">-</span>OCT<span style="color: #66cc66;">-</span>00                                   <span style="color: #cc66cc;">800</span>
       <span style="color: #cc66cc;">333</span>        <span style="color: #cc66cc;">444</span> <span style="color: #cc66cc;">21</span><span style="color: #66cc66;">-</span>OCT<span style="color: #66cc66;">-</span>00                                   <span style="color: #cc66cc;">900</span></pre></div></div>

<p>The next examples insert into multiple tables. Suppose you want to provide to sales representatives some information on orders of various sizes. The following example creates tables for small, medium, large, and special orders and populates those tables with data from the sample table oe.orders:</p>
<pre>
CREATE TABLE small_orders
   (order_id       NUMBER(12)   NOT NULL,
    customer_id    NUMBER(6)    NOT NULL,
    order_total    NUMBER(8,2),
    sales_rep_id   NUMBER(6)
   );

CREATE TABLE medium_orders AS SELECT * FROM small_orders;

CREATE TABLE large_orders AS SELECT * FROM small_orders;

CREATE TABLE special_orders
   (order_id       NUMBER(12)    NOT NULL,
    customer_id    NUMBER(6)     NOT NULL,
    order_total    NUMBER(8,2),
    sales_rep_id   NUMBER(6),
    credit_limit   NUMBER(9,2),
    cust_email     VARCHAR2(30)
   );
</pre>
<p>The first multitable insert populates only the tables for small, medium, and large orders:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">ALL</span>
   WHEN order_total <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">1000000</span> THEN
      <span style="color: #993333; font-weight: bold;">INTO</span> small_orders
   WHEN order_total <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">1000000</span> <span style="color: #993333; font-weight: bold;">AND</span> order_total <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">2000000</span> THEN
      <span style="color: #993333; font-weight: bold;">INTO</span> medium_orders
   WHEN order_total <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">2000000</span> THEN
      <span style="color: #993333; font-weight: bold;">INTO</span> large_orders
   <span style="color: #993333; font-weight: bold;">SELECT</span> order_id<span style="color: #66cc66;">,</span> order_total<span style="color: #66cc66;">,</span> sales_rep_id<span style="color: #66cc66;">,</span> customer_id
      <span style="color: #993333; font-weight: bold;">FROM</span> orders;</pre></div></div>

<p>You can accomplish the same thing using the ELSE clause in place of the insert into the large_orders table:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">ALL</span>
   WHEN order_total <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">100000</span> THEN
      <span style="color: #993333; font-weight: bold;">INTO</span> small_orders
   WHEN order_total <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">100000</span> <span style="color: #993333; font-weight: bold;">AND</span> order_total <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">200000</span> THEN
      <span style="color: #993333; font-weight: bold;">INTO</span> medium_orders
   ELSE
      <span style="color: #993333; font-weight: bold;">INTO</span> large_orders
   <span style="color: #993333; font-weight: bold;">SELECT</span> order_id<span style="color: #66cc66;">,</span> order_total<span style="color: #66cc66;">,</span> sales_rep_id<span style="color: #66cc66;">,</span> customer_id
      <span style="color: #993333; font-weight: bold;">FROM</span> orders;
<span style="color: #66cc66;">&lt;</span>pre<span style="color: #66cc66;">&gt;</span>
&nbsp;
The next example inserts <span style="color: #993333; font-weight: bold;">INTO</span> the small<span style="color: #66cc66;">,</span> medium<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">AND</span> large <span style="color: #993333; font-weight: bold;">TABLES</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">IN</span> the preceding example<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">AND</span> also puts orders greater than <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">900</span><span style="color: #66cc66;">,</span>000 <span style="color: #993333; font-weight: bold;">INTO</span> the special_orders <span style="color: #993333; font-weight: bold;">TABLE</span><span style="color: #66cc66;">.</span> This <span style="color: #993333; font-weight: bold;">TABLE</span> also shows how <span style="color: #993333; font-weight: bold;">TO</span> <span style="color: #993333; font-weight: bold;">USE</span> <span style="color: #993333; font-weight: bold;">COLUMN</span> aliases <span style="color: #993333; font-weight: bold;">TO</span> simplify the statement:
&nbsp;
<span style="color: #66cc66;">&lt;</span>pre lang<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sql&quot;</span><span style="color: #66cc66;">&gt;</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">ALL</span>
   WHEN ottl <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">100000</span> THEN
      <span style="color: #993333; font-weight: bold;">INTO</span> small_orders
         <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span>oid<span style="color: #66cc66;">,</span> ottl<span style="color: #66cc66;">,</span> sid<span style="color: #66cc66;">,</span> cid<span style="color: #66cc66;">&#41;</span>
   WHEN ottl <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">100000</span> <span style="color: #993333; font-weight: bold;">AND</span> ottl <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">200000</span> THEN
      <span style="color: #993333; font-weight: bold;">INTO</span> medium_orders 
         <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span>oid<span style="color: #66cc66;">,</span> ottl<span style="color: #66cc66;">,</span> sid<span style="color: #66cc66;">,</span> cid<span style="color: #66cc66;">&#41;</span>
   WHEN ottl <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">200000</span> THEN
      <span style="color: #993333; font-weight: bold;">INTO</span> large_orders
         <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span>oid<span style="color: #66cc66;">,</span> ottl<span style="color: #66cc66;">,</span> sid<span style="color: #66cc66;">,</span> cid<span style="color: #66cc66;">&#41;</span>
   WHEN ottl <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">290000</span> THEN
      <span style="color: #993333; font-weight: bold;">INTO</span> special_orders
   <span style="color: #993333; font-weight: bold;">SELECT</span> o<span style="color: #66cc66;">.</span>order_id oid<span style="color: #66cc66;">,</span> o<span style="color: #66cc66;">.</span>customer_id cid<span style="color: #66cc66;">,</span> o<span style="color: #66cc66;">.</span>order_total ottl<span style="color: #66cc66;">,</span>
      o<span style="color: #66cc66;">.</span>sales_rep_id sid<span style="color: #66cc66;">,</span> c<span style="color: #66cc66;">.</span>credit_limit cl<span style="color: #66cc66;">,</span> c<span style="color: #66cc66;">.</span>cust_email cem
      <span style="color: #993333; font-weight: bold;">FROM</span> orders o<span style="color: #66cc66;">,</span> customers c
      <span style="color: #993333; font-weight: bold;">WHERE</span> o<span style="color: #66cc66;">.</span>customer_id <span style="color: #66cc66;">=</span> c<span style="color: #66cc66;">.</span>customer_id;</pre></div></div>

<p>Finally, the next example uses the FIRST clause to put orders greater than 2,900,000 into the special_orders table and exclude those orders from the large_orders table:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> FIRST
   WHEN ottl <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">100000</span> THEN
      <span style="color: #993333; font-weight: bold;">INTO</span> small_orders
         <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span>oid<span style="color: #66cc66;">,</span> ottl<span style="color: #66cc66;">,</span> sid<span style="color: #66cc66;">,</span> cid<span style="color: #66cc66;">&#41;</span>
   WHEN ottl <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">100000</span> <span style="color: #993333; font-weight: bold;">AND</span> ottl <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">200000</span> THEN
      <span style="color: #993333; font-weight: bold;">INTO</span> medium_orders
         <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span>oid<span style="color: #66cc66;">,</span> ottl<span style="color: #66cc66;">,</span> sid<span style="color: #66cc66;">,</span> cid<span style="color: #66cc66;">&#41;</span>
   WHEN ottl <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">290000</span> THEN
      <span style="color: #993333; font-weight: bold;">INTO</span> special_orders
   WHEN ottl <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">200000</span> THEN
      <span style="color: #993333; font-weight: bold;">INTO</span> large_orders
         <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span>oid<span style="color: #66cc66;">,</span> ottl<span style="color: #66cc66;">,</span> sid<span style="color: #66cc66;">,</span> cid<span style="color: #66cc66;">&#41;</span>
   <span style="color: #993333; font-weight: bold;">SELECT</span> o<span style="color: #66cc66;">.</span>order_id oid<span style="color: #66cc66;">,</span> o<span style="color: #66cc66;">.</span>customer_id cid<span style="color: #66cc66;">,</span> o<span style="color: #66cc66;">.</span>order_total ottl<span style="color: #66cc66;">,</span>
      o<span style="color: #66cc66;">.</span>sales_rep_id sid<span style="color: #66cc66;">,</span> c<span style="color: #66cc66;">.</span>credit_limit cl<span style="color: #66cc66;">,</span> c<span style="color: #66cc66;">.</span>cust_email cem
      <span style="color: #993333; font-weight: bold;">FROM</span> orders o<span style="color: #66cc66;">,</span> customers c
      <span style="color: #993333; font-weight: bold;">WHERE</span> o<span style="color: #66cc66;">.</span>customer_id <span style="color: #66cc66;">=</span> c<span style="color: #66cc66;">.</span>customer_id;</pre></div></div>

<p><strong>Oracle Multi-table Insert Syntax</strong></p>
<pre>

INSERT [hint]
   {
      ALL insert_into_clause [values_clause] [error_logging_clause]
            [insert_into_clause [values_clause] [error_logging_clause]]...
      |
      conditional_insert_clause
   }

conditional_insert_clause ::=
   [ALL | FIRST]
   WHEN condition
      THEN
	     insert_into_clause
            [ values_clause ]
            [ error_logging_clause ]
         [ insert_into_clause
            [ values_clause ]
            [ error_logging_clause ]
         ]...
   [ WHEN condition
      THEN
	     insert_into_clause
            [ values_clause ]
            [ error_logging_clause ]
         [ insert_into_clause
            [ values_clause ]
            [ error_logging_clause ]
         ]...
   ]...

   [ ELSE insert_into_clause
      [ values_clause ]
         [ error_logging_clause ]
      [ insert_into_clause
         [ values_clause ]
         [ error_logging_clause ]
      ]...
   ]

insert_into_clause :=
   INTO dml_table_expression_clause [ t_alias ]
      [ (column [, column ]...) ]

values_clause :=
   VALUES ({ expr | DEFAULT }
      [, { expr | DEFAULT } ]...
   )
</pre>
]]></content:encoded>
			<wfw:commentRss>http://devcorner.georgievi.net/pages/database/oracle_database/oracle_sql/sql_insert/oracle-multitable-insert/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Find SQL Executed by a Session &#8211; Oracle</title>
		<link>http://devcorner.georgievi.net/pages/database/oracle_database/oracle_dba/session-sql</link>
		<comments>http://devcorner.georgievi.net/pages/database/oracle_database/oracle_dba/session-sql#comments</comments>
		<pubDate>Tue, 08 Dec 2009 13:32:07 +0000</pubDate>
		<dc:creator>baobab</dc:creator>
				<category><![CDATA[Oracle DBA (Database Administration)]]></category>

		<guid isPermaLink="false">http://devcorner.georgievi.net/?p=359</guid>
		<description><![CDATA[The following SQL shows the SQL text for the SQL being executed by a session.

SELECT s.sid,
       q.sql_text
  FROM v$sqltext q
       JOIN v$session s ON q.address = s.sql_address
 WHERE s.sid = &#38;sid
 ORDER BY piece;

]]></description>
			<content:encoded><![CDATA[<p>The following SQL shows the SQL text for the SQL being executed by a session.<span id="more-359"></span></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> s<span style="color: #66cc66;">.</span>sid<span style="color: #66cc66;">,</span>
       q<span style="color: #66cc66;">.</span>sql_text
  <span style="color: #993333; font-weight: bold;">FROM</span> v$sqltext q
       <span style="color: #993333; font-weight: bold;">JOIN</span> v$session s <span style="color: #993333; font-weight: bold;">ON</span> q<span style="color: #66cc66;">.</span>address <span style="color: #66cc66;">=</span> s<span style="color: #66cc66;">.</span>sql_address
 <span style="color: #993333; font-weight: bold;">WHERE</span> s<span style="color: #66cc66;">.</span>sid <span style="color: #66cc66;">=</span> &amp;sid
 <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> piece;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://devcorner.georgievi.net/pages/database/oracle_database/oracle_dba/session-sql/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Show the Longest 10 Active User Sessions</title>
		<link>http://devcorner.georgievi.net/pages/database/oracle_database/oracle_dba/10-longest-active-oracle</link>
		<comments>http://devcorner.georgievi.net/pages/database/oracle_database/oracle_dba/10-longest-active-oracle#comments</comments>
		<pubDate>Mon, 07 Dec 2009 13:34:54 +0000</pubDate>
		<dc:creator>baobab</dc:creator>
				<category><![CDATA[Oracle DBA (Database Administration)]]></category>
		<category><![CDATA[dba]]></category>
		<category><![CDATA[dba sql]]></category>
		<category><![CDATA[oracle database]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">http://devcorner.georgievi.net/?p=352</guid>
		<description><![CDATA[The following SQL can be used by Oracle Database Administrator (DBA) to retrieve information about the currently active sessions with longest execution. The SQL statement is designed to run with SQL*Plus.
To show a list with top current sessions with longest acivity execute in SQL*Plus:

/*
  longest10active.sqlplus.sql
  shows the top 10 active sessions with longest [...]]]></description>
			<content:encoded><![CDATA[<p>The following SQL can be used by Oracle Database Administrator (DBA) to retrieve information about the currently active sessions with longest execution. The SQL statement is designed to run with SQL*Plus.<span id="more-352"></span></p>
<p>To show a list with top current sessions with longest acivity execute in SQL*Plus:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*
  longest10active.sqlplus.sql
  shows the top 10 active sessions with longest execution activity
  execute in SQL*Plus
*/</span>
col osuser format a10 trunc
col LastCallET format <span style="color: #cc66cc;">99</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">999</span>
col sid format <span style="color: #cc66cc;">9999</span>
col spid formar <span style="color: #cc66cc;">999999</span>
col username format a10 trunc
col uprogram format a25 trunc
col machine format a10 trunc
<span style="color: #993333; font-weight: bold;">SET</span> linesize <span style="color: #cc66cc;">132</span>
<span style="color: #993333; font-weight: bold;">SET</span> verify off
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #66cc66;">&#40;</span>
   <span style="color: #993333; font-weight: bold;">SELECT</span> TO_CHAR<span style="color: #66cc66;">&#40;</span>s<span style="color: #66cc66;">.</span>logon_time<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'mm/dd hh:mi:ssAM'</span><span style="color: #66cc66;">&#41;</span> loggedon<span style="color: #66cc66;">,</span>
          s<span style="color: #66cc66;">.</span>sid<span style="color: #66cc66;">,</span> s<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">STATUS</span><span style="color: #66cc66;">,</span>
          floor<span style="color: #66cc66;">&#40;</span>last_call_et<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">60</span><span style="color: #66cc66;">&#41;</span> <span style="color: #ff0000;">&quot;LastCallET&quot;</span><span style="color: #66cc66;">,</span>
          s<span style="color: #66cc66;">.</span>username<span style="color: #66cc66;">,</span> s<span style="color: #66cc66;">.</span>osuser<span style="color: #66cc66;">,</span>
          p<span style="color: #66cc66;">.</span>spid<span style="color: #66cc66;">,</span> s<span style="color: #66cc66;">.</span>module <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">' - '</span> <span style="color: #66cc66;">||</span> s<span style="color: #66cc66;">.</span>program uprogram<span style="color: #66cc66;">,</span>
          s<span style="color: #66cc66;">.</span>machine<span style="color: #66cc66;">,</span> s<span style="color: #66cc66;">.</span>sql_hash_value
     <span style="color: #993333; font-weight: bold;">FROM</span> v$session s<span style="color: #66cc66;">,</span> v$process p
    <span style="color: #993333; font-weight: bold;">WHERE</span> p<span style="color: #66cc66;">.</span>addr <span style="color: #66cc66;">=</span> s<span style="color: #66cc66;">.</span>paddr
          <span style="color: #993333; font-weight: bold;">AND</span> s<span style="color: #66cc66;">.</span>type <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'USER'</span>
          <span style="color: #993333; font-weight: bold;">AND</span> module <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>
          <span style="color: #993333; font-weight: bold;">AND</span> s<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">STATUS</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'ACTIVE'</span>
    <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #cc66cc;">4</span> <span style="color: #993333; font-weight: bold;">DESC</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">WHERE</span> ROWNUM <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">11</span>;</pre></div></div>

<p>If you want the execute the statement in different tool, you can remove the formatting clauses:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*
  longest10active.sql
  shows the top 10 active sessions with longest execution activity
*/</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #66cc66;">&#40;</span>
   <span style="color: #993333; font-weight: bold;">SELECT</span> TO_CHAR<span style="color: #66cc66;">&#40;</span>s<span style="color: #66cc66;">.</span>logon_time<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'mm/dd hh:mi:ssAM'</span><span style="color: #66cc66;">&#41;</span> loggedon<span style="color: #66cc66;">,</span>
          s<span style="color: #66cc66;">.</span>sid<span style="color: #66cc66;">,</span> s<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">STATUS</span><span style="color: #66cc66;">,</span>
          floor<span style="color: #66cc66;">&#40;</span>last_call_et<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">60</span><span style="color: #66cc66;">&#41;</span> <span style="color: #ff0000;">&quot;LastCallET&quot;</span><span style="color: #66cc66;">,</span>
          s<span style="color: #66cc66;">.</span>username<span style="color: #66cc66;">,</span> s<span style="color: #66cc66;">.</span>osuser<span style="color: #66cc66;">,</span>
          p<span style="color: #66cc66;">.</span>spid<span style="color: #66cc66;">,</span> s<span style="color: #66cc66;">.</span>module <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">' - '</span> <span style="color: #66cc66;">||</span> s<span style="color: #66cc66;">.</span>program uprogram<span style="color: #66cc66;">,</span>
          s<span style="color: #66cc66;">.</span>machine<span style="color: #66cc66;">,</span> s<span style="color: #66cc66;">.</span>sql_hash_value
     <span style="color: #993333; font-weight: bold;">FROM</span> v$session s<span style="color: #66cc66;">,</span> v$process p
    <span style="color: #993333; font-weight: bold;">WHERE</span> p<span style="color: #66cc66;">.</span>addr <span style="color: #66cc66;">=</span> s<span style="color: #66cc66;">.</span>paddr
          <span style="color: #993333; font-weight: bold;">AND</span> s<span style="color: #66cc66;">.</span>type <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'USER'</span>
          <span style="color: #993333; font-weight: bold;">AND</span> module <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>
          <span style="color: #993333; font-weight: bold;">AND</span> s<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">STATUS</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'ACTIVE'</span>
    <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #cc66cc;">4</span> <span style="color: #993333; font-weight: bold;">DESC</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">WHERE</span> ROWNUM <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">11</span>;</pre></div></div>

<h2>References</h2>
<ul>
<li><a href="http://allappsdba.blogspot.com/2009/04/show-top-10-longest-active-user.html">Oracle Applications World: Show the top 10 longest-active user sessions</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://devcorner.georgievi.net/pages/database/oracle_database/oracle_dba/10-longest-active-oracle/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

