<?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>AppCrawler</title>
	<atom:link href="http://appcrawler.com/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://appcrawler.com/wordpress</link>
	<description>Tying data to business excellence</description>
	<lastBuildDate>Tue, 21 Feb 2012 13:41:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Change the mount point for an ACFS filesystem</title>
		<link>http://appcrawler.com/wordpress/2012/02/21/change-the-mount-point-for-an-acfs-filesystem/</link>
		<comments>http://appcrawler.com/wordpress/2012/02/21/change-the-mount-point-for-an-acfs-filesystem/#comments</comments>
		<pubDate>Tue, 21 Feb 2012 13:41:37 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://appcrawler.com/wordpress/?p=1903</guid>
		<description><![CDATA[Changing the mount point for an ACFS filesystem is not a straightforward process, and is not a well documented process. We found ourselves in this position after we misspelled the goldengate directory we wanted to use for the binaries and trail files in a RAC. We erroneously spelled it goldendate. We tried to use asmcmd [...]]]></description>
			<content:encoded><![CDATA[<p>Changing the mount point for an ACFS filesystem is not a straightforward process, and is not a well documented process.  We found ourselves in this position after we misspelled the goldengate directory we wanted to use for the binaries and trail files in a RAC.</p>
<p>We erroneously spelled it goldendate.  We tried to use asmcmd volset which changed it temporarily, but our changes were lost after a reboot.  After fishing around for several hours, we found what is below, and thought it may be useful to someone else.</p>
<p>You need to use the acfsutil executable, which was nowhere to be found other than under an install directory.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">expressdb1:oracle:ecomm1:/u01/app/11.2.0# ./grid/install/usm/cmds/bin/acfsutil registry -l
Device : /dev/asm/volume1-104 : Mount Point : /u01/app/oracle/acfsdata/goldendate : Options : none : Nodes : all : Disk Group : DATA : Volume : VOLUME1
expressdb1:oracle:ecomm1:/u01/app/11.2.0# ./grid/install/usm/cmds/bin/acfsutil registry -d /dev/asm/volume1-104
acfsutil registry: successfully removed ACFS volume /dev/asm/volume1-104 from Oracle Registry
expressdb1:oracle:ecomm1:/u01/app/11.2.0# ./grid/install/usm/cmds/bin/acfsutil registry -a /dev/asm/volume1-104 /u01/app/oracle/acfsdata/goldengate/
acfsutil registry: mount point /u01/app/oracle/acfsdata/goldengate successfully added to Oracle Registry
expressdb1:oracle:ecomm1:/u01/app/11.2.0#</pre></div></div>

<p>You can then either:</p>
<p>restart each node, which will result in ACFS filesystem being mounted on the new location found in the cluster registry</p>
<p>-or-</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">umount the_current_location
mount -t acfs /dev/asm/volume-&lt;###&gt; /new_location</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://appcrawler.com/wordpress/2012/02/21/change-the-mount-point-for-an-acfs-filesystem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux firewall rules for RAC</title>
		<link>http://appcrawler.com/wordpress/2012/02/18/linux-firewall-rules-for-rac/</link>
		<comments>http://appcrawler.com/wordpress/2012/02/18/linux-firewall-rules-for-rac/#comments</comments>
		<pubDate>Sat, 18 Feb 2012 14:38:15 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[RAC]]></category>

		<guid isPermaLink="false">http://appcrawler.com/wordpress/?p=1896</guid>
		<description><![CDATA[Most notes on the Oracle MOS support site suggest disabling the firewall supplied in most Linux distros as managed by the iptables program. I think this is a bit drastic, and results in lazy thinking at best, and an exposed database server subject to all sorts of hacker invasion at worst. If you don&#8217;t want [...]]]></description>
			<content:encoded><![CDATA[<p>Most notes on the Oracle MOS support site suggest disabling the firewall supplied in most Linux distros as managed by the iptables program.  I think this is a bit drastic, and results in lazy thinking at best, and an exposed database server subject to all sorts of hacker invasion at worst.</p>
<p>If you don&#8217;t want to understand every nuance of Linux firewalls, but do want to at least not completely disable it, the easiest fix is to add a simple rule to your iptables configuration on each server in the cluster.</p>
<p>As root:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">vi /etc/sysconfig/iptables</pre></div></div>

<p>add the following line before any REJECT rules, changing eth1 to whatever your private interface is</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">-A RH-Firewall-1-INPUT -p udp -i eth1 -j ACCEPT</pre></div></div>

<p>Restart the firewall</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">service iptables restart
iptables -nvL</pre></div></div>

<p>You should see a line with increasing packet activity for the UDP protocol on your private network interface.</p>
<p>This leaves all other firewall rules in place, and allows only UDP traffic on the private interface.</p>
]]></content:encoded>
			<wfw:commentRss>http://appcrawler.com/wordpress/2012/02/18/linux-firewall-rules-for-rac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Query SQL Server stored procedure text with JDBC</title>
		<link>http://appcrawler.com/wordpress/2012/02/08/query-sql-server-stored-procdure-text-with-jdbc/</link>
		<comments>http://appcrawler.com/wordpress/2012/02/08/query-sql-server-stored-procdure-text-with-jdbc/#comments</comments>
		<pubDate>Wed, 08 Feb 2012 14:30:49 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://appcrawler.com/wordpress/?p=1888</guid>
		<description><![CDATA[I needed to quickly print the text associated with several stored procedures across multiple database servers to individual files. I used what is below. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to quickly print the text associated with several stored procedures across multiple database servers to individual files.  I used what is below.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.microsoft.sqlserver.jdbc.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.*</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> sqlProcedures <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> hosts <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;host1&quot;</span>,<span style="color: #0000ff;">&quot;host2&quot;</span>,<span style="color: #0000ff;">&quot;host3&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> hosts.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #003399;">String</span> connString <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;jdbc:sqlserver://&quot;</span> <span style="color: #339933;">+</span> hosts<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;:1433;&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">Connection</span> con <span style="color: #339933;">=</span> <span style="color: #003399;">DriverManager</span>.<span style="color: #006633;">getConnection</span><span style="color: #009900;">&#40;</span>connString <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;databaseName=dbaDB;integratedSecurity=true;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">PreparedStatement</span> stm <span style="color: #339933;">=</span> con.<span style="color: #006633;">prepareCall</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;select name,id from sysobjects where name like 'dbasp%' order by 1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">ResultSet</span> rst <span style="color: #339933;">=</span> stm.<span style="color: #006633;">executeQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003399;">PreparedStatement</span> stm2 <span style="color: #339933;">=</span> con.<span style="color: #006633;">prepareCall</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;select text from syscomments where id = ?&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>rst.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #003399;">BufferedWriter</span> out <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedWriter</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">FileWriter</span><span style="color: #009900;">&#40;</span>hosts<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;_&quot;</span> <span style="color: #339933;">+</span> rst.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;.sql&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          stm2.<span style="color: #006633;">setInt</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span>,rst.<span style="color: #006633;">getInt</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>          
          <span style="color: #003399;">ResultSet</span> rst2 <span style="color: #339933;">=</span> stm2.<span style="color: #006633;">executeQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>rst2.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            out.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>rst2.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
          out.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://appcrawler.com/wordpress/2012/02/08/query-sql-server-stored-procdure-text-with-jdbc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Poor man’s partitioning with instead of triggers &#8211; PART 1</title>
		<link>http://appcrawler.com/wordpress/2012/02/07/poor-man%e2%80%99s-partitioning-with-instead-of-triggers-part-1/</link>
		<comments>http://appcrawler.com/wordpress/2012/02/07/poor-man%e2%80%99s-partitioning-with-instead-of-triggers-part-1/#comments</comments>
		<pubDate>Tue, 07 Feb 2012 17:40:35 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PL/SQL]]></category>

		<guid isPermaLink="false">http://appcrawler.com/wordpress/?p=1807</guid>
		<description><![CDATA[The Enterprise Edition of Oracle Corp’s. flagship database has many features. One of these is partitioning. Partitioning allows a user to segment table rows into separate physical storage structures. This can improve things such as performance and manageability. Performance can be improved by utilizing what Oracle terms “partition pruning”. For example, let’s assume you have [...]]]></description>
			<content:encoded><![CDATA[<p>The Enterprise Edition of Oracle Corp’s. flagship database has many features.  One of these is partitioning.  Partitioning allows a user to segment table rows into separate physical storage structures.  This can improve things such as performance and manageability.  </p>
<p>Performance can be improved by utilizing what Oracle terms “partition pruning”.  For example, let’s assume you have a table with one billion rows, which you then partition into 20 partitions based on date.  If you ask for all rows with a date of August 18, 2010, Oracle is “smart” enough to prune and search only the partition in which the row you requested could possibly exist.  This means it has to search 1/20 of the data it would have had to search in an un-partitioned table.</p>
<p>For manageability, you may be able to drop the oldest partition from some point in the past for which you no longer need the data.  This is far faster and requires fewer resources than a delete of the same data.</p>
<p>However, as nice as it is, it is an additional cost option.  Some users would like to have the ability to use it, but can’t afford to pay for it.  In this case, there is a “poor man’s” option, which is the subject of this article.  Since at least Oracle Release 8.0.6, Oracle has provided the ability for a user to insert records using a view.  A view is normally thought of as a query whose definition is stored in the database.  However, using what is called an “instead of” trigger, a user can create the view, and then create a trigger on the view which decides in which physical table to place the data.  The view is usually (although it doesn’t have to be) a union of at least two tables, and is created with the instead of option.  Below is a simple example:</p>

<div class="wp_syntax"><div class="code"><pre class="plsql" style="font-family:monospace;"><span style="color: #00F;">CREATE</span> <span style="color: #00F;">OR</span> <span style="color: #000;">REPLACE</span> <span style="color: #00F;">VIEW</span> myview <span style="color: #00F;">IS</span>
  <span style="color: #00F;">SELECT</span> <span style="color: #00F;">*</span> <span style="color: #00F;">FROM</span> table1
  <span style="color: #00F;">UNION</span>
  <span style="color: #00F;">SELECT</span> <span style="color: #00F;">*</span> <span style="color: #00F;">FROM</span> table2
<span style="color: #00F;">/</span>
&nbsp;
<span style="color: #00F;">CREATE</span> <span style="color: #00F;">OR</span> <span style="color: #000;">REPLACE</span> <span style="color: #00F;">TRIGGER</span> mytrg
  instead <span style="color: #00F;">OF</span> <span style="color: #00F;">INSERT</span> <span style="color: #00F;">ON</span> myview
  <span style="color: #00F;">FOR</span> each <span style="color: #00F;">ROW</span>
<span style="color: #00F;">BEGIN</span>
  <span style="color: #00F;">IF</span> some_condition_met <span style="color: #00F;">THEN</span>
    <span style="color: #00F;">INSERT</span> <span style="color: #00F;">INTO</span> table1<span style="color: #00F;">;</span>
  <span style="color: #00F;">ELSE</span>
    <span style="color: #00F;">INSERT</span> <span style="color: #00F;">INTO</span> table2<span style="color: #00F;">;</span>
<span style="color: #00F;">END</span><span style="color: #00F;">;</span>
<span style="color: #00F;">/</span></pre></div></div>

<p>What this allows us to do is to code the trigger to put our rows in a physical table much as the partitioning option does.</p>
<p>There are some drawbacks to using this method:</p>
<p>1.The instead of trigger is dropped when the view is changed<br />
2.dropping a table used in the view invalidates the view<br />
3.all sql executed in the trigger is soft parsed.  session_cursor_cache alleviates most of this as an issue, but it should be thoroughly tested for performance.  The appendix of this document provides a python based stress tester that compares both partitioning and instead of triggers.</p>
<p>The best application for this is probably those tables where it is reasonably easy to forecast the demand for partitions.  Monthly partitions are an excellent example.  Another would be partitioning by order_id, or some other method.  Add whatever you think you need for a *long* time going forward.  The nice thing is this functions in a similar fashion to local partitions, so you can truncate an &#8220;old&#8221; table without impacting current activity.  This would take care of the space concern.  Also, ensure you put them in tablespaces where you can easily manage the space.  Ideally, put each table in its own tablespace so you can truncate the table and resize the datafile when the data in that table is no longer needed.</p>
<p>Obviously, hash partitioning wouldn&#8217;t work here.  If you are interested, you could use the ora_hash function.</p>
<p>TEST CASE</p>
<p>Below is a test case setup that uses instead of triggers.  We create three tables, one for each month of sales as indicated in the sales_YYYY_MM naming convention.</p>

<div class="wp_syntax"><div class="code"><pre class="plsql" style="font-family:monospace;"><span style="color: #00F;">CREATE</span> <span style="color: #00F;">TABLE</span> sales_2010_07 <span style="color: #00F;">&#40;</span>period_start <span style="color: #00F;">DATE</span><span style="color: #00F;">,</span>period_end <span style="color: #00F;">DATE</span><span style="color: #00F;">,</span>product_name <span style="color: #00F;">VARCHAR2</span><span style="color: #00F;">&#40;</span><span style="color: #800;">50</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">,</span>product_total <span style="color: #00F;">NUMBER</span><span style="color: #00F;">&#41;</span>
<span style="color: #00F;">/</span>
&nbsp;
<span style="color: #00F;">CREATE</span> <span style="color: #00F;">TABLE</span> sales_2010_08 <span style="color: #00F;">&#40;</span>period_start <span style="color: #00F;">DATE</span><span style="color: #00F;">,</span>period_end <span style="color: #00F;">DATE</span><span style="color: #00F;">,</span>product_name <span style="color: #00F;">VARCHAR2</span><span style="color: #00F;">&#40;</span><span style="color: #800;">50</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">,</span>product_total <span style="color: #00F;">NUMBER</span><span style="color: #00F;">&#41;</span>
<span style="color: #00F;">/</span>
&nbsp;
<span style="color: #00F;">CREATE</span> <span style="color: #00F;">TABLE</span> sales_2010_09 <span style="color: #00F;">&#40;</span>period_start <span style="color: #00F;">DATE</span><span style="color: #00F;">,</span>period_end <span style="color: #00F;">DATE</span><span style="color: #00F;">,</span>product_name <span style="color: #00F;">VARCHAR2</span><span style="color: #00F;">&#40;</span><span style="color: #800;">50</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">,</span>product_total <span style="color: #00F;">NUMBER</span><span style="color: #00F;">&#41;</span>
<span style="color: #00F;">/</span></pre></div></div>

<p>We then create a view which unions the three tables together.</p>

<div class="wp_syntax"><div class="code"><pre class="plsql" style="font-family:monospace;"><span style="color: #00F;">CREATE</span> <span style="color: #00F;">OR</span> <span style="color: #000;">REPLACE</span> <span style="color: #00F;">VIEW</span> sales <span style="color: #00F;">AS</span>
  <span style="color: #00F;">SELECT</span> <span style="color: #00F;">*</span> <span style="color: #00F;">FROM</span> sales_2010_07
  <span style="color: #00F;">UNION</span>
  <span style="color: #00F;">SELECT</span> <span style="color: #00F;">*</span> <span style="color: #00F;">FROM</span> sales_2010_08
  <span style="color: #00F;">UNION</span>
  <span style="color: #00F;">SELECT</span> <span style="color: #00F;">*</span> <span style="color: #00F;">FROM</span> sales_2010_09
<span style="color: #00F;">/</span></pre></div></div>

<p>…and also create a trigger on the view.  The trigger determines the current date, and inserts the row in the table associated with the month of the date being inserted.</p>

<div class="wp_syntax"><div class="code"><pre class="plsql" style="font-family:monospace;"><span style="color: #00F;">CREATE</span> <span style="color: #00F;">OR</span> <span style="color: #000;">REPLACE</span> <span style="color: #00F;">TRIGGER</span> sales_trg
  instead <span style="color: #00F;">OF</span> <span style="color: #00F;">INSERT</span> <span style="color: #00F;">ON</span> sales
  <span style="color: #00F;">FOR</span> each <span style="color: #00F;">ROW</span>
<span style="color: #00F;">DECLARE</span>
  l_date <span style="color: #00F;">VARCHAR2</span><span style="color: #00F;">&#40;</span><span style="color: #800;">30</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">;</span>
<span style="color: #00F;">BEGIN</span>
  l_date <span style="color: #00F;">:=</span> <span style="color: #000;">TO_CHAR</span><span style="color: #00F;">&#40;</span><span style="color: #000;">TRUNC</span><span style="color: #00F;">&#40;</span><span style="color: #000;">LAST_DAY</span><span style="color: #00F;">&#40;</span><span style="color: #00F;">:</span><span style="color: #00F;">NEW</span><span style="color: #00F;">.</span>period_start<span style="color: #00F;">&#41;</span> <span style="color: #00F;">+</span> <span style="color: #800;">1</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">,</span><span style="color: #F00;">'YYYY_MM'</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">;</span>
  <span style="color: #00F;">IF</span> inserting <span style="color: #00F;">THEN</span>
    <span style="color: #00F;">EXECUTE</span> <span style="color: #00F;">IMMEDIATE</span> <span style="color: #F00;">'insert into sales_'</span> <span style="color: #00F;">||</span> l_date <span style="color: #00F;">||</span> <span style="color: #F00;">' values(:1,:2,:3,:4)'</span> 
      using <span style="color: #00F;">:</span><span style="color: #00F;">NEW</span><span style="color: #00F;">.</span>period_start<span style="color: #00F;">,:</span><span style="color: #00F;">NEW</span><span style="color: #00F;">.</span>period_end<span style="color: #00F;">,:</span><span style="color: #00F;">NEW</span><span style="color: #00F;">.</span>product_name<span style="color: #00F;">,:</span><span style="color: #00F;">NEW</span><span style="color: #00F;">.</span>product_total<span style="color: #00F;">;</span>
  <span style="color: #00F;">ELSIF</span> updating <span style="color: #00F;">THEN</span>
    <span style="color: #00F;">EXECUTE</span> <span style="color: #00F;">IMMEDIATE</span> <span style="color: #F00;">'update sales_'</span> <span style="color: #00F;">||</span> l_date <span style="color: #00F;">||</span> <span style="color: #F00;">' set period_start = :1, period_end = :2, product_name = :3, product_total = :4 where period_start = :5 and product_name = :6'</span> 
      using <span style="color: #00F;">:</span><span style="color: #00F;">NEW</span><span style="color: #00F;">.</span>period_start<span style="color: #00F;">,:</span><span style="color: #00F;">NEW</span><span style="color: #00F;">.</span>period_end<span style="color: #00F;">,:</span><span style="color: #00F;">NEW</span><span style="color: #00F;">.</span>product_name<span style="color: #00F;">,:</span><span style="color: #00F;">NEW</span><span style="color: #00F;">.</span>product_total<span style="color: #00F;">,:</span><span style="color: #00F;">NEW</span><span style="color: #00F;">.</span>period_start<span style="color: #00F;">,:</span><span style="color: #00F;">NEW</span><span style="color: #00F;">.</span>product_name<span style="color: #00F;">;</span>
  <span style="color: #00F;">ELSIF</span> deleting <span style="color: #00F;">THEN</span>
    <span style="color: #00F;">EXECUTE</span> <span style="color: #00F;">IMMEDIATE</span> <span style="color: #F00;">'delete sales_'</span> <span style="color: #00F;">||</span> l_date <span style="color: #00F;">||</span> <span style="color: #F00;">' where period_start = :1 and product_name = :2'</span> 
      using <span style="color: #00F;">:</span><span style="color: #00F;">NEW</span><span style="color: #00F;">.</span>period_start<span style="color: #00F;">,:</span><span style="color: #00F;">NEW</span><span style="color: #00F;">.</span>product_name<span style="color: #00F;">;</span>
  <span style="color: #00F;">END</span> <span style="color: #00F;">IF</span><span style="color: #00F;">;</span>
<span style="color: #00F;">END</span><span style="color: #00F;">;</span>
<span style="color: #00F;">/</span></pre></div></div>

<p>We can then use what is below to load our table to verify that it works functionally.</p>

<div class="wp_syntax"><div class="code"><pre class="plsql" style="font-family:monospace;"><span style="color: #00F;">DECLARE</span>
  <span style="color: #00F;">TYPE</span> t_product_list <span style="color: #00F;">IS</span> <span style="color: #00F;">TABLE</span> <span style="color: #00F;">OF</span> <span style="color: #00F;">VARCHAR2</span><span style="color: #00F;">&#40;</span><span style="color: #800;">50</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">;</span>
  l_product_list t_product_list <span style="color: #00F;">:=</span> t_product_list<span style="color: #00F;">&#40;</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">;</span>
  l_date <span style="color: #00F;">DATE</span><span style="color: #00F;">;</span>
  l_product_name <span style="color: #00F;">VARCHAR2</span><span style="color: #00F;">&#40;</span><span style="color: #800;">50</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">;</span>
<span style="color: #00F;">BEGIN</span>
  l_product_list<span style="color: #00F;">.</span>extend<span style="color: #00F;">&#40;</span><span style="color: #800;">5</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">;</span>
  l_product_list<span style="color: #00F;">&#40;</span><span style="color: #800;">1</span><span style="color: #00F;">&#41;</span> <span style="color: #00F;">:=</span> <span style="color: #F00;">'Hamburger'</span><span style="color: #00F;">;</span>
  l_product_list<span style="color: #00F;">&#40;</span><span style="color: #800;">2</span><span style="color: #00F;">&#41;</span> <span style="color: #00F;">:=</span> <span style="color: #F00;">'Frosty'</span><span style="color: #00F;">;</span>
  l_product_list<span style="color: #00F;">&#40;</span><span style="color: #800;">3</span><span style="color: #00F;">&#41;</span> <span style="color: #00F;">:=</span> <span style="color: #F00;">'Fries'</span><span style="color: #00F;">;</span>
  l_product_list<span style="color: #00F;">&#40;</span><span style="color: #800;">4</span><span style="color: #00F;">&#41;</span> <span style="color: #00F;">:=</span> <span style="color: #F00;">'Chili'</span><span style="color: #00F;">;</span>
  l_product_list<span style="color: #00F;">&#40;</span><span style="color: #800;">5</span><span style="color: #00F;">&#41;</span> <span style="color: #00F;">:=</span> <span style="color: #F00;">'Salad'</span><span style="color: #00F;">;</span>
  <span style="color: #00F;">FOR</span> i <span style="color: #00F;">IN</span> 1<span style="color: #00F;">..</span>10000 <span style="color: #00F;">LOOP</span>
    l_date <span style="color: #00F;">:=</span> <span style="color: #000;">TRUNC</span><span style="color: #00F;">&#40;</span><span style="color: #000;">SYSDATE</span> <span style="color: #00F;">-</span> <span style="color: #000;">TRUNC</span><span style="color: #00F;">&#40;</span><span style="color: #00F;">DBMS_RANDOM</span><span style="color: #00F;">.</span><span style="color: #000;">VALUE</span><span style="color: #00F;">&#40;</span><span style="color: #800;">1</span><span style="color: #00F;">,</span><span style="color: #800;">45</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">,</span><span style="color: #F00;">'MON'</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">;</span> <span style="color: #080; font-style: italic;">--first day of the period</span>
    l_product_name <span style="color: #00F;">:=</span> l_product_list<span style="color: #00F;">&#40;</span><span style="color: #000;">TRUNC</span><span style="color: #00F;">&#40;</span><span style="color: #00F;">DBMS_RANDOM</span><span style="color: #00F;">.</span><span style="color: #000;">VALUE</span><span style="color: #00F;">&#40;</span><span style="color: #800;">1</span><span style="color: #00F;">,</span><span style="color: #800;">6</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">;</span> <span style="color: #080; font-style: italic;">--random product from our list</span>
    <span style="color: #00F;">INSERT</span> <span style="color: #00F;">INTO</span> sales <span style="color: #00F;">VALUES</span><span style="color: #00F;">&#40;</span>l_date<span style="color: #00F;">,</span><span style="color: #000;">TRUNC</span><span style="color: #00F;">&#40;</span><span style="color: #000;">LAST_DAY</span><span style="color: #00F;">&#40;</span>l_date<span style="color: #00F;">&#41;</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">,</span>l_product_name<span style="color: #00F;">,</span><span style="color: #00F;">DBMS_RANDOM</span><span style="color: #00F;">.</span><span style="color: #000;">VALUE</span><span style="color: #00F;">&#40;</span><span style="color: #800;">1</span><span style="color: #00F;">,</span><span style="color: #800;">100000</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">;</span> <span style="color: #080; font-style: italic;">-- this also randomly assigns a sales figure</span>
  <span style="color: #00F;">END</span> <span style="color: #00F;">LOOP</span><span style="color: #00F;">;</span>
<span style="color: #00F;">END</span><span style="color: #00F;">;</span>
<span style="color: #00F;">/</span></pre></div></div>

<p>PERFORMANCE TEST ANALYSIS:</p>
<p>As mentioned earlier, performance is a major consideration when considering this as a possible design.</p>
<p>In our test we used 50 sessions, each of which were inserting 100,000 rows in a loop.  This will result in 5 million rows total.  We used python for our test software since it is easy to setup a multi threaded test and change things on the fly.  Our partitioned table structure is below:</p>

<div class="wp_syntax"><div class="code"><pre class="plsql" style="font-family:monospace;"><span style="color: #00F;">CREATE</span> <span style="color: #00F;">TABLE</span> sales_p <span style="color: #00F;">&#40;</span>period_start <span style="color: #00F;">DATE</span><span style="color: #00F;">,</span>period_end <span style="color: #00F;">DATE</span><span style="color: #00F;">,</span>product_name <span style="color: #00F;">VARCHAR2</span><span style="color: #00F;">&#40;</span><span style="color: #800;">50</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">,</span>product_total <span style="color: #00F;">NUMBER</span><span style="color: #00F;">&#41;</span>
  <span style="color: #00F;">PARTITION</span> <span style="color: #00F;">BY</span> <span style="color: #00F;">RANGE</span><span style="color: #00F;">&#40;</span>period_start<span style="color: #00F;">&#41;</span>
   <span style="color: #00F;">&#40;</span><span style="color: #00F;">PARTITION</span> p_2010_07 <span style="color: #00F;">VALUES</span> less than <span style="color: #00F;">&#40;</span><span style="color: #000;">TO_DATE</span><span style="color: #00F;">&#40;</span><span style="color: #F00;">'2010_07_01'</span><span style="color: #00F;">,</span><span style="color: #F00;">'YYYY_MM_DD'</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">,</span>
    <span style="color: #00F;">PARTITION</span> p_2010_08 <span style="color: #00F;">VALUES</span> less than <span style="color: #00F;">&#40;</span><span style="color: #000;">TO_DATE</span><span style="color: #00F;">&#40;</span><span style="color: #F00;">'2010_08_01'</span><span style="color: #00F;">,</span><span style="color: #F00;">'YYYY_MM_DD'</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">,</span>
    <span style="color: #00F;">PARTITION</span> p_2010_09 <span style="color: #00F;">VALUES</span> less than <span style="color: #00F;">&#40;</span><span style="color: #000;">TO_DATE</span><span style="color: #00F;">&#40;</span><span style="color: #F00;">'2010_09_01'</span><span style="color: #00F;">,</span><span style="color: #F00;">'YYYY_MM_DD'</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">&#41;</span>
   <span style="color: #00F;">&#41;</span>
<span style="color: #00F;">/</span></pre></div></div>

<p>Our instead of version is then shown below.</p>

<div class="wp_syntax"><div class="code"><pre class="plsql" style="font-family:monospace;"><span style="color: #00F;">CREATE</span> <span style="color: #00F;">TABLE</span> sales_2010_07 <span style="color: #00F;">&#40;</span>period_start <span style="color: #00F;">DATE</span><span style="color: #00F;">,</span>period_end <span style="color: #00F;">DATE</span><span style="color: #00F;">,</span>product_name <span style="color: #00F;">VARCHAR2</span><span style="color: #00F;">&#40;</span><span style="color: #800;">50</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">,</span>product_total <span style="color: #00F;">NUMBER</span><span style="color: #00F;">&#41;</span>
<span style="color: #00F;">/</span>
&nbsp;
<span style="color: #00F;">CREATE</span> <span style="color: #00F;">TABLE</span> sales_2010_08 <span style="color: #00F;">&#40;</span>period_start <span style="color: #00F;">DATE</span><span style="color: #00F;">,</span>period_end <span style="color: #00F;">DATE</span><span style="color: #00F;">,</span>product_name <span style="color: #00F;">VARCHAR2</span><span style="color: #00F;">&#40;</span><span style="color: #800;">50</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">,</span>product_total <span style="color: #00F;">NUMBER</span><span style="color: #00F;">&#41;</span>
<span style="color: #00F;">/</span>
&nbsp;
<span style="color: #00F;">CREATE</span> <span style="color: #00F;">TABLE</span> sales_2010_09 <span style="color: #00F;">&#40;</span>period_start <span style="color: #00F;">DATE</span><span style="color: #00F;">,</span>period_end <span style="color: #00F;">DATE</span><span style="color: #00F;">,</span>product_name <span style="color: #00F;">VARCHAR2</span><span style="color: #00F;">&#40;</span><span style="color: #800;">50</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">,</span>product_total <span style="color: #00F;">NUMBER</span><span style="color: #00F;">&#41;</span>
<span style="color: #00F;">/</span></pre></div></div>

<p>We then create our view of these tables…</p>

<div class="wp_syntax"><div class="code"><pre class="plsql" style="font-family:monospace;"><span style="color: #00F;">CREATE</span> <span style="color: #00F;">OR</span> <span style="color: #000;">REPLACE</span> <span style="color: #00F;">VIEW</span> sales <span style="color: #00F;">AS</span>
  <span style="color: #00F;">SELECT</span> <span style="color: #00F;">*</span> <span style="color: #00F;">FROM</span> sales_2010_07
  <span style="color: #00F;">UNION</span>
  <span style="color: #00F;">SELECT</span> <span style="color: #00F;">*</span> <span style="color: #00F;">FROM</span> sales_2010_08
  <span style="color: #00F;">UNION</span>
  <span style="color: #00F;">SELECT</span> <span style="color: #00F;">*</span> <span style="color: #00F;">FROM</span> sales_2010_09
<span style="color: #00F;">/</span></pre></div></div>

<p>..and finally create our trigger which will insert rows into the correct partitions.</p>

<div class="wp_syntax"><div class="code"><pre class="plsql" style="font-family:monospace;"><span style="color: #00F;">CREATE</span> <span style="color: #00F;">OR</span> <span style="color: #000;">REPLACE</span> <span style="color: #00F;">TRIGGER</span> sales_trg
  instead <span style="color: #00F;">OF</span> <span style="color: #00F;">INSERT</span> <span style="color: #00F;">ON</span> sales
  <span style="color: #00F;">FOR</span> each <span style="color: #00F;">ROW</span>
<span style="color: #00F;">DECLARE</span>
  l_date <span style="color: #00F;">VARCHAR2</span><span style="color: #00F;">&#40;</span><span style="color: #800;">30</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">;</span>
<span style="color: #00F;">BEGIN</span>
  l_date <span style="color: #00F;">:=</span> <span style="color: #000;">TO_CHAR</span><span style="color: #00F;">&#40;</span><span style="color: #000;">TRUNC</span><span style="color: #00F;">&#40;</span><span style="color: #000;">LAST_DAY</span><span style="color: #00F;">&#40;</span><span style="color: #00F;">:</span><span style="color: #00F;">NEW</span><span style="color: #00F;">.</span>period_start<span style="color: #00F;">&#41;</span> <span style="color: #00F;">+</span> <span style="color: #800;">1</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">,</span><span style="color: #F00;">'YYYY_MM'</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">;</span>
  <span style="color: #00F;">IF</span> inserting <span style="color: #00F;">THEN</span>
    <span style="color: #00F;">EXECUTE</span> <span style="color: #00F;">IMMEDIATE</span> <span style="color: #F00;">'insert into sales_'</span> <span style="color: #00F;">||</span> l_date <span style="color: #00F;">||</span> <span style="color: #F00;">' values(:1,:2,:3,:4)'</span> 
      using <span style="color: #00F;">:</span><span style="color: #00F;">NEW</span><span style="color: #00F;">.</span>period_start<span style="color: #00F;">,:</span><span style="color: #00F;">NEW</span><span style="color: #00F;">.</span>period_end<span style="color: #00F;">,:</span><span style="color: #00F;">NEW</span><span style="color: #00F;">.</span>product_name<span style="color: #00F;">,:</span><span style="color: #00F;">NEW</span><span style="color: #00F;">.</span>product_total<span style="color: #00F;">;</span>
  <span style="color: #00F;">ELSIF</span> updating <span style="color: #00F;">THEN</span>
    <span style="color: #00F;">EXECUTE</span> <span style="color: #00F;">IMMEDIATE</span> <span style="color: #F00;">'update sales_'</span> <span style="color: #00F;">||</span> l_date <span style="color: #00F;">||</span> <span style="color: #F00;">' set period_start = :1, period_end = :2, product_name = :3, product_total = :4 where period_start = :5 and product_name = :6'</span> 
      using <span style="color: #00F;">:</span><span style="color: #00F;">NEW</span><span style="color: #00F;">.</span>period_start<span style="color: #00F;">,:</span><span style="color: #00F;">NEW</span><span style="color: #00F;">.</span>period_end<span style="color: #00F;">,:</span><span style="color: #00F;">NEW</span><span style="color: #00F;">.</span>product_name<span style="color: #00F;">,:</span><span style="color: #00F;">NEW</span><span style="color: #00F;">.</span>product_total<span style="color: #00F;">,:</span><span style="color: #00F;">NEW</span><span style="color: #00F;">.</span>period_start<span style="color: #00F;">,:</span><span style="color: #00F;">NEW</span><span style="color: #00F;">.</span>product_name<span style="color: #00F;">;</span>
  <span style="color: #00F;">ELSIF</span> deleting <span style="color: #00F;">THEN</span>
    <span style="color: #00F;">EXECUTE</span> <span style="color: #00F;">IMMEDIATE</span> <span style="color: #F00;">'delete sales_'</span> <span style="color: #00F;">||</span> l_date <span style="color: #00F;">||</span> <span style="color: #F00;">' where period_start = :1 and product_name = :2'</span> 
      using <span style="color: #00F;">:</span><span style="color: #00F;">NEW</span><span style="color: #00F;">.</span>period_start<span style="color: #00F;">,:</span><span style="color: #00F;">NEW</span><span style="color: #00F;">.</span>product_name<span style="color: #00F;">;</span>
  <span style="color: #00F;">END</span> <span style="color: #00F;">IF</span><span style="color: #00F;">;</span>
<span style="color: #00F;">END</span><span style="color: #00F;">;</span>
<span style="color: #00F;">/</span></pre></div></div>

<p>In our next entry, we will provide the test case results.</p>
]]></content:encoded>
			<wfw:commentRss>http://appcrawler.com/wordpress/2012/02/07/poor-man%e2%80%99s-partitioning-with-instead-of-triggers-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Connecting to SQL Server using internal authentication</title>
		<link>http://appcrawler.com/wordpress/2012/01/31/connecting-to-sql-server-using-internal-authentication/</link>
		<comments>http://appcrawler.com/wordpress/2012/01/31/connecting-to-sql-server-using-internal-authentication/#comments</comments>
		<pubDate>Tue, 31 Jan 2012 17:04:05 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://appcrawler.com/wordpress/?p=1879</guid>
		<description><![CDATA[We use java for a lot of our jobs, and using it to access SQL Server is no exception. We wanted to have controlled access, and avoid &#8220;user sprawl&#8221; across servers. As such, we use Windows authentication from our java programs. Below is an example: 1 2 3 4 5 6 7 8 9 10 [...]]]></description>
			<content:encoded><![CDATA[<p>We use java for a lot of our jobs, and using it to access SQL Server is no exception.  We wanted to have controlled access, and avoid &#8220;user sprawl&#8221; across servers.  As such, we use Windows authentication from our java programs.  Below is an example:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.microsoft.sqlserver.jdbc.*</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> connSqlServer <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #003399;">Connection</span> con <span style="color: #339933;">=</span> <span style="color: #003399;">DriverManager</span>.<span style="color: #006633;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jdbc:sqlserver://STSQL01.fake_domain:1433;databaseName=MSDB;integratedSecurity=true;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #003399;">Statement</span> stm <span style="color: #339933;">=</span> con.<span style="color: #006633;">createStatement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #003399;">ResultSet</span> rst <span style="color: #339933;">=</span> stm.<span style="color: #006633;">executeQuery</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;select * from msdb.dbo.backupset&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>rst.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>rst.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;database_name&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://appcrawler.com/wordpress/2012/01/31/connecting-to-sql-server-using-internal-authentication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Comparing RPM&#8217;s between servers</title>
		<link>http://appcrawler.com/wordpress/2012/01/19/comparing-rpms-between-servers/</link>
		<comments>http://appcrawler.com/wordpress/2012/01/19/comparing-rpms-between-servers/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 15:29:30 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Operating Systems]]></category>

		<guid isPermaLink="false">http://appcrawler.com/wordpress/?p=1872</guid>
		<description><![CDATA[Periodically, I will want to compare the RPM installations between two or more servers. Sometimes, I may not care about the specific versions of each RPM, but only that *some* version exists. To do this, I can use awk and print only the name of the RPM up to but not including where the version [...]]]></description>
			<content:encoded><![CDATA[<p>Periodically, I will want to compare the RPM installations between two or more servers.  Sometimes, I may not care about the specific versions of each RPM, but only that *some* version exists.  To do this, I can use awk and print only the name of the RPM up to but not including where the version number begins.</p>
<p>First, we show the versions with a normal rpm -qa command&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">CMHLDEVPSOFT01:oracle:fn9dev:/home/oracle&gt;rpm -qa | head -10
tzdata-2011g-1.el5
expat-1.95.8-8.3.el5_5.3
libusb-0.1.12-5.1
gdbm-1.8.0-26.2.1
procps-3.2.7-17.el5
libIDL-0.8.7-1.fc6
libksba-1.0.5-2.el5
libtevent-0.9.8-10.el5
less-436-7.el5
eject-2.1.5-4.2.el5
CMHLDEVPSOFT01:oracle:fn9dev:/home/oracle&gt;</pre></div></div>

<p>&#8230;and then show how we can strip the version information from the RPM name&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">CMHLDEVPSOFT01:oracle:fn9dev:/home/oracle&gt;rpm -qa | awk -F &quot;-&quot; '{i=1;while (i &lt;= NF) {if ($i !~ /'^[0-9]'/) {if(i==1) {s=$i} else{s=s&quot;-&quot;$i};i++}else{print s;s=&quot;&quot;;next}}}' | head -10
tzdata
expat
libusb
gdbm
procps
libIDL
libksba
libtevent
less
eject</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://appcrawler.com/wordpress/2012/01/19/comparing-rpms-between-servers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why won&#8217;t my VIP start?</title>
		<link>http://appcrawler.com/wordpress/2012/01/18/why-wont-my-vip-start/</link>
		<comments>http://appcrawler.com/wordpress/2012/01/18/why-wont-my-vip-start/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 21:03:37 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[RAC]]></category>

		<guid isPermaLink="false">http://appcrawler.com/wordpress/?p=1675</guid>
		<description><![CDATA[After restarting a test server, I found the RAC VIP would not start. This post is just a quick note as to how I troubleshot the problem, as well as its ultimate resolution. I frequently use the find -mmin 5 -type f &#124; xargs grep -i "whatever you want" command to find any recently modified [...]]]></description>
			<content:encoded><![CDATA[<p>After restarting a test server, I found the RAC VIP would not start.  This post is just a quick note as to how I troubleshot the problem, as well as its ultimate resolution.</p>
<p>I frequently use the
<pre>find -mmin 5 -type f | xargs grep -i "whatever you want"</pre>
<p> command to find any recently modified files under a directory where I believe a logfile may live.  In this case, that proved to be useful.  I cd&#8217;d to the GRID_INFRASTRUCTURE home, and found references to VIP errors in the following file:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$GRID_HOME/log/$(hostname)/agent/crsd/orarootagent_root/orarootagent_root.log</pre></div></div>

<p>In this file, I found the following contents&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">2011-11-01 20:26:31.761: [    AGFW][2765908880] {1:2236:4470} Agent received the message: RESOURCE_START[ora.dell11gr1.vip 1 1] ID 4098:29951
2011-11-01 20:26:31.761: [    AGFW][2765908880] {1:2236:4470} Preparing START command for: ora.dell11gr1.vip 1 1
2011-11-01 20:26:31.761: [    AGFW][2765908880] {1:2236:4470} ora.dell11gr1.vip 1 1 state changed from: OFFLINE to: STARTING
2011-11-01 20:26:31.763: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [start] clsn_agent::start {
2011-11-01 20:26:31.781: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [start] InterfaceName = eth0
2011-11-01 20:26:31.781: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [start] NetworkMask = 255.255.255.0
2011-11-01 20:26:31.782: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [start] NetworkAuto = static
2011-11-01 20:26:31.782: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [start] Checking if eth0 Interface is fine
2011-11-01 20:26:31.791: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [start] ifname=eth0
2011-11-01 20:26:31.791: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [start] subnetmask=255.255.255.0
2011-11-01 20:26:31.791: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [start] subnetnumber=192.168.1.0
2011-11-01 20:26:31.792: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [start] InterfaceName = eth0
2011-11-01 20:26:31.970: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [start] HostName dell11gr1-vip translated to
2011-11-01 20:26:31.970: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [start] Interface Name = eth0
2011-11-01 20:26:31.970: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [start] Ip Address =
2011-11-01 20:26:31.971: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [start] clsn_agent::start: Exception AgentException
2011-11-01 20:26:31.971: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [start] InterfaceName = eth0 IpAddress =
2011-11-01 20:26:31.971: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [start] clsn_agent::start }
2011-11-01 20:26:31.971: [    AGFW][2900142992] {1:2236:4470} Command: start for resource: ora.dell11gr1.vip 1 1 completed with status: FAIL
2011-11-01 20:26:31.972: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [check] Waiting for Network Object to be initialized
2011-11-01 20:26:31.973: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [check] InterfaceName = eth0
2011-11-01 20:26:31.973: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [check] NetworkMask = 255.255.255.0
2011-11-01 20:26:31.973: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [check] NetworkAuto = static
2011-11-01 20:26:31.973: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [check] Checking if eth0 Interface is fine
2011-11-01 20:26:31.978: [    AGFW][2765908880] {1:2236:4470} Agent sending reply for: RESOURCE_START[ora.dell11gr1.vip 1 1] ID 4098:29951
2011-11-01 20:26:32.008: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [check] ifname=eth0
2011-11-01 20:26:32.008: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [check] subnetmask=255.255.255.0
2011-11-01 20:26:32.008: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [check] subnetnumber=192.168.1.0
2011-11-01 20:26:32.008: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [check] InterfaceName = eth0
2011-11-01 20:26:32.008: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [check] HostName dell11gr1-vip translated to
2011-11-01 20:26:32.009: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [check] Interface Name = eth0
2011-11-01 20:26:32.009: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [check] Ip Address =
2011-11-01 20:26:32.009: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [check] AgentException caught in VipAgent::check()
2011-11-01 20:26:32.009: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [check] InterfaceName = eth0 IpAddress =
2011-11-01 20:26:32.010: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [check] VipAgent::sendFail2Srv {
2011-11-01 20:26:32.033: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [check] VipAgent::sendFail2Srv }</pre></div></div>

<p>Notice the following line in particular&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">2011-11-01 20:26:32.008: [ora.dell11gr1.vip][2900142992] {1:2236:4470} [check] HostName dell11gr1-vip translated to</pre></div></div>

<p>I then found that I couldn&#8217;t ping the VIP by name&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">dell11gr1:oracle:+ASM1:/u01/app/11.2.0/grid# ping dell11gr1-vip
ping: unknown host dell11gr1-vip</pre></div></div>

<p>The solution in this case was simple, I just needed to start my DNS test server.</p>
]]></content:encoded>
			<wfw:commentRss>http://appcrawler.com/wordpress/2012/01/18/why-wont-my-vip-start/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting DDL for a scheduler job</title>
		<link>http://appcrawler.com/wordpress/2012/01/11/getting-ddl-for-a-shceduler-job/</link>
		<comments>http://appcrawler.com/wordpress/2012/01/11/getting-ddl-for-a-shceduler-job/#comments</comments>
		<pubDate>Wed, 11 Jan 2012 18:41:29 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://appcrawler.com/wordpress/?p=1865</guid>
		<description><![CDATA[If you need to copy the DDL to create a scheduler job from one schema to another, what is below works well&#8230; 13:28:56 oracle@oh1xpwcdb01 ~ &#62;./dynColumns.py &#34;select dbms_metadata.get_ddl('PROCOBJ','CHECK_TEMP_FREE','HOWARDS') from dual&#34; ----------------------------------------------- &#160; BEGIN dbms_scheduler.create_job('&#34;CHECK_TEMP_FREE&#34;', job_type=&#62;'PLSQL_BLOCK', job_action=&#62; 'begin oclc_checks.check_temp_free(10); end;' , number_of_arguments=&#62;0, start_date=&#62;TO_TIMESTAMP_TZ('03-OCT-2009 04.40.00.000000000 PM AMERICA/NEW_YORK','DD-MON-RRRR HH.MI.SSXFF AM TZR','NLS_DATE_LANGUAGE=english'), repeat_interval=&#62; 'FREQ=MINUTELY;INTERVAL=5' , end_date=&#62;NULL, job_class=&#62;'&#34;DEFAULT_JOB_CLASS&#34;', enabled=&#62;FALSE, auto_drop=&#62;TRUE,comments=&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>If you need to copy the DDL to create a scheduler job from one schema to another, what is below works well&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">13:28:56 oracle@oh1xpwcdb01 ~ &gt;./dynColumns.py &quot;select dbms_metadata.get_ddl('PROCOBJ','CHECK_TEMP_FREE','HOWARDS') from dual&quot;
-----------------------------------------------
&nbsp;
BEGIN 
dbms_scheduler.create_job('&quot;CHECK_TEMP_FREE&quot;',
job_type=&gt;'PLSQL_BLOCK', job_action=&gt;
'begin oclc_checks.check_temp_free(10); end;'
, number_of_arguments=&gt;0,
start_date=&gt;TO_TIMESTAMP_TZ('03-OCT-2009 04.40.00.000000000 PM AMERICA/NEW_YORK','DD-MON-RRRR HH.MI.SSXFF AM TZR','NLS_DATE_LANGUAGE=english'), repeat_interval=&gt; 
'FREQ=MINUTELY;INTERVAL=5'
, end_date=&gt;NULL,
job_class=&gt;'&quot;DEFAULT_JOB_CLASS&quot;', enabled=&gt;FALSE, auto_drop=&gt;TRUE,comments=&gt;
NULL
);
dbms_scheduler.set_attribute('&quot;CHECK_TEMP_FREE&quot;','logging_level',DBMS_SCHEDULER.LOGGING_RUNS);
dbms_scheduler.enable('&quot;CHECK_TEMP_FREE&quot;');
COMMIT; 
END; 
&nbsp;
-----------------------------------------------
13:29:04 oracle@oh1xpwcdb01 ~ &gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://appcrawler.com/wordpress/2012/01/11/getting-ddl-for-a-shceduler-job/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Standard exception pragmas</title>
		<link>http://appcrawler.com/wordpress/2012/01/06/standard-exception-pragmas/</link>
		<comments>http://appcrawler.com/wordpress/2012/01/06/standard-exception-pragmas/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 20:43:15 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PL/SQL]]></category>

		<guid isPermaLink="false">http://appcrawler.com/wordpress/?p=1530</guid>
		<description><![CDATA[Oracle provides several standard exception pragmas (essentially, a compiler directive) for exceptions found on a fairly frequent basis. These are documented in the PL/SQL User Guide and Reference, but you can also get them at runtime using what is below: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 [...]]]></description>
			<content:encoded><![CDATA[<p>Oracle provides several standard exception pragmas (essentially, a compiler directive) for exceptions found on a fairly frequent basis.  These are documented in the PL/SQL User Guide and Reference, but you can also get them at runtime using what is below:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;">SQL<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">SELECT</span> text <span style="color: #993333; font-weight: bold;">FROM</span> dba_source <span style="color: #993333; font-weight: bold;">WHERE</span> name <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'STANDARD'</span> <span style="color: #993333; font-weight: bold;">AND</span> lower<span style="color: #66cc66;">&#40;</span>text<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%pragma%exception%'</span>;
&nbsp;
TEXT
<span style="color: #808080; font-style: italic;">--------------------------------------------------------------------------------</span>
    pragma EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>CURSOR_ALREADY_OPEN<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'-6511'</span><span style="color: #66cc66;">&#41;</span>;
    pragma EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>DUP_VAL_ON_INDEX<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'-0001'</span><span style="color: #66cc66;">&#41;</span>;
    pragma EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>TIMEOUT_ON_RESOURCE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'-0051'</span><span style="color: #66cc66;">&#41;</span>;
    pragma EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>INVALID_CURSOR<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'-1001'</span><span style="color: #66cc66;">&#41;</span>;
    pragma EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>NOT_LOGGED_ON<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'-1012'</span><span style="color: #66cc66;">&#41;</span>;
    pragma EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>LOGIN_DENIED<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'-1017'</span><span style="color: #66cc66;">&#41;</span>;
    pragma EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>NO_DATA_FOUND<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span>;
    pragma EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>ZERO_DIVIDE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'-1476'</span><span style="color: #66cc66;">&#41;</span>;
    pragma EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>INVALID_NUMBER<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'-1722'</span><span style="color: #66cc66;">&#41;</span>;
    pragma EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>TOO_MANY_ROWS<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'-1422'</span><span style="color: #66cc66;">&#41;</span>;
    pragma EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>STORAGE_ERROR<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'-6500'</span><span style="color: #66cc66;">&#41;</span>;
    pragma EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>PROGRAM_ERROR<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'-6501'</span><span style="color: #66cc66;">&#41;</span>;
    pragma EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>VALUE_ERROR<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'-6502'</span><span style="color: #66cc66;">&#41;</span>;
    pragma EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>ACCESS_INTO_NULL<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'-6530'</span><span style="color: #66cc66;">&#41;</span>;
    pragma EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>COLLECTION_IS_NULL <span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'-6531'</span><span style="color: #66cc66;">&#41;</span>;
    pragma EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>SUBSCRIPT_OUTSIDE_LIMIT<span style="color: #66cc66;">,</span><span style="color: #ff0000;">'-6532'</span><span style="color: #66cc66;">&#41;</span>;
    pragma EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>SUBSCRIPT_BEYOND_COUNT <span style="color: #66cc66;">,</span><span style="color: #ff0000;">'-6533'</span><span style="color: #66cc66;">&#41;</span>;
  pragma EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>ROWTYPE_MISMATCH<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'-6504'</span><span style="color: #66cc66;">&#41;</span>;
  PRAGMA EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>SYS_INVALID_ROWID<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'-1410'</span><span style="color: #66cc66;">&#41;</span>;
    pragma EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>SELF_IS_NULL<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'-30625'</span><span style="color: #66cc66;">&#41;</span>;
    pragma EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>CASE_NOT_FOUND<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'-6592'</span><span style="color: #66cc66;">&#41;</span>;
    pragma EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>USERENV_COMMITSCN_ERROR<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'-1725'</span><span style="color: #66cc66;">&#41;</span>;
    pragma EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>NO_DATA_NEEDED<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'-6548'</span><span style="color: #66cc66;">&#41;</span>;
pragma EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>INVALID_USERENV_PARAMETER<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">2003</span><span style="color: #66cc66;">&#41;</span>;
pragma EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>ICD_UNABLE_TO_COMPUTE<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">6594</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #cc66cc;">25</span> rows selected<span style="color: #66cc66;">.</span>
&nbsp;
SQL<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>This makes it easy to use in your PL/SQL programs, as they are available to all programs since they are in the STANDARD package.</p>
<p>For example, you can do something like:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="plsql" style="font-family:monospace;">SQL<span style="color: #00F;">&gt;</span> <span style="color: #00F;">DECLARE</span>
  <span style="color: #800;">2</span>    l <span style="color: #00F;">NUMBER</span><span style="color: #00F;">;</span>
  <span style="color: #800;">3</span>  <span style="color: #00F;">BEGIN</span>
  <span style="color: #800;">4</span>    l <span style="color: #00F;">:=</span> <span style="color: #F00;">'a'</span><span style="color: #00F;">;</span>
  <span style="color: #800;">5</span>  <span style="color: #00F;">EXCEPTION</span>
  <span style="color: #800;">6</span>    <span style="color: #00F;">WHEN</span> <span style="color: #F00;">VALUE_ERROR</span> <span style="color: #00F;">THEN</span>
  <span style="color: #800;">7</span>      <span style="color: #00F;">DBMS_OUTPUT</span><span style="color: #00F;">.</span>put_line<span style="color: #00F;">&#40;</span><span style="color: #F00;">'Please enter a number rather than a letter'</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">;</span>
  <span style="color: #800;">8</span>  <span style="color: #00F;">END</span><span style="color: #00F;">;</span>
  <span style="color: #800;">9</span>  <span style="color: #00F;">/</span>
Please enter a <span style="color: #00F;">NUMBER</span> rather than a letter
&nbsp;
PL<span style="color: #00F;">/</span><span style="color: #00F;">SQL</span> <span style="color: #00F;">PROCEDURE</span> successfully completed<span style="color: #00F;">.</span>
SQL<span style="color: #00F;">&gt;</span></pre></td></tr></table></div>

<p>We can also create exceptions for the standard exceptions with a predefined pragma in the standard package.  For example, we can either:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="plsql" style="font-family:monospace;">SQL<span style="color: #00F;">&gt;</span> <span style="color: #00F;">DECLARE</span>
  <span style="color: #800;">2</span>    customer_id <span style="color: #00F;">NUMBER</span><span style="color: #00F;">;</span>
  <span style="color: #800;">3</span>  <span style="color: #00F;">BEGIN</span>
  <span style="color: #800;">4</span>    <span style="color: #00F;">SELECT</span> c <span style="color: #00F;">INTO</span> customer_id <span style="color: #00F;">FROM</span> t0909 <span style="color: #00F;">WHERE</span> c <span style="color: #00F;">=</span> <span style="color: #F00;">'a'</span><span style="color: #00F;">;</span>
  <span style="color: #800;">5</span>  <span style="color: #00F;">END</span><span style="color: #00F;">;</span>
  <span style="color: #800;">6</span>  <span style="color: #00F;">/</span>
<span style="color: #00F;">DECLARE</span>
<span style="color: #00F;">*</span>
ERROR <span style="color: #00F;">AT</span> line <span style="color: #800;">1</span><span style="color: #00F;">:</span>
ORA<span style="color: #00F;">-</span>01722<span style="color: #00F;">:</span> invalid <span style="color: #00F;">NUMBER</span>
ORA<span style="color: #00F;">-</span>06512<span style="color: #00F;">:</span> <span style="color: #00F;">AT</span> line <span style="color: #800;">4</span></pre></td></tr></table></div>

<p>&#8230;or, in addition to the standard exception pragma, we can provide a more descriptive exception to the calling program, such as java by adding a pragma to a custom package&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="plsql" style="font-family:monospace;">SQL<span style="color: #00F;">&gt;</span> <span style="color: #00F;">CREATE</span> <span style="color: #00F;">OR</span> <span style="color: #000;">REPLACE</span> <span style="color: #00F;">PACKAGE</span> my_exceptions <span style="color: #00F;">IS</span>
  <span style="color: #800;">2</span>    invalid_customer_id <span style="color: #00F;">EXCEPTION</span><span style="color: #00F;">;</span>
  <span style="color: #800;">3</span>    <span style="color: #00F;">PRAGMA</span> exception_init<span style="color: #00F;">&#40;</span>invalid_customer_id<span style="color: #00F;">,-</span><span style="color: #800;">1722</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">;</span>
  <span style="color: #800;">4</span>  <span style="color: #00F;">END</span><span style="color: #00F;">;</span>
  <span style="color: #800;">5</span>  <span style="color: #00F;">/</span>
&nbsp;
<span style="color: #00F;">PACKAGE</span> created<span style="color: #00F;">.</span></pre></td></tr></table></div>

<p>&#8230;and use our custom exception definition from our program by doing something like what is below:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="plsql" style="font-family:monospace;">SQL<span style="color: #00F;">&gt;</span> <span style="color: #00F;">DECLARE</span>
  <span style="color: #800;">2</span>    customer_id <span style="color: #00F;">NUMBER</span><span style="color: #00F;">;</span>
  <span style="color: #800;">3</span>  <span style="color: #00F;">BEGIN</span>
  <span style="color: #800;">4</span>    <span style="color: #00F;">SELECT</span> c <span style="color: #00F;">INTO</span> customer_id <span style="color: #00F;">FROM</span> t0909 <span style="color: #00F;">WHERE</span> c <span style="color: #00F;">=</span> <span style="color: #F00;">'a'</span><span style="color: #00F;">;</span>
  <span style="color: #800;">5</span>  <span style="color: #00F;">EXCEPTION</span>
  <span style="color: #800;">6</span>    <span style="color: #00F;">WHEN</span> my_exceptions<span style="color: #00F;">.</span>invalid_customer_id <span style="color: #00F;">THEN</span>
  <span style="color: #800;">7</span>      <span style="color: #00F;">DBMS_OUTPUT</span><span style="color: #00F;">.</span>put_line<span style="color: #00F;">&#40;</span><span style="color: #F00;">'Please ensure you search using a valid numeric customer_id.'</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">;</span>
  <span style="color: #800;">8</span>  <span style="color: #00F;">END</span><span style="color: #00F;">;</span>
  <span style="color: #800;">9</span>  <span style="color: #00F;">/</span>
Please ensure you search using a valid numeric customer_id<span style="color: #00F;">.</span>
&nbsp;
PL<span style="color: #00F;">/</span><span style="color: #00F;">SQL</span> <span style="color: #00F;">PROCEDURE</span> successfully completed<span style="color: #00F;">.</span>
&nbsp;
SQL<span style="color: #00F;">&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://appcrawler.com/wordpress/2012/01/06/standard-exception-pragmas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extracting SCN range from an online redo log or archived redo log</title>
		<link>http://appcrawler.com/wordpress/2011/12/31/extracting-scn-range-from-an-online-redo-log-or-archived-redo-log/</link>
		<comments>http://appcrawler.com/wordpress/2011/12/31/extracting-scn-range-from-an-online-redo-log-or-archived-redo-log/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 02:19:46 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Shell scripting]]></category>

		<guid isPermaLink="false">http://appcrawler.com/wordpress/?p=1859</guid>
		<description><![CDATA[I can&#8217;t imagine that this would be useful in a well managed system, but if you find yourself with a &#8220;raw&#8221; log file that is not in the dictionary, you can at least extract the SCN range it encompasses using what is below. [oracle@dell11gr1 ~]$ awk --version GNU Awk 3.1.5 Copyright (C) 1989, 1991-2005 Free [...]]]></description>
			<content:encoded><![CDATA[<p>I can&#8217;t imagine that this would be useful in a well managed system, but if you find yourself with a &#8220;raw&#8221; log file that is not in the dictionary, you can at least extract the SCN range it encompasses using what is below.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">[oracle@dell11gr1 ~]$ awk --version
GNU Awk 3.1.5
Copyright (C) 1989, 1991-2005 Free Software Foundation.
&nbsp;
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
&nbsp;
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
&nbsp;
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
[oracle@dell11gr1 ~]$ strings -a arch1.arc | head -20 | grep SCN | awk -F &quot;,&quot; '{split($3,t,&quot; &quot;);split(t[2],t2,&quot;-&quot;);printf(&quot;Start SCN = %d, End SCN = %d\n&quot;,strtonum(t2[1]),strtonum(t2[2]))}'
Start SCN = 5345720, End SCN = 5350856
[oracle@dell11gr1 ~]$</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://appcrawler.com/wordpress/2011/12/31/extracting-scn-range-from-an-online-redo-log-or-archived-redo-log/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

