<?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>Technology Articles &#187; PL/SQL</title>
	<atom:link href="http://technologydribble.info/category/oracle/plsql/feed/" rel="self" type="application/rss+xml" />
	<link>http://technologydribble.info</link>
	<description>Articles About Technology</description>
	<lastBuildDate>Fri, 27 Apr 2012 23:52:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Getting Session Environment Parameters in Oracle</title>
		<link>http://technologydribble.info/2011/02/11/getting-session-environment-parameters-in-oracle/</link>
		<comments>http://technologydribble.info/2011/02/11/getting-session-environment-parameters-in-oracle/#comments</comments>
		<pubDate>Fri, 11 Feb 2011 05:49:01 +0000</pubDate>
		<dc:creator>ryelpango</dc:creator>
				<category><![CDATA[ApEx]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PL/SQL]]></category>
		<category><![CDATA[environment variables]]></category>
		<category><![CDATA[get_cgi_env]]></category>
		<category><![CDATA[OWA_UTIL]]></category>
		<category><![CDATA[parameters]]></category>

		<guid isPermaLink="false">http://technologydribble.info/?p=314</guid>
		<description><![CDATA[To display all environment variable values for a given oracle session, run the following code: begin FOR i IN 1..owa.num_cgi_vars LOOP htp.p(owa.cgi_var_name(i)&#124;&#124;' : '&#124;&#124;owa.cgi_var_val(i)); END LOOP; end; The name of the environment variable and value will be displayed. To reference each variable individually use the following syntax: OWA_UTIL.get_cgi_env(VARIABLE_NAME) eg. OWA_UTIL.get_cgi_env('REQUEST_PROTOCOL') Here&#8217;s the list of all [...]]]></description>
			<content:encoded><![CDATA[<p>To display all environment variable values for a given oracle session, run the following code:</p>
<p><code>begin<br />
  FOR i IN 1..owa.num_cgi_vars LOOP<br />
    htp.p(owa.cgi_var_name(i)||' : '||owa.cgi_var_val(i));<br />
  END LOOP;<br />
end;</code></p>
<p>The name of the environment variable and value will be displayed. To reference each variable individually use the following syntax:</p>
<p><code>OWA_UTIL.get_cgi_env(<em>VARIABLE_NAME</em>) </p>
<p>eg. OWA_UTIL.get_cgi_env('REQUEST_PROTOCOL')</code></p>
<p>Here&#8217;s the list of all available variables:</p>
<p><code>PLSQL_GATEWAY<br />
GATEWAY_IVERSION<br />
SERVER_SOFTWARE<br />
GATEWAY_INTERFACE<br />
SERVER_PORT<br />
SERVER_NAME<br />
REQUEST_METHOD<br />
PATH_INFO<br />
SCRIPT_NAME<br />
REMOTE_ADDR<br />
SERVER_PROTOCOL<br />
REQUEST_PROTOCOL<br />
REMOTE_USER<br />
HTTP_CONTENT_LENGTH<br />
HTTP_CONTENT_TYPE<br />
HTTP_USER_AGENT<br />
HTTP_HOST<br />
HTTP_ACCEPT<br />
HTTP_ACCEPT_ENCODING<br />
HTTP_ACCEPT_LANGUAGE<br />
HTTP_REFERER<br />
HTTP_ORACLE_ECID<br />
WEB_AUTHENT_PREFIX<br />
DAD_NAME<br />
DOC_ACCESS_PATH<br />
DOCUMENT_TABLE<br />
PATH_ALIAS<br />
REQUEST_CHARSET<br />
REQUEST_IANA_CHARSET<br />
SCRIPT_PREFIX<br />
HTTP_COOKIE</code></p>
<p>Sample Output:</p>
<p><code>PLSQL_GATEWAY : WebDb<br />
GATEWAY_IVERSION : 3<br />
SERVER_SOFTWARE : Oracle-Application-Server-10g/10.1.2.0.0 Oracle-HTTP-Server<br />
GATEWAY_INTERFACE : CGI/1.1<br />
SERVER_PORT : 7780<br />
SERVER_NAME : lxapp0533v<br />
REQUEST_METHOD : POST<br />
PATH_INFO : /wwv_flow.show<br />
SCRIPT_NAME : /pls/dmt<br />
REMOTE_ADDR : 148.132.152.59<br />
SERVER_PROTOCOL : HTTP/1.1<br />
REQUEST_PROTOCOL : HTTP<br />
REMOTE_USER : APEX_PUBLIC_USER<br />
HTTP_CONTENT_LENGTH : 416<br />
HTTP_CONTENT_TYPE : application/x-www-form-urlencoded<br />
HTTP_USER_AGENT : Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)<br />
HTTP_HOST : lxapp0533v.in.telstra.com.au:7780<br />
HTTP_ACCEPT : */*<br />
HTTP_ACCEPT_ENCODING : gzip, deflate<br />
HTTP_ACCEPT_LANGUAGE : en-au<br />
HTTP_REFERER : http://lxapp0533v.in.telstra.com.au:7780/pls/dmt/f?p=4500:1003:4479870342920497::NO:::<br />
HTTP_ORACLE_ECID : 1297402712:144.135.172.44:22243:0:21186,0<br />
WEB_AUTHENT_PREFIX :<br />
DAD_NAME : dmt<br />
DOC_ACCESS_PATH : docs<br />
DOCUMENT_TABLE : wwv_flow_file_objects$<br />
PATH_ALIAS :<br />
REQUEST_CHARSET : UTF8<br />
REQUEST_IANA_CHARSET : UTF-8<br />
SCRIPT_PREFIX : /pls<br />
HTTP_COOKIE : ISCOOKIE=true; LOGIN_USERNAME_COOKIE=d205414; LOGIN_PASSWORD_COOKIE=; LOGIN_REMEMBER_ME_COOKIE=; r1=%23ALL; r2=%23ALL; r3=%23ALL; propHide=4301%2C%23ALL; WWV_FLOW_USER2=47770A7FD83D3E0A; ORACLE_PLATFORM_REMEMBER_UN=D205414:dmt; __ppFullPath=di-di; s_nr=1296902947468; s_evar18=%5B%5B%27referral%27%2C%271296902515781%27%5D%5D; SearchSettings=50,0,0,1,1,1,1,1; HTMLDB_IDLE_SESSION=11-FEB-2011 10:22:00; WWV_CUSTOM-F_955908081711180_100=739B959ED77BAFE2</code></p>
]]></content:encoded>
			<wfw:commentRss>http://technologydribble.info/2011/02/11/getting-session-environment-parameters-in-oracle/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Loading a File Into a BLOB Object in Oracle</title>
		<link>http://technologydribble.info/2009/08/18/loading-a-file-into-a-blob-object-in-oracle/</link>
		<comments>http://technologydribble.info/2009/08/18/loading-a-file-into-a-blob-object-in-oracle/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 22:57:34 +0000</pubDate>
		<dc:creator>ryelpango</dc:creator>
				<category><![CDATA[BLOB]]></category>
		<category><![CDATA[Load File Into BLOB]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PL/SQL]]></category>
		<category><![CDATA[Load BLOB from File]]></category>
		<category><![CDATA[Write BLOB from OS File]]></category>

		<guid isPermaLink="false">http://technologydribble.info/?p=142</guid>
		<description><![CDATA[Loading a file into a BLOB object in Oracle is easy. All we need to do is use the DBMS_LOB package to load the file into a temporary LOB object. This is demonstrated in the following example. This example assumes that you have a directory object set up where the files are stored. In this [...]]]></description>
			<content:encoded><![CDATA[<p>Loading a file into a BLOB object in Oracle is easy. All we need to do is use the DBMS_LOB package to load the file into a temporary LOB object. This is demonstrated in the following example.</p>
<p>This example assumes that you have a directory object set up where the files are stored. In this example the following object is used:</p>
<p><code>CREATE DIRECTORY FILEUPLOADS AS '/home_new/dmt/public_html/fileuploads';</code></p>
<p>Use the following function to load a file based on the filename parameter and return the BLOB reference for processing:</p>
<pre>

CREATE OR REPLACE FUNCTION loadBlobFromFile(p_file_name VARCHAR2) RETURN BLOB AS
  dest_loc  BLOB := empty_blob();
  src_loc   BFILE := BFILENAME('FILEUPLOADS', p_file_name);
BEGIN
  -- Open source binary file from OS
  DBMS_LOB.OPEN(src_loc, DBMS_LOB.LOB_READONLY);

  -- Create temporary LOB object
  DBMS_LOB.CREATETEMPORARY(
        lob_loc => dest_loc
      , cache   => true
      , dur     => dbms_lob.session
  );

  -- Open temporary lob
  DBMS_LOB.OPEN(dest_loc, DBMS_LOB.LOB_READWRITE);

  -- Load binary file into temporary LOB
  DBMS_LOB.LOADFROMFILE(
        dest_lob => dest_loc
      , src_lob  => src_loc
      , amount   => DBMS_LOB.getLength(src_loc));

  -- Close lob objects
  DBMS_LOB.CLOSE(dest_loc);
  DBMS_LOB.CLOSE(src_loc);

  -- Return temporary LOB object
  RETURN dest_loc;
END loadBlobFromFile;
/
</pre>
<p>Easy as that.</p>
]]></content:encoded>
			<wfw:commentRss>http://technologydribble.info/2009/08/18/loading-a-file-into-a-blob-object-in-oracle/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Improving Performance of Your Oracle Application Express Software</title>
		<link>http://technologydribble.info/2009/02/04/improving-performance-of-your-oracle-application-express-software/</link>
		<comments>http://technologydribble.info/2009/02/04/improving-performance-of-your-oracle-application-express-software/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 01:40:49 +0000</pubDate>
		<dc:creator>ryelpango</dc:creator>
				<category><![CDATA[ApEx]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PL/SQL]]></category>
		<category><![CDATA[Application Express]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://technologydribble.info/?p=37</guid>
		<description><![CDATA[I am writing this article with the thread http://forums.oracle.com/forums/thread.jspa?messageID=3205216&#38;#3205216 in mind. We have a very large workflow application written in Oracle Application Express, supporting some 3000+ users. This application was written with care, for obvious reasons. Well for one, it&#8217;s written in Application Express, a rapid development tool which is not designed for an application [...]]]></description>
			<content:encoded><![CDATA[<p>I am writing this article with the thread <a href="http://forums.oracle.com/forums/thread.jspa?messageID=3205216&amp;#3205216">http://forums.oracle.com/forums/thread.jspa?messageID=3205216&amp;#3205216</a> in mind. We have a very large workflow application written in Oracle Application Express, supporting some 3000+ users. This application was written with care, for obvious reasons. Well for one, it&#8217;s written in Application Express, a rapid development tool which is not designed for an application of this magnitude (80+ hits per second, 15 hours a day)! Every condition, expression, process is held in pre-compiled Oracle packages/procedure/functions in order to minimize latching and thus improve performance.</p>
<p>All is well until the application hits peak periods, which is when our CPU was 100% busy all the time. It remained a mystery for about two years until a few days ago. For two years I&#8217;ve searched high and low for an answer, because our application has been optimized from top to bottom. We knew what was causing the problem, it is the dreaded PL/SQL block below:</p>
<pre>declare
 rc__ number;
 simple_list__ owa_util.vc_arr;
 complex_list__ owa_util.vc_arr;
begin
 owa.init_cgi_env(:n__,:nm__,:v__);
 htp.HTBUF_LEN := 255;
 null;
 null;
 simple_list__(1) := 'sys.%';
 simple_list__(2) := 'dbms\_%';
 simple_list__(3) := 'utl\_%';
 simple_list__(4) := 'owa\_%';
 simple_list__(5) := 'owa.%';
 simple_list__(6) := 'htp.%';
 simple_list__(7) := 'htf.%';
 simple_list__(8) := 'wpg_docload.%';
 if ((owa_match.match_pattern('f', simple_list__, complex_list__, true))) then
  rc__ := 2;
 else
  null;
  null;
  f(p=&gt;:p);
  if (wpg_docload.is_file_download) then
   rc__ := 1;
   wpg_docload.get_download_file(:doc_info);
   null;
   null;
   null;
   commit;
  else
   rc__ := 0;
   null;
   null;
   null;
   commit;
   owa.get_page(:data__,:ndata__);
  end if;
 end if;
 :rc__ := rc__;
end;</pre>
<p>The dreaded PL/SQL block above was called about 7,000 times in an hour and consumes 58% of the CPU load in our system (see stats below)!</p>
<pre>CPU Elapsed CPU per % Total
Time (s) Time (s) Executions Exec (s) DB Time SQL Id
---------- ---------- ------------ ----------- ------- -------------
4,014 19,928 6,686 0.60 58.2 c34r978mgkrmf</pre>
<p>For two years I could not find the answer. I&#8217;ve seen similar problems experienced by other people but it was dismissed as an expected behaviour by Oracle (see &#8220;Performance degradation is the expected behavior&#8221; <a href="http://forums.oracle.com/forums/thread.jspa?messageID=3205216&amp;#3205216">http://forums.oracle.com/forums/thread.jspa?messageID=3205216&amp;#3205216</a>). Our DBA hassled me again last week advising that I enhance our application in order to reduce the number of calls to the dreaded SQL. I told him that I did not know when the block of code was called and advised that the only way I could even have a remote chance in finding it, I would need access to HTTP logs as well as database logs. Even Oracle Ace sspadafo said &#8220;That looks like the anonymous block built by modplsql to handle the form POST&#8221;.</p>
<p>Equipped with renewed vigour to find a solution the problem, our DBA went away and &#8220;reversed engineed&#8221; the problem so that a solution can be found once and for all! He got back to me a few days later with this email:</p>
<hr /><code>Ariel,I did a bit reverse engineer on this internal ApEx API. The core of this API is part of OWA. The related OWA is inside package wpg_docload. The source code of wpg_docload is at $ORACLE_HOME/rdbms/admin/wpgdocs.sql.</p>
<p>Whenever the end-users download a file (images, word docus, etc.), the wpg_docload is called. Obviously we call it too frequently and causes a big performance problem.</p>
<p>For example, between 14:00pm and 15:00pm yesterday, we fetched more than 3000 times for each of the files below:<br />
[oracle@puma-c-app-00 logs]$ grep access.gif junk2 | wc -l<br />
3777<br />
[oracle@puma-c-app-00 logs]$ grep bug.gif junk2 | wc -l<br />
3731<br />
[oracle@puma-c-app-00 logs]$ grep change.gif junk2 | wc -l<br />
3360<br />
[oracle@puma-c-app-00 logs]$ grep dmt1.jpg junk2 | wc -l<br />
3595<br />
[oracle@puma-c-app-00 logs]$ grep dmt2.jpg junk2 | wc -l<br />
4006<br />
[oracle@puma-c-app-00 logs]$ grep dmt3.jpg junk2 | wc -l<br />
3813<br />
[oracle@puma-c-app-00 logs]$ grep dot.gif junk2 | wc -l<br />
3140<br />
[oracle@puma-c-app-00 logs]$ grep htmldb_remix.js junk2 | wc -l<br />
3729<br />
[oracle@puma-c-app-00 logs]$ grep theme.css junk2 | wc -l<br />
3952<br />
[oracle@puma-c-app-00 logs]$ grep whats_new.gif junk2 | wc -l<br />
3538</p>
<p>We have 2 AppServers, so the real fetches are twice. On average, they are accessed 20 times per second!</p>
<p>Because only one CPU can access a particular RAM address at a given time, all other CPUs have to wait. This kind of issues can't be resolved by big/better hardware. The more powerful of the host, the worse it gets. For 4 CPUs, 3 have to wait. For 8 CPUs, 7 have to wait, For 16 CPU, 15 have to wait. While the CPUs are waiting, they are spinning (controlled by a hidden parameter _spin_count in Oracle). Spinning means using 100% CPU doing nothing! This is why your host is always busy.</p>
<p>The solution is to move the above images from database tier to middle tier.</p>
<p>When the image is fetched from database, the PC can't cache it because the PC does not know if the file has changed since last fetch. (If you read the source code I mentioned above, you will see actually Oracle is fully aware of this problem in 1999/2000)</p>
<p>When the image is fetched from Apache, it will be cached in the PC's RAM until the file on Apache server is changed.</p>
<p>After we move the above images into Apache, we will never need to run the culprit API to fetch these files, the workload on database tier will be reduced dramatically. As the images are cached in the PC's RAM, the workload on middle tier will be reduced largely as well.</p>
<p>What do you think?</p>
<p>Cheers,<br />
Han</p>
<p></code></p>
<hr />The revelation hit me like a lightning bolt! I&#8217;ve been looking in the wrong place! All this time I&#8217;ve been targetting expressions, conditions, computations, processes etc. I never thought to look in Shared Components -&gt; Templates to optimize the application! Who would? Right? Templates control the look and feel of the application (stylesheets, images, themes, etc.), it should contain minimal database calls, right?</p>
<p>Not so with Oracle Application Express. Well, every image you store in Shared Components -&gt; Images are only accessed through a database call specified below:</p>
<pre>wwv_flow_file_mgr.get_file?p_security_group_id=923024072426648&amp;p_fname=[FILE_NAME]</pre>
<p>You reference these images through the page template through a substitution string eg.:</p>
<pre>&lt;script src="#COMPANY_IMAGES#htmldb remix. js" type="text/javascript"&gt;&lt;/script&gt;
&lt;img src="#COMPANY_IMAGES#sample_picture.jpg" alt="sample picture /&gt;
<script src="#COMPANY_IMAGES#htmldb remix. js" type="text/javascript"><!--mce:0--></script></pre>
<p>When the image or js is fetched from the database, the client can&#8217;t cache it because the client computer does not know if the file has changed since the last fetch. Therefore if you got hundreds of these images on your page, it would mean that you would call the &#8220;dreaded code&#8221; hundreds of times!</p>
<p>After this information was revealed to me by our brilliant DBA, the fix was simple. Move all images and js source from the database to a web server. Change all references #COMPANY_IMAGES# (sometimes referred to as #WORKSPACE_IMAGES# on some installation) in the page templates.</p>
<p>The performance improvement was almost instant! Within an hour the CPU usage on our system dropped by 40%! Here are the stats:</p>
<table style="width: 318pt; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0" width="424">
<colgroup span="1">
<col style="width: 114pt; mso-width-source: userset; mso-width-alt: 5558;" span="1" width="152"></col>
<col style="width: 105pt; mso-width-source: userset; mso-width-alt: 5120;" span="1" width="140"></col>
<col style="width: 99pt; mso-width-source: userset; mso-width-alt: 4827;" span="1" width="132"></col>
</colgroup>
<tbody>
<tr style="height: 12.75pt;" height="17">
<td style="width: 114pt; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="152" height="17"><span style="font-size: x-small; font-family: Arial;">CPU Usage</span></td>
<td style="width: 105pt; background-color: transparent; border: #ece9d8;" width="140"><span style="font-size: x-small; font-family: Arial;">Date and Time (Today)</span></td>
<td style="width: 99pt; background-color: transparent; border: #ece9d8;" width="132"><span style="font-size: x-small; font-family: Arial;">Percentage reduction</span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8;" height="17" align="right"><span style="font-size: x-small; font-family: Arial;">683970966</span></td>
<td style="background-color: transparent; border: #ece9d8;"><span style="font-size: x-small; font-family: Arial;">09/02/05 00</span></td>
<td style="background-color: transparent; border: #ece9d8;" align="right"><span style="font-size: x-small; font-family: Arial;">11.32</span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8;" height="17" align="right"><span style="font-size: x-small; font-family: Arial;">703065671</span></td>
<td style="background-color: transparent; border: #ece9d8;"><span style="font-size: x-small; font-family: Arial;">09/02/05 01</span></td>
<td style="background-color: transparent; border: #ece9d8;" align="right"><span style="font-size: x-small; font-family: Arial;">10.93</span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8;" height="17" align="right"><span style="font-size: x-small; font-family: Arial;">709172691</span></td>
<td style="background-color: transparent; border: #ece9d8;"><span style="font-size: x-small; font-family: Arial;">09/02/05 02</span></td>
<td style="background-color: transparent; border: #ece9d8;" align="right"><span style="font-size: x-small; font-family: Arial;">11.36</span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8;" height="17" align="right"><span style="font-size: x-small; font-family: Arial;">711003880</span></td>
<td style="background-color: transparent; border: #ece9d8;"><span style="font-size: x-small; font-family: Arial;">09/02/05 03</span></td>
<td style="background-color: transparent; border: #ece9d8;" align="right"><span style="font-size: x-small; font-family: Arial;">11.37</span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8;" height="17" align="right"><span style="font-size: x-small; font-family: Arial;">369238</span></td>
<td style="background-color: transparent; border: #ece9d8;"><span style="font-size: x-small; font-family: Arial;">09/02/05 04</span></td>
<td style="background-color: transparent; border: #ece9d8;" align="right"><span style="font-size: x-small; font-family: Arial;">19.83</span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8;" height="17" align="right"><span style="font-size: x-small; font-family: Arial;">6961506</span></td>
<td style="background-color: transparent; border: #ece9d8;"><span style="font-size: x-small; font-family: Arial;">09/02/05 05</span></td>
<td style="background-color: transparent; border: #ece9d8;" align="right"><span style="font-size: x-small; font-family: Arial;">25.88</span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8;" height="17" align="right"><span style="font-size: x-small; font-family: Arial;">9324080</span></td>
<td style="background-color: transparent; border: #ece9d8;"><span style="font-size: x-small; font-family: Arial;">09/02/05 06</span></td>
<td style="background-color: transparent; border: #ece9d8;" align="right"><span style="font-size: x-small; font-family: Arial;">19.41</span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8;" height="17" align="right"><span style="font-size: x-small; font-family: Arial;">36286117</span></td>
<td style="background-color: transparent; border: #ece9d8;"><span style="font-size: x-small; font-family: Arial;">09/02/05 07</span></td>
<td style="background-color: transparent; border: #ece9d8;" align="right"><span style="font-size: x-small; font-family: Arial;">25.12</span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8;" height="17" align="right"><span style="font-size: x-small; font-family: Arial;">66275947</span></td>
<td style="background-color: transparent; border: #ece9d8;"><span style="font-size: x-small; font-family: Arial;">09/02/05 08</span></td>
<td style="background-color: transparent; border: #ece9d8;" align="right"><span style="font-size: x-small; font-family: Arial;">31.29</span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8;" height="17" align="right"><span style="font-size: x-small; font-family: Arial;">95548315</span></td>
<td style="background-color: transparent; border: #ece9d8;"><span style="font-size: x-small; font-family: Arial;">09/02/05 09</span></td>
<td class="xl24" style="background-color: transparent; border: #ece9d8;" align="right"><strong><span style="font-size: x-small; color: #ff0000; font-family: Arial;">41.38</span></strong></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8;" height="17"><strong></strong></td>
<td style="background-color: transparent; border: #ece9d8;"><strong></strong></td>
<td style="background-color: transparent; border: #ece9d8;"><strong></strong></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8;" height="17"><span style="font-size: x-small; font-family: Arial;">Total CPU(Include waits)</span></td>
<td style="background-color: transparent; border: #ece9d8;"> </td>
<td style="background-color: transparent; border: #ece9d8;"> </td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8;" height="17" align="right"><span style="font-size: x-small; font-family: Arial;">2030852964</span></td>
<td style="background-color: transparent; border: #ece9d8;"><span style="font-size: x-small; font-family: Arial;">09/02/05 00</span></td>
<td style="background-color: transparent; border: #ece9d8;" align="right"><span style="font-size: x-small; font-family: Arial;">25.43</span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8;" height="17" align="right"><span style="font-size: x-small; font-family: Arial;">2104019110</span></td>
<td style="background-color: transparent; border: #ece9d8;"><span style="font-size: x-small; font-family: Arial;">09/02/05 01</span></td>
<td style="background-color: transparent; border: #ece9d8;" align="right"><span style="font-size: x-small; font-family: Arial;">24.63</span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8;" height="17" align="right"><span style="font-size: x-small; font-family: Arial;">2112896205</span></td>
<td style="background-color: transparent; border: #ece9d8;"><span style="font-size: x-small; font-family: Arial;">09/02/05 02</span></td>
<td style="background-color: transparent; border: #ece9d8;" align="right"><span style="font-size: x-small; font-family: Arial;">24.76</span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8;" height="17" align="right"><span style="font-size: x-small; font-family: Arial;">2118178749</span></td>
<td style="background-color: transparent; border: #ece9d8;"><span style="font-size: x-small; font-family: Arial;">09/02/05 03</span></td>
<td style="background-color: transparent; border: #ece9d8;" align="right"><span style="font-size: x-small; font-family: Arial;">24.72</span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8;" height="17" align="right"><span style="font-size: x-small; font-family: Arial;">2029337</span></td>
<td style="background-color: transparent; border: #ece9d8;"><span style="font-size: x-small; font-family: Arial;">09/02/05 04</span></td>
<td style="background-color: transparent; border: #ece9d8;" align="right"><span style="font-size: x-small; font-family: Arial;">1.24</span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8;" height="17" align="right"><span style="font-size: x-small; font-family: Arial;">12410075</span></td>
<td style="background-color: transparent; border: #ece9d8;"><span style="font-size: x-small; font-family: Arial;">09/02/05 05</span></td>
<td style="background-color: transparent; border: #ece9d8;" align="right"><span style="font-size: x-small; font-family: Arial;">31.12</span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8;" height="17" align="right"><span style="font-size: x-small; font-family: Arial;">19783820</span></td>
<td style="background-color: transparent; border: #ece9d8;"><span style="font-size: x-small; font-family: Arial;">09/02/05 06</span></td>
<td style="background-color: transparent; border: #ece9d8;" align="right"><span style="font-size: x-small; font-family: Arial;">21.76</span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8;" height="17" align="right"><span style="font-size: x-small; font-family: Arial;">88298905</span></td>
<td style="background-color: transparent; border: #ece9d8;"><span style="font-size: x-small; font-family: Arial;">09/02/05 07</span></td>
<td style="background-color: transparent; border: #ece9d8;" align="right"><span style="font-size: x-small; font-family: Arial;">20.7</span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8;" height="17" align="right"><span style="font-size: x-small; font-family: Arial;">166585318</span></td>
<td style="background-color: transparent; border: #ece9d8;"><span style="font-size: x-small; font-family: Arial;">09/02/05 08</span></td>
<td style="background-color: transparent; border: #ece9d8;" align="right"><span style="font-size: x-small; font-family: Arial;">29.21</span></td>
</tr>
<tr style="height: 12.75pt;" height="17">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8;" height="17" align="right"><span style="font-size: x-small; font-family: Arial;">238824609</span></td>
<td style="background-color: transparent; border: #ece9d8;"><span style="font-size: x-small; font-family: Arial;">09/02/05 09</span></td>
<td class="xl24" style="background-color: transparent; border: #ece9d8;" align="right"><strong><span style="font-size: x-small; color: #ff0000; font-family: Arial;">41.35</span></strong></td>
</tr>
</tbody>
</table>
<p>Unbelievable, isn&#8217;t it?</p>
<p>Here&#8217;s an extract of the email conversation that took place between me and our DBA for your reference:</p>
<hr /><code>From: Ariel<br />
Sent: Thursday, 5 February 2009 10:58<br />
To: Han<br />
Subject: RE: Culprit, again</p>
<p>Well done Han, it looks like you nailed it!<br />
It would be interesting to see what Oracle has to say about this issue, considering that some Oracle experts doesn't have a clue when the "dreaded code" is executed, and didn't offer any viable solution to the problem.</p>
<p>http://forums.oracle.com/forums/thread.jspa?messageID=3205216?</p>
<p>eg. Oracle Ace sspadafo said "That looks like the anonymous block built by modplsql to handle the form POST".<br />
Oracle also said "Performance degradation is the expected behavior" and closed the following service request as a non-bug:</p>
<p>https://metalink.oracle.com/CSP/main/article?cmd=show&#038;type=BUG&#038;id=4755226</p>
<p>I think Oracle should reconsider addressing this as a bug considering that it has the ability to run a massive system to the ground.</p>
<p>Hehehe.. You should work for Oracle and make the database better!<br />
They'll probably hire you if you post your analysis below to them.</p>
<p>Regards,<br />
Ariel</p>
<p>_____________________________________________<br />
From: Han<br />
Sent: Thursday, 5 February 2009 10:31<br />
To: Ariel</p>
<p>Subject: RE: Culprit, again</p>
<p>CPU Usage Date and time (Yesterday) CPU Usage Date and Time (Today) Percentage reduction<br />
771304282 09/02/04 00 683970966 09/02/05 00 11.32<br />
789369951 09/02/04 01 703065671 09/02/05 01 10.93<br />
800036699 09/02/04 02 709172691 09/02/05 02 11.36<br />
802199588 09/02/04 03 711003880 09/02/05 03 11.37<br />
460544 09/02/04 04 369238 09/02/05 04 19.83<br />
9392224 09/02/04 05 6961506 09/02/05 05 25.88<br />
11569372 09/02/04 06 9324080 09/02/05 06 19.41<br />
48457545 09/02/04 07 36286117 09/02/05 07 25.12<br />
96454957 09/02/04 08 66275947 09/02/05 08 31.29<br />
162988493 09/02/04 09 95548315 09/02/05 09 41.38</p>
<p>Total CPU(Include waits) Total CPU(Include waits)<br />
2723572445 09/02/04 00 2030852964 09/02/05 00 25.43<br />
2791755271 09/02/04 01 2104019110 09/02/05 01 24.63<br />
2808149247 09/02/04 02 2112896205 09/02/05 02 24.76<br />
2813795083 09/02/04 03 2118178749 09/02/05 03 24.72<br />
2054772 09/02/04 04 2029337 09/02/05 04 1.24<br />
18015757 09/02/04 05 12410075 09/02/05 05 31.12<br />
25285828 09/02/04 06 19783820 09/02/05 06 21.76<br />
111341642 09/02/04 07 88298905 09/02/05 07 20.7<br />
235337742 09/02/04 08 166585318 09/02/05 08 29.21<br />
407219600 09/02/04 09 238824609 09/02/05 09 41.35</p>
<p>_____________________________________________<br />
From: Han<br />
Sent: Wednesday, 4 February 2009 3:15 PM<br />
To: Ariel</p>
<p>Subject: RE: Culprit, again</p>
<p>Ariel,</p>
<p>I did a bit reverse engineer on this internal ApEx API. The core of this API is part of OWA. The related OWA is inside package wpg_docload. The source code of wpg_docload is at $ORACLE_HOME/rdbms/admin/wpgdocs.sql.</p>
<p>Whenever the end-users download a file (images, word docus, etc.), the wpg_docload is called. Obviously we call it too frequently and causes a big performance problem.</p>
<p>For example, between 14:00pm and 15:00pm yesterday, we fetched more than 3000 times for each of the files below:<br />
[oracle@puma-c-app-00 logs]$ grep access.gif junk2 | wc -l<br />
3777<br />
[oracle@puma-c-app-00 logs]$ grep bug.gif junk2 | wc -l<br />
3731<br />
[oracle@puma-c-app-00 logs]$ grep change.gif junk2 | wc -l<br />
3360<br />
[oracle@puma-c-app-00 logs]$ grep dmt1.jpg junk2 | wc -l<br />
3595<br />
[oracle@puma-c-app-00 logs]$ grep dmt2.jpg junk2 | wc -l<br />
4006<br />
[oracle@puma-c-app-00 logs]$ grep dmt3.jpg junk2 | wc -l<br />
3813<br />
[oracle@puma-c-app-00 logs]$ grep dot.gif junk2 | wc -l<br />
3140<br />
[oracle@puma-c-app-00 logs]$ grep htmldb_remix.js junk2 | wc -l<br />
3729<br />
[oracle@puma-c-app-00 logs]$ grep theme.css junk2 | wc -l<br />
3952<br />
[oracle@puma-c-app-00 logs]$ grep whats_new.gif junk2 | wc -l<br />
3538</p>
<p>We have 2 AppServers, so the real fetches are twice. On average, they are accessed 20 times per second!</p>
<p>Because only one CPU can access a particular RAM address at a given time, all other CPUs have to wait. This kind of issues can't be resolved by big/better hardware. The more powerful of the host, the worse it gets. For 4 CPUs, 3 have to wait. For 8 CPUs, 7 have to wait, For 16 CPU, 15 have to wait. While the CPUs are waiting, they are spinning (controlled by a hidden parameter _spin_count in Oracle). Spinning means using 100% CPU doing nothing! This is why your host is always busy.</p>
<p>The solution is to move the above images from database tier to middle tier.</p>
<p>When the image is fetched from database, the PC can't cache it because the PC does not know if the file has changed since last fetch. (If you read the source code I mentioned above, you will see actually Oracle is fully aware of this problem in 1999/2000)</p>
<p>When the image is fetched from Apache, it will be cached in the PC's RAM until the file on Apache server is changed.</p>
<p>After we move the above images into Apache, we will never need to run the culprit API to fetch these files, the workload on database tier will be reduced dramatically. As the images are cached in the PC's RAM, the workload on middle tier will be reduced largely as well.</p>
<p>What do you think?</p>
<p>Cheers,<br />
Han</p>
<p>_____________________________________________<br />
From: Han<br />
Sent: Tuesday, 3 February 2009 11:34 AM<br />
To: Ariel</p>
<p>Subject: RE: Culprit, again</p>
<p>Ariel,</p>
<p>Yes, it's ApEx internal API, but I don't think we can blame Oracle entirely. Now we know this API is bad, we shouldn't call it.</p>
<p>CPU Elapsed CPU per % Total<br />
Time (s) Time (s) Executions Exec (s) DB Time SQL Id<br />
---------- ---------- ------------ ----------- ------- -------------<br />
4,014 19,928 6,686 0.60 58.2 c34r978mgkrmf</p>
<p>This SQL was called 6,686 times in an hour. Do we really need to call it so many times?</p>
<p>This issue was reported in 2005 as "Severe Loss of Service" by others, Oracle closed it "not a bug". See metalink bug#4755226 for details.<br />
This issue was occurred again in 11g ApEx 3.1.2, http://forums.oracle.com/forums/thread.jspa?messageID=3205216?<br />
Yes, it's Oracle's API, but Oracle will not do anything about it, the only choice we have is to avoid calling it.<br />
Cheers,<br />
Han</p>
<p>_____________________________________________<br />
From: Ariel<br />
Sent: Tuesday, 3 February 2009 10:58 AM<br />
To: Han</p>
<p>Subject: RE: Culprit, again</p>
<p>Han,<br />
Well, it's Oracle ApEx's own API's that's chewing up CPU. I'm hoping that their experts would have found the problem by now and enhanced the process. Oracle 10g's PL/SQL gateway is so full of patches, that 58% of the CPU load is spent checking for potential threats because requests aren't checked on the Application Server but passed to the database directly and executed by the PL/SQL gateway. During busy period, it just doesn't cope.</p>
<p>When is the code executed? I don't know.. I'm guessing it's every time because every request can potentially contain malicious code injected within the URL.</p>
<p>Oracle 11g is a single tier system. It's mechanics would be completely different to Oracle 10g. I am only hoping.</p>
<p>Regards,<br />
Ariel</p>
<p>_____________________________________________<br />
From: Han<br />
Sent: Tuesday, 3 February 2009 10:45<br />
To: Ariel</p>
<p>Subject: RE: Culprit, again</p>
<p>Ariel,</p>
<p>I think we need to further isolate the issue. "This piece of SQL gets executed everytime a request is made.". We need to find out what kind of "a request" it's. As I know, not all requests will run this SQL. There are many other applications on PUMA don't run it, even DMT right now is not running it that frequently. Can you give me an example of the URL you refer to please?</p>
<p>Why do you think 11g ApEx 3.1 helps here? If it's network traffic, I can image, but it's CPU.</p>
<p>Regards,<br />
Han</p>
<p>_____________________________________________<br />
From: Ariel<br />
Sent: Tuesday, 3 February 2009 10:34 AM<br />
To: Han</p>
<p>Subject: RE: Culprit, again</p>
<p>Han,<br />
This piece of SQL gets executed everytime a request is made.<br />
The code checks for exclusion strings in the URL and halts the request if excluded strings exists in the URL.</p>
<p>The only way we can reduce the number of times this code gets executed is to reduce the traffic during this period (2.00pm to 3:00), or upgrade ApEx to Oracle 11g ApEx 3.1, with it's embedded Oracle Application Server, which may be less prone to these issues because the App Server is in the database.</p>
<p>2:00 to 3:00 pm is the busiest time of the day, because Day shift staff from 3 workcentres (Coffs, Sydney and Ballarat) are frantically booking activities off to DMT before they finish off for the day.</p>
<p>Regards,<br />
Ariel</p>
<p>_____________________________________________<br />
From: Han<br />
Sent: Monday, 2 February 2009 15:49<br />
To: Ariel<br />
Subject: Culprit, again</p>
<p>Ariel,</p>
<p>The old issue come back again.</p>
<p>I checked the performance issue between 2:00pm and 3:00pm today when CPU was 100% busy all the time. The #1 SQL is:</p>
<p>CPU Elapsed CPU per % Total<br />
Time (s) Time (s) Executions Exec (s) DB Time SQL Id<br />
---------- ---------- ------------ ----------- ------- -------------<br />
4,014 19,928 6,686 0.60 58.2 c34r978mgkrmf</p>
<p>So 58% of CPU usage is used by this SQL. Then I find out the SQL text:</p>
<p>select sql_fulltext from v$sqlstats where sql_id = 'c34r978mgkrmf'</p>
<p>declare<br />
rc__ number;<br />
simple_list__ owa_util.vc_arr;<br />
complex_list__ owa_util.vc_arr;<br />
begin<br />
owa.init_cgi_env(:n__,:nm__,:v__);<br />
htp.HTBUF_LEN := 255;<br />
null;<br />
null;<br />
simple_list__(1) := 'sys.%';<br />
simple_list__(2) := 'dbms\_%';<br />
simple_list__(3) := 'utl\_%';<br />
simple_list__(4) := 'owa\_%';<br />
simple_list__(5) := 'owa.%';<br />
simple_list__(6) := 'htp.%';<br />
simple_list__(7) := 'htf.%';<br />
simple_list__(8) := 'wpg_docload.%';<br />
if ((owa_match.match_pattern('f', simple_list__, complex_list__, true))) then<br />
rc__ := 2;<br />
else<br />
null;<br />
null;<br />
f(p=&gt;:p);<br />
if (wpg_docload.is_file_download) then<br />
rc__ := 1;<br />
wpg_docload.get_download_file(:doc_info);<br />
null;<br />
null;<br />
null;<br />
commit;<br />
else<br />
rc__ := 0;<br />
null;<br />
null;<br />
null;<br />
commit;<br />
owa.get_page(:data__,:ndata__);<br />
end if;<br />
end if;<br />
:rc__ := rc__;<br />
end;</p>
<p>Now, it looks familiar, it rings a bell. I looked around, it's actually the same culprit we identified 2 years ago (see below email).</p>
<p>Any chance you can limit the times of running on this piece please?</p>
<p>Cheers,<br />
Han</p>
<p>_____________________________________________<br />
From: Han<br />
Sent: Monday, 27 November 2006 9:24 AM<br />
To: Ariel<br />
Subject: RE:</p>
<p>Thanks.</p>
<p>Any chance you can limit the times of running on this piece please:</p>
<p>declare<br />
rc__ number;<br />
simple_list__ owa_util.vc_arr;<br />
complex_list__ owa_util.vc_arr;<br />
begin<br />
owa.init_cgi_env(:n__,:nm__,:v__);<br />
htp.HTBUF_LEN := 255;<br />
null;<br />
null;<br />
simple_list__(1) := 'sys.%';<br />
simple_list__(2) := 'dbms\_%';<br />
simple_list__(3) := 'utl\_%';<br />
simple_list__(4) := 'owa\_%';<br />
simple_list__(5) := 'owa.%';<br />
simple_list__(6) := 'htp.%';<br />
simple_list__(7) := 'htf.%';<br />
simple_list__(8) := 'wpg_docload.%';<br />
if ((owa_match.match_pattern('f', simple_list__, complex_list__, true))) then<br />
rc__ := 2;<br />
else<br />
null;<br />
null;<br />
f(p=&gt;:p);<br />
if (wpg_docload.is_file_download) then<br />
rc__ := 1;<br />
wpg_docload.get_download_file(:doc_info);<br />
null;<br />
null;<br />
null;<br />
commit;<br />
else<br />
rc__ := 0;<br />
null;<br />
null;<br />
null;<br />
commit;<br />
owa.get_page(:data__,:ndata__);<br />
end if;<br />
end if;<br />
:rc__ := rc__;<br />
end;</p>
<p>_____________________________________________<br />
From: Ariel<br />
Sent: Monday, 27 November 2006 9:20 AM<br />
To: Han<br />
Subject: RE:</p>
<p>Done, the process has been modified.</p>
<p>Regards,<br />
Ariel</p>
<p>_____________________________________________<br />
From: Han<br />
Sent: Monday, 27 November 2006 9:15 AM<br />
To: Ariel<br />
Subject: RE:</p>
<p>Yes, it causes performance issue, please try to run it only when necessary.</p>
<p>_____________________________________________<br />
From: Ariel<br />
Sent: Monday, 27 November 2006 9:13 AM<br />
To: Han<br />
Subject: RE:</p>
<p>Yes, it's a computation that happens everytime a page loads. Is it causing a problem? I can modify it to only run once during login.</p>
<p>select 1<br />
from pay_rate<br />
where pay_rate_id = (select pay_rate from dmt_users where user_id = <img src='http://technologydribble.info/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> MT_USER_ID)<br />
and to_number(to_char(sysdate - nvl(:DMT_TIME,0),'HH24')) between start_hour and end_hour</p>
<p>Regards,<br />
Ariel</p>
<p>_____________________________________________<br />
From: Han<br />
Sent: Monday, 27 November 2006 9:03 AM<br />
To: Ariel<br />
Subject: RE:</p>
<p>Does this SQL ring a bell to you please?</p>
<p>select 1 from pay_rate where pay_rate_id = (select pay_rate from dmt_users where user_id = <img src='http://technologydribble.info/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> MT_USER_ID) and to_number(to_char(sysdate - nvl(:DMT_TIME,0),'HH24')) between start_hour and end_hour</p>
<p>Many sessions are running the same SQL.</p>
<p>_____________________________________________<br />
From: Ariel<br />
Sent: Monday, 27 November 2006 8:29 AM<br />
To: Han<br />
Subject:<br />
Importance: High</p>
<p>Han/John,<br />
DMT on PUMAE is running very slowly at the moment and it appears to be getting worse. Could you please investigate at you earliest possible convenience.</p>
<p>Thank you,</p>
<p>Regards,<br />
Ariel</p>
<p> </p>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://technologydribble.info/2009/02/04/improving-performance-of-your-oracle-application-express-software/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>HTTP Post from Oracle PL/SQL</title>
		<link>http://technologydribble.info/2008/10/02/http-post-from-oracle-plsql/</link>
		<comments>http://technologydribble.info/2008/10/02/http-post-from-oracle-plsql/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 06:33:09 +0000</pubDate>
		<dc:creator>ryelpango</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PL/SQL]]></category>
		<category><![CDATA[apex]]></category>
		<category><![CDATA[http post]]></category>
		<category><![CDATA[web service]]></category>

		<guid isPermaLink="false">http://technologydribble.info/?p=7</guid>
		<description><![CDATA[I recently needed to execute a HTTP post from an ApEx application to another web page running as some sort of a service. For added security the web page service only accepted POST requests and one of the parameters passed is a secret password (not encrypted but secure enough for an Intranet application). Anyway the [...]]]></description>
			<content:encoded><![CDATA[<p>I recently needed to execute a HTTP post from an ApEx application to another web page running as some sort of a service. For added security the web page service only accepted POST requests and one of the parameters passed is a secret password (not encrypted but secure enough for an Intranet application).</p>
<p>Anyway the requirement was to post the request using PL/SQL to the web service, and receive the response. I visited the oracle page on <a title="UTL_HTTP reference" href="http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/u_http.htm">UTL_HTTP</a> for a bit of reference and came up with the following code:</p>
<pre>

set serveroutput on;
exec dbms_output.enable(1000000000);
set escape '\'

DECLARE
  req   UTL_HTTP.REQ;
  resp  UTL_HTTP.RESP;
  value VARCHAR2(1024);  -- URL to post to
  v_url VARCHAR2(200) := 'http://T97040476TA9000/core_dmt/withdraw_job.php';
  -- Post Parameters
  v_param VARCHAR2(500) := 'pwd=password123\&#038;core_id=12223\&#038;type=PK\&#038;reason=Test reason';
  v_param_length NUMBER := length(v_param);
BEGIN
  -- Set up proxy servers if required
  --  UTL_HTTP.SET_PROXY('proxy.my-company.com', 'corp.my-company.com');
  req := UTL_HTTP.BEGIN_REQUEST (url=> v_url, method => 'POST');
  --  UTL_HTTP.SET_HEADER(req, 'User-Agent', 'Mozilla/4.0');
  UTL_HTTP.SET_HEADER (r      =>  req,
                       name   =>  'Content-Type',
                       value  =>  'application/x-www-form-urlencoded');
  UTL_HTTP.SET_HEADER (r      =>   req,
                       name   =>   'Content-Length',
                       value  =>   v_param_length);
  UTL_HTTP.WRITE_TEXT (r      =>   req,
                       data   =>   v_param);  resp := UTL_HTTP.GET_RESPONSE(req);
  LOOP
    UTL_HTTP.READ_LINE(resp, value, TRUE);
    DBMS_OUTPUT.PUT_LINE(value);
  END LOOP;
  UTL_HTTP.END_RESPONSE(resp);
EXCEPTION
  WHEN UTL_HTTP.END_OF_BODY THEN
    UTL_HTTP.END_RESPONSE(resp);
END;
/
</pre>
<p>The only thing you need to change to make the code work for you are the <strong>v_url</strong> and the <strong>v_param</strong> values to reflect the url of your service and the parameters it expects.</p>
<p>Happy Coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://technologydribble.info/2008/10/02/http-post-from-oracle-plsql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

