<?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>Enkitec Blog</title>
	<atom:link href="http://blog.enkitec.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.enkitec.com</link>
	<description>The official blog of Enkitec</description>
	<lastBuildDate>Fri, 27 Jul 2012 02:06:42 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>More OS X Tips for Oracle Developers</title>
		<link>http://blog.enkitec.com/2012/07/more-os-x-tips-for-oracle-developers/</link>
		<comments>http://blog.enkitec.com/2012/07/more-os-x-tips-for-oracle-developers/#comments</comments>
		<pubDate>Fri, 27 Jul 2012 02:06:42 +0000</pubDate>
		<dc:creator>Toby Marks</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Oracle Forms]]></category>
		<category><![CDATA[OS X Lion]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[Safari]]></category>
		<category><![CDATA[SQL Developer]]></category>

		<guid isPermaLink="false">http://blog.enkitec.com/?p=686</guid>
		<description><![CDATA[The latest from my blog: Fix for Page Load Issues in Safari 5.1.7 Easy Fix for High CPU Usage in SQL Developer on OS X Run Oracle Forms 11g Applications on OS X Lion]]></description>
				<content:encoded><![CDATA[<p>The latest from my blog:</p>
<p><a href="http://tmblr.co/Z9fAmvQ3sMQF">Fix for Page Load Issues in Safari 5.1.7</a></p>
<p><a href="http://tmblr.co/Z9fAmvPl3fGb">Easy Fix for High CPU Usage in SQL Developer on OS X</a></p>
<p><a href="http://tmblr.co/Z9fAmvPE3MFC">Run Oracle Forms 11g Applications on OS X Lion</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.enkitec.com/2012/07/more-os-x-tips-for-oracle-developers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>HugePages Configuration and Monitoring</title>
		<link>http://blog.enkitec.com/2012/07/hugepages-configuration-and-monitoring/</link>
		<comments>http://blog.enkitec.com/2012/07/hugepages-configuration-and-monitoring/#comments</comments>
		<pubDate>Fri, 20 Jul 2012 12:34:07 +0000</pubDate>
		<dc:creator>Rick Miners</dc:creator>
				<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://blog.enkitec.com/?p=661</guid>
		<description><![CDATA[I was recently working with a customer who was experiencing some memory pressure on their Linux database server. They were running Oracle 10.2.0.5 on Oracle Enterprise Server 5.7. The buffer cache was 50G and they wanted to increase it to about 100G. Here is what the memory allocation on the machine looked like; 10G in [...]]]></description>
				<content:encoded><![CDATA[<p>I was recently working with a customer who was experiencing some memory pressure on their Linux database server.<br />
They were running Oracle 10.2.0.5 on Oracle Enterprise Server 5.7.<br />
The buffer cache was 50G and they wanted to increase it to about 100G.</p>
<p>Here is what the memory allocation on the machine looked like; 10G in PageTables.<br />
<span id="more-661"></span><br />
$ cat /proc/meminfo<br />
MemTotal: 264251332 kB<br />
MemFree: 356300 kB<br />
Buffers: 954760 kB<br />
Cached: 245170884 kB<br />
SwapCached: 1758320 kB<br />
Active: 175702124 kB<br />
Inactive: 75100644 kB<br />
HighTotal: 0 kB<br />
HighFree: 0 kB<br />
LowTotal: 264251332 kB<br />
LowFree: 356300 kB<br />
SwapTotal: 4194296 kB<br />
SwapFree: 504648 kB<br />
Dirty: 52 kB<br />
Writeback: 56 kB<br />
AnonPages: 2918272 kB<br />
Mapped: 43409016 kB<br />
Slab: 2252952 kB<br />
PageTables: 10498900 kB<br />
NFS_Unstable: 0 kB<br />
Bounce: 0 kB<br />
CommitLimit: 136319960 kB<br />
Committed_AS: 67219780 kB<br />
VmallocTotal: 34359738367 kB<br />
VmallocUsed: 279684 kB<br />
VmallocChunk: 34359458295 kB<br />
HugePages_Total: 0<br />
HugePages_Free: 0<br />
HugePages_Rsvd: 0<br />
Hugepagesize: 2048 kB</p>
<p>Their server had 256G of RAM and a SGA that was already 100G; a good candidate for HugePages due to their sizes.</p>
<p>From Oracle documentation, here are some major advantages of using HugePages.</p>
<p>* HugePages is crucial for faster Oracle database performance on Linux if you have a large RAM and SGA.</p>
<p>* HugePages are not swappable. Therefore there is no page-in/page-out mechanism overhead. HugePages are universally regarded as pinned.</p>
<p>Implementing HugePages has become common practice with Oracle 11g and is fairly well documented in MOS Note 361468.1.<br />
The basics steps are as follows:</p>
<p>* Set the memlock ulimit for the oracle user.<br />
* Disable Automatic Memory Managment if necesary as it is incompatible with HugePages.<br />
* Run the Oracle supplied hugepages_settings.sh script to calculate the recommended value for the vm.nr_hugepages kernel parameter.<br />
* Edit /etc/sysctl.conf with the vm.nr_hugepages with the recommeneded setting.<br />
* Reboot the server</p>
<p>Unfortunately, The database we were working with was 10g. As it turns out, there are some differences between<br />
Oracle 10 and 11, mainly that there is no HugePage logging in the alert log on version 10. See MOS Note: 1392543.1<br />
This makes troubleshooting difficult because HugePages does not take effect until after it is configured.</p>
<p>Another noticable difference is the fact that the initialization parameter use_large_pages was not added until version 11.2.0.2.<br />
In the event that you have multiple databases on one machine, this parameter allows you to control which databases<br />
use HugePages. In addition, it can prevent a database from starting up if not enough HugePages can be allocated at instance startup.<br />
See &#8220;USE_LARGE_PAGES To Enable HugePages In 11.2 [ID 1392497.1]&#8221; for more detailed info on the values for this parameter.</p>
<p>Similar across both versions is the initialization parameter PRE_PAGE_SGA, which determines whether Oracle<br />
will read the entire SGA into memory at instance startup or not. However, it is not<br />
specific to HugePages as it works with the default OS pages as well. Also, there is an environment variable DISABLE_HUGETLBFS<br />
that can be used in 10g to accomplish the same thing as the use_large_pages parameter in 11g. If this variable is set, it<br />
will prevent Oracle from using HugePages. So presumably you could have startup scripts that set or unset this variable prior<br />
to starting databases which would give you ability to have some use huge pages while others do not, even in 10g.</p>
<p>Getting back to the story, we successfully got HugePages working on their QA box, but then it did not<br />
work in production. HupePages were created by the OS after the reboot as seen in /proc/meminfo;<br />
however, Oracle didn&#8217;t use them. In comparing the two environments, two notable differences were found:</p>
<p>1. memlock settings in /etc/security/limits.conf ( Can be seen by running ulimit ) was unlimited in QA, but not production</p>
<p>> ulimit -l<br />
98566144</p>
<p>> cat /etc/security/limits.conf<br />
# /etc/security/limits.conf<br />
#<br />
&#8230;<br />
oracle soft memlock 98566144<br />
oracle hard memlock 98566144<br />
# End of file</p>
<p>2. SHMMAX was 90G on QA, but 190G on production</p>
<p>Oracle&#8217;s recommendation for the memlock setting ( from the MOS note 1392543.1 ) is stated as follows:<br />
&#8220;Set the value (in KB) slightly smaller than installed RAM.&#8221;<br />
The customer had decided to set it to 94% of their 100G SGA.</p>
<p>After some searching, we found the MOS note &#8220;Oracle Not Utilizing Hugepages [ID 803238.1]&#8221; which<br />
gives a formula for calculating the value. This value is the minimum required in order for the database<br />
to successfully startup using HugePages. The memlock setting is specified in KB and must match the<br />
memory size of the number of HugePages that Oracle should be able to allocate.</p>
<p>memlock = ( HugePages * Hugepagesize )<br />
where HugePages is the output given using script from MOS note 401749.1 and Hugepagesize is value from<br />
in /proc/meminfo (on Linux Hugepagesize is normally 2048).</p>
<p>memlock = ( 51203 * 2048 ) = 104863744<br />
This number is higher than what was set for memlock in /etc/security/limits.conf .</p>
<p>Now, what about SHMMAX? According to MOS note 567506.1, Oracle Global Customer Support officially recommends<br />
a maximum for SHMMAX of &#8220;1/2 of physical RAM&#8221;. Since the customer&#8217;s value was higher than this,<br />
SHMMAX was lowered from 190G to 90G to match that of QA.</p>
<p>After making these two changes, the database successfuly started up using HugePages.<br />
It is worth mentioning here that if HugePages had not been successfully configured, the vm.nr_hugepages<br />
parameter change in /etc/sysctl.conf should be backed out as the space allocated to HugePages would be<br />
wasted if Oracle cannot use it.</p>
<p>So, was it memlock or SHMMAX that was causing the issue? Or was it both?</p>
<p>Since 11g writes a lot of information to the alert log regarding hugepage usage I decided to see what kind<br />
of messages would be emitted when the same situation occurred on an 11g database.<br />
As it turns out, the messages in the alert log are very informational in pointing you in the right direction.</p>
<p>Here is a snippet from the 11g alert log on a clean startup utilizing HugePages:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p661code13'); return false;">View Code</a> NONE</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p66113"><td class="code" id="p661code13"><pre class="none" style="font-family:monospace;">Starting ORACLE instance (normal)
****************** Large Pages Information *****************
&nbsp;
Total Shared Global Region in Large Pages = 806 MB (100%)
&nbsp;
Large Pages used by this instance: 403 (806 MB)
Large Pages unused system wide = 97 (194 MB) (alloc incr 4096 KB)
Large Pages configured system wide = 500 (1000 MB)
Large Page size = 2048 KB
***********************************************************</pre></td></tr></table></div>

<p>In the following example, I lowered the memlock setting to below its recommended value.<br />
Note the Memlock messages saying it is too small.<br />
The &#8220;recommendation&#8221; part seems a bit odd as it suggests to add 0 pages!<br />
We&#8217;ll look at that one next.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p661code14'); return false;">View Code</a> NONE</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p66114"><td class="code" id="p661code14"><pre class="none" style="font-family:monospace;">Starting ORACLE instance (normal)
Memlock limit too small: 32768 to accommodate segment size: 4194304
Memlock limit too small: 32768 to accommodate segment size: 8388608
Memlock limit too small: 32768 to accommodate segment size: 4194304
Memlock limit too small: 32768 to accommodate segment size: 4194304
...
Memlock limit too small: 32768 to accommodate segment size: 4194304
Memlock limit too small: 32768 to accommodate segment size: 4194304
Memlock limit too small: 32768 to accommodate segment size: 2097152
****************** Large Pages Information *****************
&nbsp;
Total Shared Global Region in Large Pages = 0 KB (0%)
&nbsp;
Large Pages used by this instance: 0 (0 KB)
Large Pages unused system wide = 500 (1000 MB) (alloc incr 4096 KB)
Large Pages configured system wide = 500 (1000 MB)
Large Page size = 2048 KB
&nbsp;
RECOMMENDATION:
Total Shared Global Region size is 810 MB. For optimal performance,
prior to the next instance restart increase the number
of unused Large Pages by atleast 0 2048 KB Large Pages (0 KB)
system wide to get 100% of the Shared
Global Region allocated with Large pages
***********************************************************</pre></td></tr></table></div>

<p>In the following example, the memlock value and hugepages are both too small.<br />
As you can see from the alert log below, messages about both are mentioned, good!</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p661code15'); return false;">View Code</a> NONE</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p66115"><td class="code" id="p661code15"><pre class="none" style="font-family:monospace;">Starting ORACLE instance (normal)
Memlock limit too small: 32768 to accommodate segment size: 4194304
Memlock limit too small: 32768 to accommodate segment size: 8388608
Memlock limit too small: 32768 to accommodate segment size: 4194304
...
Memlock limit too small: 32768 to accommodate segment size: 4194304
Memlock limit too small: 32768 to accommodate segment size: 4194304
Memlock limit too small: 32768 to accommodate segment size: 2097152
****************** Large Pages Information *****************
&nbsp;
Total Shared Global Region in Large Pages = 0 KB (0%)
&nbsp;
Large Pages used by this instance: 0 (0 KB)
Large Pages unused system wide = 100 (200 MB) (alloc incr 4096 KB)
Large Pages configured system wide = 100 (200 MB)
Large Page size = 2048 KB
&nbsp;
RECOMMENDATION:
Total Shared Global Region size is 810 MB. For optimal performance,
prior to the next instance restart increase the number
of unused Large Pages by atleast 305 2048 KB Large Pages (610 MB)
system wide to get 100% of the Shared
Global Region allocated with Large pages
***********************************************************</pre></td></tr></table></div>

<p>Let&#8217;s take a look at the kernel parameter SHMMAX now.<br />
On the Oracle VM where I was testing this, the default SHMMAX was set to 64GB. Much bigger<br />
than the 2GB of RAM allocated to the VM. In trying values between 1GB and 64Gb, the<br />
database always started up using HugePages without any issue. However, the value of SHMALL<br />
is one that needs to be set correctly.</p>
<p>In the next example, I lowered SHMALL to below its recommended value.<br />
You will see the output below from SQL*Plus, but nothing was shown in the alert log.<br />
After reading a couple of Documents on MOS, you should<br />
choose the higher of the two values below for SHMALL, it will depend on your database memory sizes.<br />
From MOS note 169706.1 : SHMALL = SHMMAX / OS PAGE_SIZE<br />
From MOS note 301830.1 : SHMALL = sum(SGAs)/ OS PAGE_SIZE</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p661code16'); return false;">View Code</a> NONE</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p66116"><td class="code" id="p661code16"><pre class="none" style="font-family:monospace;">SQL &gt; startup
ORA-27102: out of memory
Linux-x86_64 Error: 28: No space left on device</pre></td></tr></table></div>

<p>As I mentioned earlier, HugePages is not compatible with Automatic Memory Mangement.<br />
If you try to start the database using AMM, here is what the entry from the alert log will look like.<br />
Note that you can still use the sga_target parameter, just not memory_target, memory_max_target.<br />
Note also that you can’t use the use_indirect data._buffers parameter.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p661code17'); return false;">View Code</a> NONE</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p66117"><td class="code" id="p661code17"><pre class="none" style="font-family:monospace;">Starting ORACLE instance (normal)
******************************************************************
Large Pages are not compatible with specified SGA memory parameters
use_large_pages = &quot;ONLY&quot; cannot be used with memory_target,
memory_max_target, or use_indirect_data_buffers parameters
Large Pages are compatible with sga_target and shared_pool_size
******************************************************************</pre></td></tr></table></div>

<p>Since the alert log in Oracle 10g does not log any HugePage information, we have to be a little more creative<br />
to uncover clues as to why huge pages are not used . There is a note on MOS that recommends using strace<br />
to help diagnose this type of issue. So let&#8217;s use strace on a<br />
sqlplus session when starting the Oracle 10 database to see if that will provide<br />
any useful troubleshooting information. I intentionally lowered the SHMALL parameter in this example to 56000.<br />
Notice here that we are trying to allocate more memory that we have allotted for with the SHMALL kernel parameter.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p661code18'); return false;">View Code</a> NONE</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p66118"><td class="code" id="p661code18"><pre class="none" style="font-family:monospace;">&gt; strace -f -o output.txt sqlplus / as sysdba
&nbsp;
SQL*Plus: Release 10.2.0.5.0 - Production
&nbsp;
Copyright (c) 1982, 2010, Oracle. All Rights Reserved.
&nbsp;
Connected to an idle instance.
&nbsp;
SYS:ORA10&gt;startup
ORA-27102: out of memory
Linux-x86_64 Error: 28: No space left on device</pre></td></tr></table></div>

<p>In the output.txt file, you should see output similar to the following showing the shmget calls.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p661code19'); return false;">View Code</a> NONE</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p66119"><td class="code" id="p661code19"><pre class="none" style="font-family:monospace;">9624  shmget(0x22675a08, 232783872, IPC_CREAT|IPC_EXCL|SHM_HUGETLB|0660) = -1 ENOSPC (No space left on device)</pre></td></tr></table></div>

<p>In the next example, I lowered the ulimit setting. Here the database successfully started; however, HugePages was<br />
not used as seen in /proc/meminfo.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p661code20'); return false;">View Code</a> NONE</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p66120"><td class="code" id="p661code20"><pre class="none" style="font-family:monospace;">&gt;strace -f -o output.txt sqlplus / as sysdba
&nbsp;
SQL*Plus: Release 10.2.0.5.0 - Production
&nbsp;
Copyright (c) 1982, 2010, Oracle. All Rights Reserved.
&nbsp;
Connected to an idle instance.
&nbsp;
SYS:ORA10&gt;;startup
ORACLE instance started.
&nbsp;
Total System Global Area 230686720 bytes
Fixed Size 2095344 bytes
Variable Size 117442320 bytes
Database Buffers 104857600 bytes
Redo Buffers 6291456 bytes
Database mounted.
Database opened.
&nbsp;
SYS:ORA10&gt;;exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
&nbsp;
&gt; cat /proc/meminfo | grep -i huge
HugePages_Total: 520
HugePages_Free: 520
HugePages_Rsvd: 0
Hugepagesize: 2048 kB</pre></td></tr></table></div>

<p>From output.txt, you can see that the database tried to use huge pages, but failed and then started up using<br />
the OS standard pages.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p661code21'); return false;">View Code</a> NONE</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p66121"><td class="code" id="p661code21"><pre class="none" style="font-family:monospace;">10783 shmget(0x22675a08, 232783872, IPC_CREAT|IPC_EXCL|SHM_HUGETLB|0660) = -1 ENOMEM (Cannot allocate memory)
...
10783 shmget(0x22675a08, 232783872, IPC_CREAT|IPC_EXCL|0660) = 12353549</pre></td></tr></table></div>

<p>If you do not want an 11g database to startup without HugePages, remember to set the use_large_pages initilization<br />
parameter mentioned previously. When set to &#8220;only&#8221;, the database will fail to start. You will need to be at least<br />
on version 11.2.0.2 though.</p>
<p>For Oracle 10g, if you want to ensure that your database is using HugePages,<br />
you can use the equation from MOS note 1392543.1 to calculate the<br />
&#8220;Large Pages used by this instance&#8221; as seen in 11g alert log.<br />
If you have multiple databases, you will need to monitor /proc/meminfo between instance startups.<br />
Note that if HugePages_Total = HugePages_Free, then you at NOT using HugePages.</p>
<p>Large Pages used by this instance (#pages) = HugePages_Total &#8211; HugePages_Free + HugePages_Rsvd</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p661code22'); return false;">View Code</a> NONE</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p66122"><td class="code" id="p661code22"><pre class="none" style="font-family:monospace;"> &gt; cat /proc/meminfo | grep -i huge
HugePages_Total: 520
HugePages_Free: 409
HugePages_Rsvd: 0
Hugepagesize: 2048 kB</pre></td></tr></table></div>

<p>#pages = 520 &#8211; 409 + 0 = 111</p>
<p>Here&#8217;s an example using Oracle 11g showing the correlation between the equation and the alert log.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p661code23'); return false;">View Code</a> NONE</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p66123"><td class="code" id="p661code23"><pre class="none" style="font-family:monospace;">DBM&gt;startup
ORACLE instance started.
&nbsp;
Total System Global Area 839282688 bytes
Fixed Size 2233000 bytes
Variable Size 780143960 bytes
Database Buffers 50331648 bytes
Redo Buffers 6574080 bytes
Database mounted.
Database opened.
&nbsp;
[el5-5-64:oracle:ORA10] /home/oracle
&gt; cat /proc/meminfo
HugePages_Total: 520
HugePages_Free: 403
HugePages_Rsvd: 286
Hugepagesize: 2048 kB</pre></td></tr></table></div>

<p>#pages = 520 &#8211; 403 + 286 = 403, which matches the value that is shown in the alert log snippet below.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p661code24'); return false;">View Code</a> NONE</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p66124"><td class="code" id="p661code24"><pre class="none" style="font-family:monospace;">Starting ORACLE instance (normal)
****************** Large Pages Information *****************
Parameter use_large_pages = ONLY
&nbsp;
Total Shared Global Region in Large Pages = 806 MB (100%)
&nbsp;
Large Pages used by this instance: 403 (806 MB)
Large Pages unused system wide = 117 (234 MB) (alloc incr 4096 KB)
Large Pages configured system wide = 520 (1040 MB)
Large Page size = 2048 KB
***********************************************************</pre></td></tr></table></div>

<p>Please see MOS notes Oracle Not Utilizing Hugepages [ID 803238.1] and<br />
Upon startup of Linux database get ORA-27102: out of memory Linux-X86_64 Error: 28: No space left on device [ID 301830.1]<br />
for more troubleshooting examples.</p>
<p>Finally, it is important to remember is that the HugePage confguration is not dynamic. If you make changes to the SGA size, add another database, etc.,<br />
you should revisit the HugePage configuration.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.enkitec.com/2012/07/hugepages-configuration-and-monitoring/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>OS X Software for Oracle Developers</title>
		<link>http://blog.enkitec.com/2012/06/os-x-software-for-oracle-developers/</link>
		<comments>http://blog.enkitec.com/2012/06/os-x-software-for-oracle-developers/#comments</comments>
		<pubDate>Wed, 27 Jun 2012 21:53:06 +0000</pubDate>
		<dc:creator>Toby Marks</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[enkitec]]></category>

		<guid isPermaLink="false">http://blog.enkitec.com/?p=651</guid>
		<description><![CDATA[New on my Tumblr blog: my list of OS X software recommendations for Oracle Developers.]]></description>
				<content:encoded><![CDATA[<p>New on my Tumblr blog: my list of <a href="http://tjmoracle.tumblr.com/post/26025230295/os-x-software-for-oracle-developers" target="_blank">OS X software recommendations for Oracle Developers</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.enkitec.com/2012/06/os-x-software-for-oracle-developers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DML Error Logging</title>
		<link>http://blog.enkitec.com/2012/06/dml-error-logging/</link>
		<comments>http://blog.enkitec.com/2012/06/dml-error-logging/#comments</comments>
		<pubDate>Thu, 07 Jun 2012 19:50:15 +0000</pubDate>
		<dc:creator>Toby Marks</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://blog.enkitec.com/?p=644</guid>
		<description><![CDATA[Introduced with Oracle 10gR2, DML Error Logging allows you to make standard SQL INSERT, UPDATE, and MERGE statements behave more like the SQL*Loader utility, logging errors to a table rather than failing and rolling back the first time an error condition is encountered. Read on&#8230;]]></description>
				<content:encoded><![CDATA[<p>Introduced with Oracle 10gR2, DML Error Logging allows you to make standard SQL INSERT, UPDATE, and MERGE statements behave more like the SQL*Loader utility, logging errors to a table rather than failing and rolling back the first time an error condition is encountered.</p>
<p><a href="http://tjmoracle.tumblr.com/post/24616799679/dml-error-logging">Read on&#8230;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.enkitec.com/2012/06/dml-error-logging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ODBC Connection Fails for MS Access App on Citrix</title>
		<link>http://blog.enkitec.com/2012/05/odbc-connection-fails-for-ms-access-app-on-citrix/</link>
		<comments>http://blog.enkitec.com/2012/05/odbc-connection-fails-for-ms-access-app-on-citrix/#comments</comments>
		<pubDate>Fri, 11 May 2012 21:51:20 +0000</pubDate>
		<dc:creator>Toby Marks</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[access]]></category>
		<category><![CDATA[citrix]]></category>
		<category><![CDATA[odbc]]></category>
		<category><![CDATA[webapp]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[xenapp]]></category>

		<guid isPermaLink="false">http://blog.enkitec.com/?p=634</guid>
		<description><![CDATA[(Original article on my Tumblr page.) I ran into an interesting problem recently when attempting to publish an MS Access application with Citrix XenApp. The application pulled data from an Oracle database, so an ODBC connection was created on the Citrix server. What we found was that when a non-privileged user tried to run the application, [...]]]></description>
				<content:encoded><![CDATA[<p>(<a href="http://tjmoracle.tumblr.com/post/22857143505/odbc-connection-fails-for-ms-access-app-on-citrix">Original article on my Tumblr page</a>.)</p>
<p>I ran into an interesting problem recently when attempting to publish an MS Access application with <a href="http://www.citrix.com/English/ps2/products/product.asp?contentID=186&amp;ntref=footer">Citrix XenApp</a>. The application pulled data from an Oracle database, so an ODBC connection was created on the Citrix server. What we found was that when a non-privileged user tried to run the application, the connection failed. When the Citrix server admin ran it, however, it worked. Furthermore, as long as the admin was logged in, anybody else could run the application successfully; when he logged out, the users’ connections broke again.</p>
<p><span id="more-634"></span></p>
<p>Since Access is not my area of expertise, we finally contacted Microsoft tech support after trying a few suggestions we dug up in our own research. The support analyst clued us in to the following solution, which I pulled from an Oracle Primavera <a href="http://docs.oracle.com/cd/E16688_01/Technical_Documentation/Terminal_Services_and_Citrix/Terminal%20Services%20and%20Citrix.pdf">setup document</a>.</p>
<p>From what I’ve seen on different support forums, this seems to be a pretty standard setup task when running Oracle on Windows over Citrix.</p>
<blockquote><p>If using an Oracle database platform, confirm [that] the Create Global Objects Windows Security Policy is set up on the Terminal Servers and add the domain Users or Groups of the end-users who will be accessing the published application. If the local security policy is not setup, the following steps can be used to add the policy:</p>
<ol>
<li>Click Start, Programs, Administrative Tools, and then click Local Security Policy.</li>
<li>Expand Local Policies, and then click User Rights Assignments.</li>
<li>In the right pane, double-click Create Global Objects.</li>
<li>In the Local Security Policy Setting dialogbox, click Add.</li>
<li>In the Select Users or Group dialog box, select the user group that these end users are a part of, click Add, and then click OK.</li>
<li>Click OK.</li>
</ol>
<p>If using an Oracle database platform, the Oracle client software also requires that you give the Authenticated User Group, Read and Execute privilege to the Oracle Home Directory and ALL its sub directories and files on the Terminal Servers.</p></blockquote>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.enkitec.com/2012/05/odbc-connection-fails-for-ms-access-app-on-citrix/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Discovering Command-line Java Profiling Tools</title>
		<link>http://blog.enkitec.com/2012/05/discovering-command-line-java-profiling-tools/</link>
		<comments>http://blog.enkitec.com/2012/05/discovering-command-line-java-profiling-tools/#comments</comments>
		<pubDate>Thu, 03 May 2012 20:14:58 +0000</pubDate>
		<dc:creator>Toby Marks</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[instrumentation]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jhat]]></category>
		<category><![CDATA[jmap]]></category>
		<category><![CDATA[jps]]></category>
		<category><![CDATA[jstack]]></category>
		<category><![CDATA[jstat]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[profiling]]></category>

		<guid isPermaLink="false">http://blog.enkitec.com/?p=624</guid>
		<description><![CDATA[On my Tumblr blog I review a bevy of command-line Java profiling tools that you may not even know existed. They do, and they come included with the JDK! Read on&#8230;]]></description>
				<content:encoded><![CDATA[<p>On my <a target="_blank" href="http://tjmoracle.tumblr.com/">Tumblr blog</a> I review a bevy of command-line Java profiling tools that you may not even know existed. They do, and they come included with the JDK!</p>
<p><a target="_blank" href="http://tjmoracle.tumblr.com/post/22276471924/discovering-command-line-java-profiling-tools">Read on&#8230;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.enkitec.com/2012/05/discovering-command-line-java-profiling-tools/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VMSTAT Tools</title>
		<link>http://blog.enkitec.com/2012/02/vmstat-tools/</link>
		<comments>http://blog.enkitec.com/2012/02/vmstat-tools/#comments</comments>
		<pubDate>Sat, 18 Feb 2012 21:03:22 +0000</pubDate>
		<dc:creator>Jon Adams</dc:creator>
				<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://blog.enkitec.com/?p=605</guid>
		<description><![CDATA[As database administrators, we should have the ability to review and evaluate resources on the underlying hardware where our databases reside. Often this review is done during times of stress when there is a current performance problem. Fortunately, there are a number of tools that are useful for determining the resource usage on these platforms. [...]]]></description>
				<content:encoded><![CDATA[<p>As database administrators, we should have the ability to review and evaluate resources on the underlying hardware where our databases reside.  Often this review is done during times of stress when there is a current performance problem.  Fortunately, there are a number of tools that are useful for determining the resource usage on these platforms.  I will focus on the VMSTAT tool in this blog entry.</p>
<p>VMSTAT is a tool on Unix type plaforms that provides an impressive amount of resource information, but is formatted in such a way that it can be difficult to read much less determine when the snapshot occurred if looking at historic snapshots.  Here is an example</p>
<p>[root@new-host ~]# vmstat 2<br />
procs &#8212;&#8212;&#8212;&#8211;memory&#8212;&#8212;&#8212;- &#8212;swap&#8211; &#8212;&#8211;io&#8212;- &#8211;system&#8211; &#8212;&#8211;cpu&#8212;&#8212;<br />
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st<br />
 0  0      0 1916352  39376 906944    0    0   186    39 1024 1139  1  2 93  4  0<br />
 1  0      0 1916352  39384 906968    0    0     0    76 1015 1203  0  2 95  4  0<br />
 0  0      0 1916260  39392 906976    0    0     0    58 1014 1118  0  2 98  0  0</p>
<p>Through some simple Unix scripting commands, you can get more user-friendly information from this tool.</p>
<p>The vmstat_tool.sh script below works for most Linux versions:</p>
<p>#!/bin/sh<br />
#vmstat_tool.sh<br />
#vmstat parser script. Makes the information easily readable.</p>
<p>#Ensure that the number of loops and delay parameters<br />
#were passed to this script<br />
if [ $# -ne 2 ]<br />
then<br />
  echo &#8220;Usage: $0 <loop_count> <delay_in_seconds_between_loops>&#8221;<br />
  exit<br />
fi</p>
<p>export LPCNT=$1<br />
export DLAY=$2</p>
<p>c=0</p>
<p>while [ "$c" -lt $LPCNT ]<br />
do<br />
date<br />
vmstat | tail -n 1 | awk &#8216;{printf(&#8220;%d processes are waiting\n%d processes are blocked\n%d virtual memory used, %d idle memory, %d buffer memory, %d cache memory\n%d memory swapped in from disk, %d memory swapped out to disk\n%d blocks per second written\n%d blocks per second read\n%d interrupts per second\n%d context switches per second\nCPU usage: %d%% (user, non-kernel), %d%% (system, kernel), %d%% idle, %d%% wait\n\n&#8221;,$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16)}&#8217;</p>
<p>sleep $DLAY<br />
c=$((c+1))<br />
done</p>
<p>Sample Output (Single Loop):</p>
<p>Sat Feb 18 11:15:48 PST 2012<br />
1 processes are waiting<br />
0 processes are blocked<br />
0 virtual memory used, 1990308 idle memory, 32964 buffer memory, 843564 cache memory<br />
0 memory swapped in from disk, 0 memory swapped out to disk<br />
928 blocks per second written<br />
75 blocks per second read<br />
1062 interrupts per second<br />
1128 context switches per second<br />
CPU usage: 4% (user, non-kernel), 2% (system, kernel), 77% idle, 17% wait</p>
<p>As you can see. the output is much more readable than the regular vmstat output.</p>
<p>Should you need to do more than just a cursory examination of the VMSTAT output, you can use these scripts to generate an output file for examination with the following method:</p>
<p>nohup vmstat_tool.sh 288 300 > ./vmstat.log &#038;</p>
<p>In the above example, you are using the native nohup command to run the vmstat_tool.sh script to loop every 5 minutes (300 seconds) for 24 hours (288 5-minute loops).  The output will to the vmstat.log script in the local directory and will run in the background by using &#8216;&#038;&#8217; at the end of the command.  Examining the output is a simple matter of using the native cat and grep commands in the following manner:</p>
<p>cat ./vmstat.log | grep &#8220;processes are waiting&#8221; | more</p>
<p>Sample Output:</p>
<p>0 processes are waiting 0 processes are blocked<br />
0 processes are waiting 0 processes are blocked<br />
0 processes are waiting 0 processes are blocked<br />
0 processes are waiting 0 processes are blocked<br />
0 processes are waiting 0 processes are blocked<br />
0 processes are waiting 0 processes are blocked<br />
0 processes are waiting 0 processes are blocked<br />
0 processes are waiting 0 processes are blocked</p>
<p>You can now see the output of the first line of the VMSTAT tool scrolled one screen at a time.  If you see a line that has some abnormal values, you can then use the vi utility to zero in on that particular value and get the timestamp from it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.enkitec.com/2012/02/vmstat-tools/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My crsstat script: Improved Formatting of crs_stat on 10g and 11g</title>
		<link>http://blog.enkitec.com/2011/10/my-crsstat-script-improved-formatting-of-crs_stat-on-10g-and-11g/</link>
		<comments>http://blog.enkitec.com/2011/10/my-crsstat-script-improved-formatting-of-crs_stat-on-10g-and-11g/#comments</comments>
		<pubDate>Sat, 29 Oct 2011 03:08:53 +0000</pubDate>
		<dc:creator>Paul Elbow</dc:creator>
				<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://blog.enkitec.com/?p=525</guid>
		<description><![CDATA[My crsstat shows a tabular format of CRS or HAS resources (i.e. Cluster 10gR2-11gR2 or ASM/Single instance scenario 11gR2). It has been a work in progress for a while. When I first started working with 10gR2 RAC, I quickly discovered that I didn&#8217;t quite like the formatting of the default crs_stat -t output, so I [...]]]></description>
				<content:encoded><![CDATA[<p>My crsstat shows a tabular format of CRS or HAS resources (i.e. Cluster 10gR2-11gR2 or ASM/Single instance scenario 11gR2).  It has been a work in progress for a while.  When I first started working with 10gR2 RAC, I quickly discovered that I didn&#8217;t quite like the formatting of the default crs_stat -t output, so I wrote my first version of the crsstat script, which consisted of a korn shell script and an awk script (which gave pretty close to the same output as the current version).  I enhanced it at some point to show a different color, if the state didn&#8217;t match the target state.  Then 11gR2 came out and I really didn&#8217;t like the output, so I sat down and wrote the awk script to format the 11gR2 output and added a variable at the top to choose which awk script.  One of my colleagues saw it and liked the output, so I shared it; however, he asked if I could simplify the installation, as at that time you had to set the location of the script, whether it was 10g or 11g, and the location of the CRS_HOME.  Finally, I sat down and decided to make it as universal and easy to use, as I could by adding the awk scripts as variables within the ksh script and adding a section to attempt to determine the CRS or HAS home automatically.  It seems to work fairly well and several of my colleagues have been using it, so I thought I would share it more universally.  Hope everyone finds it useful!<br />
<span id="more-525"></span></p>
<h1>How it Works</h1>
<p>It should work with 10gR2-11gR2 without changes.  The first time is run, it will attempt to identify the Grid Infrastructure / CRS home and the version that is being used (CRS/HAS must be up for it to gather)- it takes that information and writes the info to a crsstat.env located in the same location as the script.  It only gathers the information the first time, so if you upgrade the Oracle software you will want to remove the crsstat.env and allow the script to re-gather the information.</p>
<p>The output of the script assumes a term width of 132 and attempts to highlight possible issues, by showing in RED those resources with a target of ONLINE and a state of OFFLINE.  You can also pass in “search criteria” as the first and only parameter.</p>
<p>Also of note, per Oracle support document 1086563.1, the “State Details” output in 11gR2 could show incorrect information, such as, “Instance Shutdown” even though it is up and running correctly.</p>
<p>Under the covers, the script is utilizing the “crs_stat -t” in 10gR2/11gR1 and “crsctl status resource -t” and then awks their output to create the tabular format.  It has been used on AIX and Linux (SuSE, Red Hat, Oracle).</p>
<h1>How to Install</h1>
<h2>Pre-requisite to Installation:</h2>
<p>1. CRS/HAS must be running<br />
2. The location of the crsstat script must be writable by the user that will run the installation (either root or your oracle user)</p>
<h2>Installation Location:</h2>
<p>Generally, it is practical to put the crsstat script in the /usr/local/bin directory, so everyone will have access (in most users path).  Make sure the crsstat.env file can be created in the /usr/local/bin directory the first time the script is run.  If it is preferred to put it an alternate location, choose a location that is accessible by your Unix users that should be able to list the CRS or HAS resources (i.e. in their PATH).</p>
<h2>Installation Process:</h2>
<p>1) Copy the installation script from this link <a href="http://blog.enkitec.com/wp-content/uploads/2012/07/crsstat.v1.2.2.zip">http://blog.enkitec.com/wp-content/uploads/2012/07/crsstat.v1.2.2.zip</a><br />
2) Do a &#8220;cp crsstat.v1.2.1.zip /usr/local/bin/&#8221;<br />
3) As root run the crsstat and a &#8220;crsstat.env&#8221; file is created:</p>
<pre style="padding-left: 60px;"># cd /usr/local/bin
# unzip crsstat.v1.2.1.zip
# chmod 755 crsstat
# ./crsstat</pre>
<p><em style="padding-left: 65px;">Output like example below&#8230;</em></p>
<pre style="padding-left: 60px;"># chmod 644 crsstat.env</pre>
<p>4) Verify that the crsstat.env file has two entries like the following:<br />
GRID_HOME=/u01/app/oracle/product/11.2.0/grid<br />
GRID_VER=11.2</p>
<h1>Example Usage</h1>
<p>Basic Usage (note that the dbfs filesystem is offline when it should be online, thus it is highlight in red):</p>
<pre style="padding-left: 30px; background-color: #000000;"><span style="color: #ffffff; background-color: #000000;">$ crsstat

Resource Name                            Resource Type  Target       State        Node            State Details
---------------------------------------- -------------- ------------ ------------ --------------- --------------
ora.DATA.dg                              diskgroup      ONLINE       ONLINE       tstdb01
ora.DATA.dg                              diskgroup      ONLINE       ONLINE       tstdb02
ora.LISTENER.lsnr                        Listener       ONLINE       ONLINE       tstdb01
ora.LISTENER.lsnr                        Listener       ONLINE       ONLINE       tstdb02
ora.LISTENER_SCAN1.lsnr                  SCAN Listener  ONLINE       ONLINE       tstdb02
ora.LISTENER_SCAN2.lsnr                  SCAN Listener  ONLINE       ONLINE       tstdb01
ora.LISTENER_SCAN3.lsnr                  SCAN Listener  ONLINE       ONLINE       tstdb01
ora.RECO.dg                              diskgroup      ONLINE       ONLINE       tstdb01
ora.RECO.dg                              diskgroup      ONLINE       ONLINE       tstdb02
ora.SYSTEM.dg                            diskgroup      ONLINE       ONLINE       tstdb01
ora.SYSTEM.dg                            diskgroup      ONLINE       ONLINE       tstdb02
ora.asm                                  ASM            ONLINE       ONLINE       tstdb01
ora.asm                                  ASM            ONLINE       ONLINE       tstdb02
ora.cvu                                  cvu            ONLINE       ONLINE       tstdb01
ora.dbfs.db                              database       ONLINE       ONLINE       tstdb01         Open
ora.dbfs.db                              database       ONLINE       ONLINE       tstdb02         Open
<span style="color: #ff0000;">ora.dbfs.filesystem                                     ONLINE       OFFLINE</span>
<span style="color: #ff0000;">ora.dbfs.filesystem                                     ONLINE       OFFLINE</span>
ora.demo.db                              database       ONLINE       ONLINE       tstdb01         Open
ora.demo.db                              database       ONLINE       ONLINE       tstdb02         Open
ora.demo.workshop.svc                    service        ONLINE       ONLINE       tstdb01
ora.demo.workshop.svc                    service        ONLINE       ONLINE       tstdb02
ora.tstdb01.vip                          Cluster VIP    ONLINE       ONLINE       tstdb01
ora.tstdb02.vip                          Cluster VIP    ONLINE       ONLINE       tstdb02
ora.net1.network                         Network (VIP)  ONLINE       ONLINE       tstdb01
ora.net1.network                         Network (VIP)  ONLINE       ONLINE       tstdb02
ora.ons                                  Ora Notif Svc  ONLINE       ONLINE       tstdb01
ora.ons                                  Ora Notif Svc  ONLINE       ONLINE       tstdb02
ora.registry.acfs                        registry       ONLINE       ONLINE       tstdb01
ora.registry.acfs                        registry       ONLINE       ONLINE       tstdb02
ora.scan1.vip                            SCAN VIP       ONLINE       ONLINE       tstdb02
ora.scan2.vip                            SCAN VIP       ONLINE       ONLINE       tstdb01
ora.scan3.vip                            SCAN VIP       ONLINE       ONLINE       tstdb01
ora.test.db                              database       OFFLINE      OFFLINE
ora.test.db                              database       OFFLINE      OFFLINE
</span></pre>
<p>A couple of examples using the search key:</p>
<pre style="padding-left: 30px; background-color: #000000;"><span style="color: #ffffff; background-color: #000000;">$ crsstat service

Resource Name                            Resource Type  Target       State        Node            State Details
---------------------------------------- -------------- ------------ ------------ --------------- --------------
ora.demo.workshop.svc                    service        ONLINE       ONLINE       tstdb01
ora.demo.workshop.svc                    service        ONLINE       ONLINE       tstdb02

$ crsstat demo

Resource Name                            Resource Type  Target       State        Node            State Details
---------------------------------------- -------------- ------------ ------------ --------------- --------------
ora.demo.db                              database       ONLINE       ONLINE       enkdb01         Open
ora.demo.db                              database       ONLINE       ONLINE       enkdb02         Open
ora.demo.workshop.svc                    service        ONLINE       ONLINE       enkdb01
ora.demo.workshop.svc                    service        ONLINE       ONLINE       enkdb02
</span></pre>
<p>Another example, as sometimes when there are many databases it is useful to pipe the output to grep:</p>
<pre style="padding-left: 30px; background-color: #000000;"><span style="color: #ffffff; background-color: #000000;">$ crsstat database | grep -i offline

ora.test.db                              database       OFFLINE      OFFLINE
ora.test.db                              database       OFFLINE      OFFLINE
</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.enkitec.com/2011/10/my-crsstat-script-improved-formatting-of-crs_stat-on-10g-and-11g/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Table Functions: 9i Feature Worth Revisiting (Part 2)</title>
		<link>http://blog.enkitec.com/2011/10/table-functions-9i-feature-worth-revisiting-part-2/</link>
		<comments>http://blog.enkitec.com/2011/10/table-functions-9i-feature-worth-revisiting-part-2/#comments</comments>
		<pubDate>Mon, 17 Oct 2011 22:14:25 +0000</pubDate>
		<dc:creator>Toby Marks</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[9i]]></category>
		<category><![CDATA[PIPE ROW]]></category>
		<category><![CDATA[PIPELINED]]></category>
		<category><![CDATA[TABLE]]></category>
		<category><![CDATA[Table Functions]]></category>

		<guid isPermaLink="false">http://blog.enkitec.com/?p=470</guid>
		<description><![CDATA[In part I of this series I showed a simple example of how table functions can be used to treat PL/SQL collection types as tables in a SQL query. We used a nested table collection type to which we manually added a few entries. In this example, I intend to show a more practical use [...]]]></description>
				<content:encoded><![CDATA[<p>In <a href="http://blog.enkitec.com/?p=407">part I of this series</a> I showed a simple example of how table functions can be used to treat PL/SQL collection types as tables in a SQL query. We used a nested table collection type to which we manually added a few entries. In this example, I intend to show a more practical use of table functions using all three PL/SQL collection types: associative arrays, nested tables, and VARRAYs.</p>
<p><span id="more-470"></span></p>
<p>Let&#8217;s revisit a use case I alluded to in my earlier blog entry: incorporating LDAP data into a query. Suppose your task is to code a custom authorization scheme for an enterprise application reporting system. You want row access to be determined by a user&#8217;s group memberships in the company&#8217;s Active Directory server. If a user is assigned to &#8220;the Company A group&#8221; in Active Directory, he gets to see Company A&#8217;s data. You can configure that kind of restriction at a database level using <a href="http://www.oracle.com/technetwork/database/security/index-088277.html">Oracle&#8217;s Virtual Private Database</a> feature. Configuring VPD is beyond the scope of this blog entry, but ultimately you will be associating a table to a portion of a SQL WHERE clause that gets appended to every query written against that table. You can find more documentation on VPD <a href="http://download.oracle.com/docs/cd/B28359_01/network.111/b28531/vpd.htm">on the OTN site</a>. In this case, let&#8217;s assume you know that another team has written a PL/SQL database package to query data from Active Directory, and you want to make use of that code. The only problem is that all the functions in that package return collections of various types, and you need to be able to access that information from the WHERE clause you are building with VPD. This is where table functions come in handy.</p>
<p>Let&#8217;s begin by setting up our example schema. We&#8217;ll be looking at client sales data. First, let&#8217;s set up our clients.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p470code37'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p47037"><td class="code" id="p470code37"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> clients <span style="color: #66cc66;">&#40;</span>
  client_id NUMBER<span style="color: #66cc66;">,</span>
  client_name VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> clients <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Timco Industries'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> clients <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">200</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Moneybros'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> clients <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">300</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'The Monacle Corporation'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> clients <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">400</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Schmapple'</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>We also need application users who will be logging in to view the report data. We&#8217;ll assume each application user is uniquely linked to a user in Active Directory via the external_id column.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p470code38'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p47038"><td class="code" id="p470code38"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> users <span style="color: #66cc66;">&#40;</span>
  sequence_number NUMBER<span style="color: #66cc66;">,</span>
  user_name VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
  external_id VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
  first_name VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">30</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
  last_name VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">30</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> users <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'JACKA'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'jaugusti'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Jack'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Augustine'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> users <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'KENKI'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'kkidd'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Ken'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Kidd'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> users <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'BRIAH'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'bhill'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Brian'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Hill'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> users <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'KEOVO'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'kvongkas'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Keo'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Vongkaseum'</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>Finally, we need a data table on which to report.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p470code39'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p47039"><td class="code" id="p470code39"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> quarterly_sales_data <span style="color: #66cc66;">&#40;</span>
  sequence_number NUMBER<span style="color: #66cc66;">,</span>
  client_id NUMBER<span style="color: #66cc66;">,</span>
  sales_year NUMBER<span style="color: #66cc66;">,</span>
  sales_quarter NUMBER<span style="color: #66cc66;">,</span>
  sales_amount NUMBER<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> quarterly_sales_data <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">100</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2011</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">20000</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> quarterly_sales_data <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">100</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2011</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">17500</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> quarterly_sales_data <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">100</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2011</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">33000</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> quarterly_sales_data <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">200</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2011</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">4500</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> quarterly_sales_data <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">200</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2011</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">7000</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> quarterly_sales_data <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">6</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">200</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2011</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">6300</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> quarterly_sales_data <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">7</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">300</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2011</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">11100</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> quarterly_sales_data <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">300</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2011</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">12800</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> quarterly_sales_data <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">9</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">300</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2011</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">14000</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> quarterly_sales_data <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">400</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2011</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">55600</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> quarterly_sales_data <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">400</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2011</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">80000</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> quarterly_sales_data <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">12</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">400</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2011</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">78500</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>Our basic report query will look something like this:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p470code40'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p47040"><td class="code" id="p470code40"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> client_name<span style="color: #66cc66;">,</span> sales_year<span style="color: #66cc66;">,</span> sales_quarter<span style="color: #66cc66;">,</span> sales_amount
  <span style="color: #993333; font-weight: bold;">FROM</span> quarterly_sales_data <span style="color: #993333; font-weight: bold;">NATURAL</span> <span style="color: #993333; font-weight: bold;">JOIN</span> clients;</pre></td></tr></table></div>

<p>Our Active Directory groups will be TIMCO_GRP, MONEYBROS_GRP, MONACLE_GRP, and SCHMAPPLE_GRP. If a user belongs to one or more of these groups, he has permission to view the respective client&#8217;s data.</p>
<p>Now we need a function that returns data from Active Directory. Just to keep it simple we will create a package that hardcodes the group memberships and returns them as collections of various types. We will then look at how table functions can be used to transform each one of those collections into an aggregate result set. (NOTE: querying LDAP directories from PL/SQL is not too difficult, and might serve as the basis for a future blog entry.)</p>
<p>Here&#8217;s our function. We&#8217;ve placed it in a package called LDAP_UTIL.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p470code41'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p47041"><td class="code" id="p470code41"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> PACKAGE ldap_util <span style="color: #993333; font-weight: bold;">AS</span>
&nbsp;
  TYPE ldap_entry_typ <span style="color: #993333; font-weight: bold;">IS</span> RECORD <span style="color: #66cc66;">&#40;</span>
    cn VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">30</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
    description VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1000</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
    distinguished_name VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">200</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
    name VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">30</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
    samaccountname VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">30</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  TYPE ldap_groups_nt <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">TABLE</span> OF ldap_entry_typ;
  TYPE ldap_groups_aa <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">TABLE</span> OF ldap_entry_typ <span style="color: #993333; font-weight: bold;">INDEX</span> <span style="color: #993333; font-weight: bold;">BY</span> PLS_INTEGER;
  TYPE ldap_groups_va <span style="color: #993333; font-weight: bold;">IS</span> VARRAY<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span> of ldap_entry_typ;
&nbsp;
  <span style="color: #993333; font-weight: bold;">FUNCTION</span> get_user_groups_nt <span style="color: #66cc66;">&#40;</span>p_user VARCHAR2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">RETURN</span> ldap_groups_nt;
  <span style="color: #993333; font-weight: bold;">FUNCTION</span> get_user_groups_aa <span style="color: #66cc66;">&#40;</span>p_user VARCHAR2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">RETURN</span> ldap_groups_aa;
  <span style="color: #993333; font-weight: bold;">FUNCTION</span> get_user_groups_va <span style="color: #66cc66;">&#40;</span>p_user VARCHAR2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">RETURN</span> ldap_groups_va;
&nbsp;
END ldap_util;
<span style="color: #66cc66;">/</span>
<span style="color: #993333; font-weight: bold;">SHOW</span> ERRORS
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> PACKAGE BODY ldap_util <span style="color: #993333; font-weight: bold;">AS</span>
&nbsp;
  <span style="color: #993333; font-weight: bold;">FUNCTION</span> get_user_groups_nt <span style="color: #66cc66;">&#40;</span>p_user VARCHAR2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">RETURN</span> ldap_groups_nt <span style="color: #993333; font-weight: bold;">IS</span>
    l_groups ldap_groups_nt :<span style="color: #66cc66;">=</span> ldap_groups_nt<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  BEGIN
    CASE p_user
      WHEN <span style="color: #ff0000;">'jaugusti'</span> THEN
&nbsp;
        l_groups<span style="color: #66cc66;">.</span>extend;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>cn :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'TIMCO_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>description :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Employees working on the Timco Industries account.'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>distinguished_name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'CN=TIMCO_GRP,OU=Global Groups,DC=acme,DC=com'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'TIMCO_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>samaccountname :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'TIMCO_GRP'</span>;
&nbsp;
      WHEN <span style="color: #ff0000;">'kkidd'</span> THEN
&nbsp;
        l_groups<span style="color: #66cc66;">.</span>extend;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>cn :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONEYBROS_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>description :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Employees working on the Moneybros account.'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>distinguished_name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'CN=MONEYBROS_GRP,OU=Global Groups,DC=acme,DC=com'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONEYBROS_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>samaccountname :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONEYBROS_GRP'</span>;
&nbsp;
      WHEN <span style="color: #ff0000;">'bhill'</span> THEN
&nbsp;
        l_groups<span style="color: #66cc66;">.</span>extend;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>cn :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'TIMCO_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>description :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Employees working on the Timco Industries account.'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>distinguished_name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'CN=TIMCO_GRP,OU=Global Groups,DC=acme,DC=com'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'TIMCO_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>samaccountname :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'TIMCO_GRP'</span>;
&nbsp;
        l_groups<span style="color: #66cc66;">.</span>extend;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>cn :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONACLE_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>description :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Employees working on the Monacle Corporation account.'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>distinguished_name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'CN=MONACLE_GRP,OU=Global Groups,DC=acme,DC=com'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONACLE_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>samaccountname :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONACLE_GRP'</span>;
&nbsp;
      WHEN <span style="color: #ff0000;">'kvongkas'</span> THEN
&nbsp;
        l_groups<span style="color: #66cc66;">.</span>extend;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>cn :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONEYBROS_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>description :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Employees working on the Moneybros account.'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>distinguished_name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'CN=MONEYBROS_GRP,OU=Global Groups,DC=acme,DC=com'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONEYBROS_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>samaccountname :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONEYBROS_GRP'</span>;
&nbsp;
        l_groups<span style="color: #66cc66;">.</span>extend;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>cn :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONACLE_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>description :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Employees working on the Monacle Corporation account.'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>distinguished_name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'CN=MONACLE_GRP,OU=Global Groups,DC=acme,DC=com'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONACLE_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>samaccountname :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONACLE_GRP'</span>;
&nbsp;
        l_groups<span style="color: #66cc66;">.</span>extend;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>cn :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'SCHMAPPLE_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>description :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Employees working on the Schmapple account.'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>distinguished_name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'CN=SCHMAPPLE_GRP,OU=Global Groups,DC=acme,DC=com'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'SCHMAPPLE_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>samaccountname :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'SCHMAPPLE_GRP'</span>;
&nbsp;
    END CASE;
    <span style="color: #993333; font-weight: bold;">RETURN</span> l_groups;
  END get_user_groups_nt;
&nbsp;
  <span style="color: #993333; font-weight: bold;">FUNCTION</span> get_user_groups_aa <span style="color: #66cc66;">&#40;</span>p_user VARCHAR2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">RETURN</span> ldap_groups_aa <span style="color: #993333; font-weight: bold;">IS</span>
    l_groups ldap_groups_aa;
  BEGIN
    CASE p_user
      WHEN <span style="color: #ff0000;">'jaugusti'</span> THEN
&nbsp;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>cn :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'TIMCO_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>description :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Employees working on the Timco Industries account.'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>distinguished_name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'CN=TIMCO_GRP,OU=Global Groups,DC=acme,DC=com'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'TIMCO_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>samaccountname :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'TIMCO_GRP'</span>;
&nbsp;
      WHEN <span style="color: #ff0000;">'kkidd'</span> THEN
&nbsp;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>cn :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONEYBROS_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>description :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Employees working on the Moneybros account.'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>distinguished_name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'CN=MONEYBROS_GRP,OU=Global Groups,DC=acme,DC=com'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONEYBROS_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>samaccountname :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONEYBROS_GRP'</span>;
&nbsp;
      WHEN <span style="color: #ff0000;">'bhill'</span> THEN
&nbsp;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>cn :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'TIMCO_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>description :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Employees working on the Timco Industries account.'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>distinguished_name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'CN=TIMCO_GRP,OU=Global Groups,DC=acme,DC=com'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'TIMCO_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>samaccountname :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'TIMCO_GRP'</span>;
&nbsp;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>cn :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONACLE_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>description :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Employees working on the Monacle Corporation account.'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>distinguished_name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'CN=MONACLE_GRP,OU=Global Groups,DC=acme,DC=com'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONACLE_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>samaccountname :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONACLE_GRP'</span>;
&nbsp;
      WHEN <span style="color: #ff0000;">'kvongkas'</span> THEN
&nbsp;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>cn :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONEYBROS_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>description :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Employees working on the Moneybros account.'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>distinguished_name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'CN=MONEYBROS_GRP,OU=Global Groups,DC=acme,DC=com'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONEYBROS_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>samaccountname :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONEYBROS_GRP'</span>;
&nbsp;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>cn :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONACLE_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>description :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Employees working on the Monacle Corporation account.'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>distinguished_name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'CN=MONACLE_GRP,OU=Global Groups,DC=acme,DC=com'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONACLE_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>samaccountname :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONACLE_GRP'</span>;
&nbsp;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>cn :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'SCHMAPPLE_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>description :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Employees working on the Schmapple account.'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>distinguished_name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'CN=SCHMAPPLE_GRP,OU=Global Groups,DC=acme,DC=com'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'SCHMAPPLE_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>samaccountname :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'SCHMAPPLE_GRP'</span>;
&nbsp;
    END CASE;
    <span style="color: #993333; font-weight: bold;">RETURN</span> l_groups;
  END get_user_groups_aa;
&nbsp;
  <span style="color: #993333; font-weight: bold;">FUNCTION</span> get_user_groups_va <span style="color: #66cc66;">&#40;</span>p_user VARCHAR2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">RETURN</span> ldap_groups_va <span style="color: #993333; font-weight: bold;">IS</span>
    l_groups ldap_groups_va :<span style="color: #66cc66;">=</span> ldap_groups_va<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  BEGIN
    CASE p_user
      WHEN <span style="color: #ff0000;">'jaugusti'</span> THEN
&nbsp;
        l_groups<span style="color: #66cc66;">.</span>extend;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>cn :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'TIMCO_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>description :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Employees working on the Timco Industries account.'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>distinguished_name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'CN=TIMCO_GRP,OU=Global Groups,DC=acme,DC=com'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'TIMCO_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>samaccountname :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'TIMCO_GRP'</span>;
&nbsp;
      WHEN <span style="color: #ff0000;">'kkidd'</span> THEN
&nbsp;
        l_groups<span style="color: #66cc66;">.</span>extend;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>cn :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONEYBROS_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>description :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Employees working on the Moneybros account.'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>distinguished_name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'CN=MONEYBROS_GRP,OU=Global Groups,DC=acme,DC=com'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONEYBROS_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>samaccountname :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONEYBROS_GRP'</span>;
&nbsp;
      WHEN <span style="color: #ff0000;">'bhill'</span> THEN
&nbsp;
        l_groups<span style="color: #66cc66;">.</span>extend;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>cn :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'TIMCO_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>description :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Employees working on the Timco Industries account.'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>distinguished_name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'CN=TIMCO_GRP,OU=Global Groups,DC=acme,DC=com'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'TIMCO_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>samaccountname :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'TIMCO_GRP'</span>;
&nbsp;
        l_groups<span style="color: #66cc66;">.</span>extend;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>cn :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONACLE_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>description :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Employees working on the Monacle Corporation account.'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>distinguished_name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'CN=MONACLE_GRP,OU=Global Groups,DC=acme,DC=com'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONACLE_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>samaccountname :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONACLE_GRP'</span>;
&nbsp;
      WHEN <span style="color: #ff0000;">'kvongkas'</span> THEN
&nbsp;
        l_groups<span style="color: #66cc66;">.</span>extend;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>cn :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONEYBROS_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>description :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Employees working on the Moneybros account.'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>distinguished_name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'CN=MONEYBROS_GRP,OU=Global Groups,DC=acme,DC=com'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONEYBROS_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>samaccountname :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONEYBROS_GRP'</span>;
&nbsp;
        l_groups<span style="color: #66cc66;">.</span>extend;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>cn :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONACLE_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>description :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Employees working on the Monacle Corporation account.'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>distinguished_name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'CN=MONACLE_GRP,OU=Global Groups,DC=acme,DC=com'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONACLE_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>samaccountname :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MONACLE_GRP'</span>;
&nbsp;
        l_groups<span style="color: #66cc66;">.</span>extend;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>cn :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'SCHMAPPLE_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>description :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Employees working on the Schmapple account.'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>distinguished_name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'CN=SCHMAPPLE_GRP,OU=Global Groups,DC=acme,DC=com'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>name :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'SCHMAPPLE_GRP'</span>;
        l_groups<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>samaccountname :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'SCHMAPPLE_GRP'</span>;
&nbsp;
    END CASE;
    <span style="color: #993333; font-weight: bold;">RETURN</span> l_groups;
  END get_user_groups_va;
&nbsp;
END ldap_util;
<span style="color: #66cc66;">/</span>
<span style="color: #993333; font-weight: bold;">SHOW</span> ERRORS</pre></td></tr></table></div>

<p>As you can see, LDAP_UTIL has three functions that return the three kinds of collections in PL/SQL: nested tables, associative arrays, and varrays.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p470code42'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p47042"><td class="code" id="p470code42"><pre class="sql" style="font-family:monospace;">  <span style="color: #993333; font-weight: bold;">FUNCTION</span> get_user_groups_nt <span style="color: #66cc66;">&#40;</span>p_user VARCHAR2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">RETURN</span> ldap_groups_nt;
  <span style="color: #993333; font-weight: bold;">FUNCTION</span> get_user_groups_aa <span style="color: #66cc66;">&#40;</span>p_user VARCHAR2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">RETURN</span> ldap_groups_aa;
  <span style="color: #993333; font-weight: bold;">FUNCTION</span> get_user_groups_va <span style="color: #66cc66;">&#40;</span>p_user VARCHAR2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">RETURN</span> ldap_groups_va;</pre></td></tr></table></div>

<p>The collections consist of a group of records representing &#8220;group&#8221; data from Active Directory.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p470code43'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p47043"><td class="code" id="p470code43"><pre class="sql" style="font-family:monospace;">  TYPE ldap_entry_typ <span style="color: #993333; font-weight: bold;">IS</span> RECORD <span style="color: #66cc66;">&#40;</span>
    cn VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">30</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
    description VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1000</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
    distinguished_name VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">200</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
    name VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">30</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
    samaccountname VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">30</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>The p_user parameter would be the user&#8217;s network id, corresponding to the sAMAccountName attribute in Active Directory; since we&#8217;re hardcoding group data this is not important to us at the moment. The point is you pass in a username and you get a collection of groups.</p>
<p>Using the same technique we demonstrated in part one, we now create a wrapper package of pipelined functions to transform the collection data into something we can query &#8211; an aggregate result set.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p470code44'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p47044"><td class="code" id="p470code44"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> PACKAGE ldap_util_pipelined <span style="color: #993333; font-weight: bold;">AS</span>
&nbsp;
  <span style="color: #993333; font-weight: bold;">FUNCTION</span> get_user_groups_nt <span style="color: #66cc66;">&#40;</span>p_user VARCHAR2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">RETURN</span> ldap_util<span style="color: #66cc66;">.</span>ldap_groups_nt PIPELINED;
  <span style="color: #993333; font-weight: bold;">FUNCTION</span> get_user_groups_aa <span style="color: #66cc66;">&#40;</span>p_user VARCHAR2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">RETURN</span> ldap_util<span style="color: #66cc66;">.</span>ldap_groups_nt PIPELINED;
  <span style="color: #993333; font-weight: bold;">FUNCTION</span> get_user_groups_va <span style="color: #66cc66;">&#40;</span>p_user VARCHAR2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">RETURN</span> ldap_util<span style="color: #66cc66;">.</span>ldap_groups_va PIPELINED;
&nbsp;
END ldap_util_pipelined;
<span style="color: #66cc66;">/</span>
<span style="color: #993333; font-weight: bold;">SHOW</span> ERRORS
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> PACKAGE BODY ldap_util_pipelined <span style="color: #993333; font-weight: bold;">AS</span>
&nbsp;
  <span style="color: #993333; font-weight: bold;">FUNCTION</span> get_user_groups_nt <span style="color: #66cc66;">&#40;</span>p_user VARCHAR2<span style="color: #66cc66;">&#41;</span> 
  <span style="color: #993333; font-weight: bold;">RETURN</span> ldap_util<span style="color: #66cc66;">.</span>ldap_groups_nt PIPELINED <span style="color: #993333; font-weight: bold;">IS</span>
    l_groups ldap_util<span style="color: #66cc66;">.</span>ldap_groups_nt;
  BEGIN
    l_groups :<span style="color: #66cc66;">=</span> ldap_util<span style="color: #66cc66;">.</span>get_user_groups_nt<span style="color: #66cc66;">&#40;</span>p_user<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #993333; font-weight: bold;">FOR</span> i <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">..</span> l_groups<span style="color: #66cc66;">.</span>count LOOP
      PIPE ROW <span style="color: #66cc66;">&#40;</span>l_groups<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
    END LOOP;
    <span style="color: #993333; font-weight: bold;">RETURN</span>;
  END get_user_groups_nt;
&nbsp;
  <span style="color: #993333; font-weight: bold;">FUNCTION</span> get_user_groups_aa <span style="color: #66cc66;">&#40;</span>p_user VARCHAR2<span style="color: #66cc66;">&#41;</span> 
  <span style="color: #993333; font-weight: bold;">RETURN</span> ldap_util<span style="color: #66cc66;">.</span>ldap_groups_nt PIPELINED <span style="color: #993333; font-weight: bold;">IS</span>
    l_groups ldap_util<span style="color: #66cc66;">.</span>ldap_groups_aa;
  BEGIN
    l_groups :<span style="color: #66cc66;">=</span> ldap_util<span style="color: #66cc66;">.</span>get_user_groups_aa<span style="color: #66cc66;">&#40;</span>p_user<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #993333; font-weight: bold;">FOR</span> i <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">..</span> l_groups<span style="color: #66cc66;">.</span>count LOOP
      PIPE ROW <span style="color: #66cc66;">&#40;</span>l_groups<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
    END LOOP;
    <span style="color: #993333; font-weight: bold;">RETURN</span>;
  END get_user_groups_aa;
&nbsp;
  <span style="color: #993333; font-weight: bold;">FUNCTION</span> get_user_groups_va <span style="color: #66cc66;">&#40;</span>p_user VARCHAR2<span style="color: #66cc66;">&#41;</span> 
  <span style="color: #993333; font-weight: bold;">RETURN</span> ldap_util<span style="color: #66cc66;">.</span>ldap_groups_va PIPELINED <span style="color: #993333; font-weight: bold;">IS</span>
    l_groups ldap_util<span style="color: #66cc66;">.</span>ldap_groups_va;
  BEGIN
    l_groups :<span style="color: #66cc66;">=</span> ldap_util<span style="color: #66cc66;">.</span>get_user_groups_va<span style="color: #66cc66;">&#40;</span>p_user<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #993333; font-weight: bold;">FOR</span> i <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">..</span> l_groups<span style="color: #66cc66;">.</span>count LOOP
      PIPE ROW <span style="color: #66cc66;">&#40;</span>l_groups<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
    END LOOP;
    <span style="color: #993333; font-weight: bold;">RETURN</span>;
  END get_user_groups_va;
&nbsp;
END ldap_util_pipelined;
<span style="color: #66cc66;">/</span>
<span style="color: #993333; font-weight: bold;">SHOW</span> ERRORS</pre></td></tr></table></div>

<p>Note the return types of the three functions in ldap_util_pipelined.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p470code45'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p47045"><td class="code" id="p470code45"><pre class="sql" style="font-family:monospace;">  <span style="color: #993333; font-weight: bold;">FUNCTION</span> get_user_groups_nt <span style="color: #66cc66;">&#40;</span>p_user VARCHAR2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">RETURN</span> ldap_util<span style="color: #66cc66;">.</span>ldap_groups_nt PIPELINED;
  <span style="color: #993333; font-weight: bold;">FUNCTION</span> get_user_groups_aa <span style="color: #66cc66;">&#40;</span>p_user VARCHAR2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">RETURN</span> ldap_util<span style="color: #66cc66;">.</span>ldap_groups_nt PIPELINED;
  <span style="color: #993333; font-weight: bold;">FUNCTION</span> get_user_groups_va <span style="color: #66cc66;">&#40;</span>p_user VARCHAR2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">RETURN</span> ldap_util<span style="color: #66cc66;">.</span>ldap_groups_va PIPELINED;</pre></td></tr></table></div>

<p>The first two return a nested table collection, while the third returns a VARRAY. These two collections can be pipelined because they correspond to native SQL datatypes in Oracle; not so for associative arrays. In order to pipeline the associative array returned from ldap_util.get_user_groups_aa, we need to map that collection to one of the other types. Here, we map it to a nested table. The iterative logic is the same, though, as the other two functions.</p>
<p>Now we can verify that our approach worked by issuing some simple queries, supported by the SQL &#8220;TABLE&#8221; construct.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p470code46'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p47046"><td class="code" id="p470code46"><pre class="sql" style="font-family:monospace;">SQL<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">select</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">from</span> <span style="color: #993333; font-weight: bold;">table</span><span style="color: #66cc66;">&#40;</span>ldap_util_pipelined<span style="color: #66cc66;">.</span>get_user_groups_nt<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'jaugusti'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
CN        DESCRIPTION                                        DISTINGUISHED_NAME                            NAME      SAMACCOUN
<span style="color: #808080; font-style: italic;">--------- -------------------------------------------------- --------------------------------------------- --------- ---------</span>
TIMCO_GRP Employees working <span style="color: #993333; font-weight: bold;">on</span> the Timco Industries account<span style="color: #66cc66;">.</span> CN<span style="color: #66cc66;">=</span>TIMCO_GRP<span style="color: #66cc66;">,</span>OU<span style="color: #66cc66;">=</span>Global Groups<span style="color: #66cc66;">,</span>DC<span style="color: #66cc66;">=</span>acme<span style="color: #66cc66;">,</span>DC<span style="color: #66cc66;">=</span>com  TIMCO_GRP TIMCO_GRP</pre></td></tr></table></div>

<p>As you can see, the individual attributes of the record structure form the columns of our new table, and we can reference those columns directly, if we wish.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p470code47'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p47047"><td class="code" id="p470code47"><pre class="sql" style="font-family:monospace;">SQL<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">select</span> cn <span style="color: #993333; font-weight: bold;">from</span> <span style="color: #993333; font-weight: bold;">table</span><span style="color: #66cc66;">&#40;</span>ldap_util_pipelined<span style="color: #66cc66;">.</span>get_user_groups_nt<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'kvongkas'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
CN
<span style="color: #808080; font-style: italic;">---------------</span>
MONEYBROS_GRP
MONACLE_GRP
SCHMAPPLE_GRP</pre></td></tr></table></div>

<p>All that&#8217;s left for us at this point is to construct a WHERE clause condition to use with Oracle&#8217;s Virtual Private Database feature to limit data returned from queries against the table QUARTERLY_SALES_DATA. That condition could look something like this, assuming that our application connects to the database as the logged in user.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p470code48'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p47048"><td class="code" id="p470code48"><pre class="sql" style="font-family:monospace;">client_id <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> CASE cn
                       WHEN <span style="color: #ff0000;">'TIMCO_GRP'</span> THEN <span style="color: #cc66cc;">100</span>
                       WHEN <span style="color: #ff0000;">'MONEYBROS_GRP'</span> THEN <span style="color: #cc66cc;">200</span>
                       WHEN <span style="color: #ff0000;">'MONACLE_GRP'</span> THEN <span style="color: #cc66cc;">300</span>
                       WHEN <span style="color: #ff0000;">'SCHMAPPLE_GRP'</span> THEN <span style="color: #cc66cc;">400</span>
                     END
                <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #993333; font-weight: bold;">TABLE</span><span style="color: #66cc66;">&#40;</span>ldap_util_pipelined<span style="color: #66cc66;">.</span>get_user_groups_nt<span style="color: #66cc66;">&#40;</span>USER<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>Here the mapping between AD group name and client ID is hardcoded in the CASE expression. A more flexible way would be to create a mapping table. Also, this is probably not a case study in writing a well performing VPD clause, but the real point here is that using SQL table functions and PL/SQL pipelined functions, we can translate data retrieved from an API, LDAP directory, or web service into table-like structures that we can query, join, and otherwise manipulate just like real tables.</p>
<p><script src="http://connect.facebook.net/en_US/all.js#appId=245406032159496&#038;xfbml=1"></script><br />
<script type="text/javascript" src="//platform.twitter.com/widgets.js"></script><br />
<script type="text/javascript">  (function() {    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;    po.src = 'https://apis.google.com/js/plusone.js';    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);  })();</script><br />
<script src="http://platform.linkedin.com/in.js" type="text/javascript"></script></p>
<div id="fb-root"></div>
<p><fb:like href="" send="false" layout="button_count" width="100" show_faces="false" font="arial"></fb:like><a href="https://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-via="toby_marks">Tweet</a><g:plusone size="medium"></g:plusone><script type="IN/Share" data-url="http://blog.enkitec.com/2011/10/table-functions-9i-feature-worth-revisiting-part-2/" data-counter="right"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.enkitec.com/2011/10/table-functions-9i-feature-worth-revisiting-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sizing up your environment for backups to tape</title>
		<link>http://blog.enkitec.com/2011/09/sizing-up-your-environment-for-backups-to-tape/</link>
		<comments>http://blog.enkitec.com/2011/09/sizing-up-your-environment-for-backups-to-tape/#comments</comments>
		<pubDate>Thu, 01 Sep 2011 16:11:52 +0000</pubDate>
		<dc:creator>Heath Boral</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Backups]]></category>
		<category><![CDATA[Exadata]]></category>
		<category><![CDATA[Sizing]]></category>
		<category><![CDATA[Tape]]></category>

		<guid isPermaLink="false">http://blog.enkitec.com/?p=444</guid>
		<description><![CDATA[So, you just spent many long hours putting together your latest and greatest creation. Hot off the presses, you have a true work of art. Now what? You are being audited on backups? You realize that there was no money for backup gear in the budget, but having this kind of risk over your head [...]]]></description>
				<content:encoded><![CDATA[<p>So, you just spent many long hours putting together your latest and greatest creation. Hot off the presses, you have a true work of art. Now what? You are being audited on backups? You realize that there was no money for backup gear in the budget, but having this kind of risk over your head can only be viewed as something to offload to an over-taxed shared services IT department at your org or a chance to play russian roullette with your data? No! It&#8217;s time to get an accurate assessment of what you need to backup and get your tape requirements sorted out so that you can present a case for your backups and any needed gear to get the job done. Don&#8217;t worry, you may not have to spend 2 trillion dollars on gear (unless you work for the government), especially if you already have a working environment to do your existing backups and just need to find/make capacity on the tape SAN. That being said, you still need to know what you&#8217;ll need to do or ask for and how can you do that if you just go to upper management and say, &#8221; I just got an Exadata and I need at least 48&#215;365 = 17520 TB of capacity in my tape backup gear to make sure we are covered for the year. Let&#8217;s not be greedy. Even the most novice executive will question the costs needed to satisfy that kind of requirement.</p>
<p>Making the assumption that you are using RMAN, you have already configured your backups to run a weekly full on each database to tape once per week, incrementals daily, and a reasonable amount of archivelogs being generated daily to the Fast Recovery Area, we can proceed to estimate your immediate needs.</p>
<p>If you are running Oracle and you are using RMAN, you can get the sizing numbers you need for your tape requirements somewhat easily if you are already taking backups to your Fast Recovery Area. There are a number of different views that can provide information about your backups, but I have found the most beneficial information can be gathered from the views used here. The helpful script that follows can be run to collect data on all the different types of backups you are currently running and the sizes (this script allows you to feed a list of SIDs):</p>
<p>#!/bin/bash</p>
<p>. /home/oracle/.bash_profile</p>
<p>ORAENV_ASK=NO</p>
<p>for DB in `echo &#8220;$DB_LIST&#8221;`; do<br />
export ORACLE_SID=$DB<br />
. oraenv $DB &gt;/dev/null</p>
<p>echo &#8220;Database: $DB&#8221;</p>
<p>sqlplus -s \/ as sysdba&lt;&lt;EOF<br />
set serveroutput on<br />
set linesize 150<br />
set pagesize 300</p>
<p>select ctime &#8220;Date&#8221;,</p>
<p>decode(backup_type, &#8216;L&#8217;, &#8216;Archive Log&#8217;, &#8216;D&#8217;, &#8216;Full&#8217;, &#8216;Incremental&#8217;) backup_type,bsize &#8220;Size GB&#8221; from (select trunc(bp.completion_time) ctime, backup_type, round(sum(bp.bytes/1024/1024/1024),2) bsize</p>
<p>from v\$backup_set bs,</p>
<p>v\$backup_piece bp where bs.set_stamp = bp.set_stamp and bs.set_count  = bp.set_count and bp.status = &#8216;A&#8217; group by trunc(bp.completion_time), backup_type) order by 1, 2;</p>
<p>exit;<br />
EOF<br />
done</p>
<p>You can then look at the history of your current backups and right-size your tape requirements.</p>
<p>You might also check how many archive logs you are generating in a week under full production load:</p>
<p>&nbsp;</p>
<p>col gbytes form 999,999.99</p>
<p>select sum(blocks*block_size)/1024/1024/1024 gbytes</p>
<p>from v$archived_log</p>
<p>where next_time &gt; sysdate-8;</p>
<p>&nbsp;</p>
<p>Some things to consider when you decide on your tape solution:</p>
<p>The type of tape drives</p>
<p>Encryption needs</p>
<p>The amount of compression</p>
<p>The number of tape drives</p>
<p>The type of backup software (OSB vs Netbackup vs Tivoli)</p>
<p>Your vaulting schedule (number of available media slots)</p>
<p>How fast can your channel send the data to the tape drives</p>
<p>Assuming you already have a tape SAN and you are not given enough money in your budget or enough lead time to get the gear in place before an audit, you might consider looking at what you have now in place and checking to see if you are doing too many backups, you have tuned your backups incorrectly, or if you have a number of backups that would benefit from VTL or dedup technologies in order to free space on your existing tape infrastructure.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.enkitec.com/2011/09/sizing-up-your-environment-for-backups-to-tape/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
