<?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>I&#039;m CaLendarW Blog &#187; oracle</title>
	<atom:link href="http://wongkalun.idv.hk/tag/oracle/feed/" rel="self" type="application/rss+xml" />
	<link>http://wongkalun.idv.hk</link>
	<description>Put the technology in correct places</description>
	<lastBuildDate>Sun, 18 Apr 2010 16:19:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Create Trigger to Run Jar using Shell in Oracle 10g</title>
		<link>http://wongkalun.idv.hk/2008/03/14/create-trigger-to-run-shell-in-oracle-10g/</link>
		<comments>http://wongkalun.idv.hk/2008/03/14/create-trigger-to-run-shell-in-oracle-10g/#comments</comments>
		<pubDate>Fri, 14 Mar 2008 08:49:38 +0000</pubDate>
		<dc:creator>calendarw</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[oracle]]></category>

		<guid isPermaLink="false">http://wongkalun.idv.hk/?p=31</guid>
		<description><![CDATA[First login to sys and grant the permission in sqlplus EXEC dbms_java.grant_permission('ABC', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', ''); EXEC dbms_java.grant_permission('ABC', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', ''); EXEC dbms_java.grant_permission('ABC', 'SYS:java.io.FilePermission', '/bin/sh', 'execute'); And then, login to ABC and create java in sqlplus: CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED &#34;Host&#34; AS import java.io.*; public class Host { public static void executeCommand(String [...]]]></description>
			<content:encoded><![CDATA[<p>First login to sys and grant the permission in sqlplus</p>
<pre class="brush: sql;">
EXEC dbms_java.grant_permission('ABC', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
EXEC dbms_java.grant_permission('ABC', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
EXEC dbms_java.grant_permission('ABC', 'SYS:java.io.FilePermission', '/bin/sh', 'execute');
</pre>
<p>And then, login to ABC and create java in sqlplus:</p>
<pre class="brush: java;">CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED &quot;Host&quot; AS
import java.io.*;
public class Host {
  public static void executeCommand(String command) {
    try {
      String[] finalCommand;
      if (System.getProperty(&quot;os.name&quot;).toLowerCase().indexOf(&quot;windows&quot;) != -1) {
        finalCommand = new String[4];
        finalCommand[0] = &quot;C:\\winnt\\system32\\cmd.exe&quot;;
        finalCommand[1] = &quot;/y&quot;;
        finalCommand[2] = &quot;/c&quot;;
        finalCommand[3] = command;
      } else {
	// Linux or Unix System
        finalCommand = new String[3];
        finalCommand[0] = &quot;/bin/sh&quot;;
        finalCommand[1] = &quot;-c&quot;;
        finalCommand[2] = command;
      }

      // Execute the command...
      final Process pr = Runtime.getRuntime().exec(finalCommand);

      // Capture output from STDOUT...
      BufferedReader br_in = null;
      try {
        br_in = new BufferedReader(
            new InputStreamReader(pr.getInputStream()));
        String buff = null;
        while ((buff = br_in.readLine()) != null) {
          System.out.println(&quot;stdout: &quot; + buff);
          try {Thread.sleep(100); } catch(Exception e) {}
        }
        br_in.close();
      } catch (IOException ioe) {
        System.out.println(&quot;Error printing process output.&quot;);
        ioe.printStackTrace();
      } finally {
        try {
          br_in.close();
        } catch (Exception ex) {}
      }

      // Capture output from STDERR...
      BufferedReader br_err = null;
      try {
        br_err = new BufferedReader(
            new InputStreamReader(pr.getErrorStream()));
        String buff = null;
        while ((buff = br_err.readLine()) != null) {
          System.out.println(&quot;stderr: &quot; + buff);
          try {Thread.sleep(100); } catch(Exception e) {}
        }
        br_err.close();
      } catch (IOException ioe) {
        System.out.println(&quot;Error printing execution errors.&quot;);
        ioe.printStackTrace();
      } finally {
        try {
          br_err.close();
        } catch (Exception ex) {}
      }
    }
    catch (Exception ex) {
      System.out.println(ex.getLocalizedMessage());
    }
  }
};
</pre>
<p>after that, create procedure in sqlplus:</p>
<pre class="brush: sql;">CREATE OR REPLACE PROCEDURE host (p_command IN VARCHAR2)
   AS LANGUAGE JAVA
   NAME 'Host.executeCommand (java.lang.String)';
</pre>
<p>set the output display if neccessary in sqlplus:</p>
<pre class="brush: sql;">CALL DBMS_JAVA.SET_OUTPUT(1000000);
SET SERVEROUTPUT ON</pre>
<p>You can test the procedure using following command:</p>
<pre class="brush: sql;">exec host('/bin/ls');</pre>
<p>Create a sh file in linux:</p>
<pre class="brush: bash;">#!/bin/bash
source /home/abc/.bash_profile
cd /home/abc
java -jar /home/abc/abc.jar
</pre>
<p>Remember to change mode in linux:</p>
<pre class="brush: bash;">chmod a+x /home/abc/run.sh</pre>
<p>Finally, create the trigger:</p>
<pre class="brush: bash;">
create or replace trigger abc_run
after update on abc.testing
begin host('/home/abc/run.sh');
end;
</pre>
<pre class="brush: sql;">commit;</pre>
<p>Reference: <a href="http://www.orafaq.com/wiki/PL/SQL_FAQ">Ref1</a> <a href="http://www.orafaq.com/scripts/plsql/oscmd.txt">Ref2</a></p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-enjoy">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://wongkalun.idv.hk/2008/03/14/create-trigger-to-run-shell-in-oracle-10g/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://wongkalun.idv.hk/2008/03/14/create-trigger-to-run-shell-in-oracle-10g/&amp;title=Create+Trigger+to+Run+Jar+using+Shell+in+Oracle+10g" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://wongkalun.idv.hk/2008/03/14/create-trigger-to-run-shell-in-oracle-10g/&amp;title=Create+Trigger+to+Run+Jar+using+Shell+in+Oracle+10g" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://wongkalun.idv.hk/2008/03/14/create-trigger-to-run-shell-in-oracle-10g/&amp;title=Create+Trigger+to+Run+Jar+using+Shell+in+Oracle+10g&amp;desc=First%20login%20to%20sys%20and%20grant%20the%20permission%20in%20sqlplus%0D%0A%5Bsql%5D%0D%0AEXEC%20dbms_java.grant_permission%28%27ABC%27%2C%20%27SYS%3Ajava.lang.RuntimePermission%27%2C%20%27writeFileDescriptor%27%2C%20%27%27%29%3B%0D%0AEXEC%20dbms_java.grant_permission%28%27ABC%27%2C%20%27SYS%3Ajava.lang.RuntimePermission%27%2C%20%27readFileDescriptor%27%2C%20%27%27%29%3B%0D%0AEXEC%20dbms_java.grant_permission%28" rel="nofollow" class="external" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://wongkalun.idv.hk/2008/03/14/create-trigger-to-run-shell-in-oracle-10g/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-misterwong">
			<a href="http://www.mister-wong.com/addurl/?bm_url=http://wongkalun.idv.hk/2008/03/14/create-trigger-to-run-shell-in-oracle-10g/&amp;bm_description=Create+Trigger+to+Run+Jar+using+Shell+in+Oracle+10g&amp;plugin=sexybookmarks" rel="nofollow" class="external" title="Add this to Mister Wong">Add this to Mister Wong</a>
		</li>
		<li class="shr-mixx">
			<a href="http://www.mixx.com/submit?page_url=http://wongkalun.idv.hk/2008/03/14/create-trigger-to-run-shell-in-oracle-10g/&amp;title=Create+Trigger+to+Run+Jar+using+Shell+in+Oracle+10g" rel="nofollow" class="external" title="Share this on Mixx">Share this on Mixx</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://wongkalun.idv.hk/2008/03/14/create-trigger-to-run-shell-in-oracle-10g/&amp;title=Create+Trigger+to+Run+Jar+using+Shell+in+Oracle+10g" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://wongkalun.idv.hk/2008/03/14/create-trigger-to-run-shell-in-oracle-10g/&amp;title=Create+Trigger+to+Run+Jar+using+Shell+in+Oracle+10g" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://wongkalun.idv.hk/2008/03/14/create-trigger-to-run-shell-in-oracle-10g/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Create+Trigger+to+Run+Jar+using+Shell+in+Oracle+10g+-+http://bit.ly/b1xNCq&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>




		<!-- Added by WP-DragToShare-eXtended Plugin -->
		<script type="text/javascript">
			dtsv.dtse_post_31_permalink = 'http://wongkalun.idv.hk/2008/03/14/create-trigger-to-run-shell-in-oracle-10g/';
			dtsv.dtse_post_31_title = 'Create Trigger to Run Jar using Shell in Oracle 10g';
		</script>
		<!-- End of WP-DragToShare-eXtended Plugin -->]]></content:encoded>
			<wfw:commentRss>http://wongkalun.idv.hk/2008/03/14/create-trigger-to-run-shell-in-oracle-10g/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle Notes</title>
		<link>http://wongkalun.idv.hk/2008/03/14/oracle-notes/</link>
		<comments>http://wongkalun.idv.hk/2008/03/14/oracle-notes/#comments</comments>
		<pubDate>Fri, 14 Mar 2008 02:35:07 +0000</pubDate>
		<dc:creator>calendarw</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[oracle]]></category>

		<guid isPermaLink="false">http://wongkalun.idv.hk/?p=30</guid>
		<description><![CDATA[Run shell in sqlplus: host ls -l or !ls -l Dummy Table Name: dual Get user error message in oracle: select * from user_errors; or show errors; ERROR: PLS-00201: identifier &#8216;SYS.DBMS_PIPE&#8217; must be declared Connect to the SYS schema and issue the following command: grant all on dbms_pipe to public; Subscribe to the comments for [...]]]></description>
			<content:encoded><![CDATA[<p>Run shell in sqlplus:</p>
<pre class="brush: sql;">host ls -l</pre>
<p>or</p>
<pre class="brush: sql;">!ls -l</pre>
<p>Dummy Table Name: dual</p>
<p>Get user error message in oracle:</p>
<pre class="brush: sql;">select * from user_errors;</pre>
<p>or</p>
<pre class="brush: sql;">show errors;</pre>
<p>ERROR: PLS-00201: identifier &#8216;SYS.DBMS_PIPE&#8217; must be declared<br />
Connect to the SYS schema and issue the following command:</p>
<pre class="brush: sql;">grant all on dbms_pipe to public;</pre>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-enjoy">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://wongkalun.idv.hk/2008/03/14/oracle-notes/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://wongkalun.idv.hk/2008/03/14/oracle-notes/&amp;title=Oracle+Notes" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://wongkalun.idv.hk/2008/03/14/oracle-notes/&amp;title=Oracle+Notes" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://wongkalun.idv.hk/2008/03/14/oracle-notes/&amp;title=Oracle+Notes&amp;desc=Run%20shell%20in%20sqlplus%3A%0D%0A%5Bsql%5Dhost%20ls%20-l%5B%2Fsql%5D%0D%0Aor%0D%0A%5Bsql%5D%21ls%20-l%5B%2Fsql%5D%0D%0ADummy%20Table%20Name%3A%20dual%0D%0A%0D%0AGet%20user%20error%20message%20in%20oracle%3A%0D%0A%5Bsql%5Dselect%20%2A%20from%20user_errors%3B%5B%2Fsql%5D%0D%0Aor%0D%0A%5Bsql%5Dshow%20errors%3B%5B%2Fsql%5D%0D%0AERROR%3A%20PLS-00201%3A%20identifier%20%27SYS.DBMS_PIPE%27%20must%20be%20declared%0D%0AConnect%20to%20the%20SYS%20schema%20and%20issue%20the" rel="nofollow" class="external" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://wongkalun.idv.hk/2008/03/14/oracle-notes/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-misterwong">
			<a href="http://www.mister-wong.com/addurl/?bm_url=http://wongkalun.idv.hk/2008/03/14/oracle-notes/&amp;bm_description=Oracle+Notes&amp;plugin=sexybookmarks" rel="nofollow" class="external" title="Add this to Mister Wong">Add this to Mister Wong</a>
		</li>
		<li class="shr-mixx">
			<a href="http://www.mixx.com/submit?page_url=http://wongkalun.idv.hk/2008/03/14/oracle-notes/&amp;title=Oracle+Notes" rel="nofollow" class="external" title="Share this on Mixx">Share this on Mixx</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://wongkalun.idv.hk/2008/03/14/oracle-notes/&amp;title=Oracle+Notes" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://wongkalun.idv.hk/2008/03/14/oracle-notes/&amp;title=Oracle+Notes" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://wongkalun.idv.hk/2008/03/14/oracle-notes/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Oracle+Notes+-+http://bit.ly/9k1I02&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>




		<!-- Added by WP-DragToShare-eXtended Plugin -->
		<script type="text/javascript">
			dtsv.dtse_post_30_permalink = 'http://wongkalun.idv.hk/2008/03/14/oracle-notes/';
			dtsv.dtse_post_30_title = 'Oracle Notes';
		</script>
		<!-- End of WP-DragToShare-eXtended Plugin -->]]></content:encoded>
			<wfw:commentRss>http://wongkalun.idv.hk/2008/03/14/oracle-notes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
