MacLochlainns Weblog

Michael McLaughlin's Technical Blog

Site Admin

Archive for April, 2009

Native Mac Oracle 10gR2

with 2 comments

I noticed today working with my students on downloads for the new term that Oracle finally released Oracle Database 10g Release 2 for Mac OS X Intel. That’s awesome until you see what it doesn’t include. You can find the installation instructions along with a list of unsupported products here. The real instructions are inside the zip file that you download.

If you’re like me, you’re asking: “When does Oracle Database 11g Release 1 for Mac OS X Intel ship?” However, I’m downloading it right now to test.

Written by maclochlainn

April 28th, 2009 at 11:52 pm

Posted in Mac,Oracle

Oracle XE Install

without comments

Some folks asked me to post Oracle Database 10g Express Edition step-by-step installation and how to setup an initial user/schema. There’s not much difference between the Windows and Linux installation but this one is the Windows XP installation.

Here are the eight steps required to run the MSI program:

1. Launch the MSI icon from your Windows Explorer:


2. Click the run button to extracing the zip file:


3. Click the Next button to run the Oracle Database 10g Expression Edition install wizard:


4. Accept the license agreement and click the Next button:


5. You can change the default installation base folder by clicking the Browse button, but why bother. Click the Next button to proceed.


6. This is the screen where you enter the privileged user account for the Oracle database. Make sure you’ll remember the password you enter. When you’ve entered it twice, click the Next button to continue the installation.


7. The Summary dialog shows you the ports for the installation. If you want to access this machine externally from the local host, you should open these ports for TCP transactions in your firewall. Click the Install button to proceed.


8. The last screen tells you that the InstallShield Wizard is complete. Make sure the Launch the Database homepage check box checked and click the Finish button to complete the installation.


After you’ve installed the database, you should immediately create a schema where you’ll work. The next steps show you how to create your own user/schema in the Oracle Database 10g XE instance.

1. The Database homepage provides you with a web login to the database. The only configured user at this point is the privileged user, which is known as the system user. The password to this account is the same as the one you entered during the product installation.


2. After you sign on to the database, you’ll be on the following console page. Click the Administration button on the far left.


3. The middle Database Users button in the web page allows you to create new database users. Click the Database Users image to proceed.


4. The Manage Database Users console lets you create or manage existing users. Click the Create button to create a new user.


5. The Create Database User console lets you enter a user name and password plus lets you grant necessary permissions to the new user. The entries on this form create a STUDENT user/schema with superuser responsibilities. The DBA role grants those superuser privileges. You click the Create button to setup a new user.


6. After you create the user, you’ll see the following screen. You can now click the Logout link to exit the application. Then, you can logon again as the STUDENT user.


I hope this meets the needs of new users.

Written by maclochlainn

April 23rd, 2009 at 12:34 am

Posted in pl/sql,Red Hat

VMWare and PowerShell

without comments

There is a nasty little surprise Microsoft PowerShell can deliver when you try to install it in a virtual machine. You can’t do it if you’ve built the VMWare Fusion instance with the default SCSI hard drive option.

It appears that Microsoft PowerShell, a prerequisite for Microsoft SQL Server 2008 Express edition, can’t work with the SCSI driver. At least, when I rebuilt the Microsoft Vista instance with an IDE hard drive it worked.

If anybody knows the details of why it fails, please share it with me and other readers.

Another tidbit about installing Microsoft SQL Server 2008 Express without having installed the .NET Development Suite, you must patch it. These were required on Microsoft Vista (32-bit) before you could successfully install SQL Server 2008 Express Edition.

1. Microsoft .Net Framework 3.5 SP1 (even if you’re more current).
2. Microsoft PluginInstall (verifies you’ve a licensed copy).
3. Microsoft Installer 4.5.
4. Microsoft Windows PowerShell 1.0.

The list of files for the installation on Windows Vista 32-bit are:


The installation screen shots from my earlier install are here. You must also import the correct certificate. A pre-installation Microsoft .NET Application Security warning will stop the installation completely. If you click the warning, you’ll see this message:


Enter the URL in your browser and you’ll get the following if it was successful.


I choose not to enable automatic updates because it often runs at awkward times. Ultimately, the installation worked fine.

Written by maclochlainn

April 20th, 2009 at 8:30 pm

External C Procedure

with 7 comments

Somebody wanted to know how to write an external procedure in C. I entered the reply as a comment and then thought it would be better as a blog post. Here are the instructions for deploying and calling an external procedure.

The quick list of things to do, summarized from Chapter 13 on External Procedures from my Oracle Database 11g PL/SQL Programming book are:

1. Configure your tnsnames.ora file with a callout listener, which is required because the IPC/TCP layers must be separated. That means your LISTENER should only support the TCP protocol, which means you’ll remove the IPC line from your listener.ora file. If you fail to take this step, you’ll encounter the following error:

ORA-28595: Extproc agent: Invalid DLL Path

Your callout listener has two parts, the CALLOUT_LISTENER and the SID_LIST_CALLOUT_LISTENER listener. Your listener.ora file should look like this:

                   (KEY = extproc)
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = <oracle_home_directory>)
      (PROGRAM = extproc)
      (ENV = "EXTPROC_DLLS=ONLY:/<customlib>/,LD_LIBRARY_PATH=/lib")

2. You also need to have a tnsnames.ora file with an instance TNS alias and EXTPROC alias, like:

               (HOST = <host_name>.<domain_name>)
               (PORT = 1521)
      (SERVICE_NAME = <database_sid>)
                 (KEY = EXTPROC)
      (SID = PLSExtProc)

3. Create a shared library, like this:

#include <stdio.h>
void writestr(char *path, char *message) {
  FILE *file_name;
  file_name = fopen(path,"w");
  fclose(file_name); }

4. In Linux, compile the shared library from Step #1 with the following syntax:

gcc -shared -o writestr1.c

If you encounter an error like this:

/usr/bin/ld: /tmp/ccTIWHVA.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/tmp/ccTIWHVA.o: could not read symbols: Bad value
collect2: ld returned 1 exit status

Then, use this alternative syntax:

gcc -shared -fPIC -o writestr.c

5. Create a library. Granting CREATE LIBRARY is a potentially large security risk, and a DBA should put all external procedure libraries in a single schema with additional monitoring protocols.

CREATE [OR REPLACE] LIBRARY library_write_string AS | IS '/<customlib>/

6. Write a wrapper to the library.

LIBRARY library_write_string
NAME "writestr"

7. Call the wrapper procedure with valid values:

  write_string('/tmp/file.txt','Hello World!');

Hope this helps some folks.

Written by maclochlainn

April 20th, 2009 at 6:50 pm

Posted in C,Oracle

VMWare, Spaces, and F8

with one comment

Starting writing with the new publisher’s template and found that I couldn’t use Word 2007 or Word 2008. I ran into a neat twist with the F8 key when building a Windows XP virtual machine for Word 2003. Whether inside or outside the virtual machine, the focus for the F8 key always stayed with Mac OS X. That meant F8 launches Spaces instead of letting the Windows XP install proceed.

The fix was simple enough, I disabled F8 as the launch key for Spaces. Then, it let the Windows XP install work.

Should that work around be there? It’s probably a bug in VMWare Fusion, Version 2.0 (116369). If you know for sure, let me and other readers know.

Written by maclochlainn

April 19th, 2009 at 12:20 am

Posted in Microsoft XP,VMWare


without comments

I noted a bug in the emca utility in this earlier blog on reconfiguring OEM. It manifest itself in Oracle 11g ( on the Windows platform. Testing found that it’s fixed in the new Oracle 11g ( This means you no longer have to manually drop the SYSMAN schema because the following command does that now, like it should.

C:\Data> emca -deconfig dbcontrol db -repos DROP

Written by maclochlainn

April 18th, 2009 at 12:46 am

VMWare and Fedora 10

without comments

It sometimes gets tiresome to sort the VMWare compatibility issues with Linux release-by-release but at the end of the cycle it’s fine. I downloaded the current Fedora 10 Live release because it is so much smaller than the install disk. It uses a kernel of I encountered a critical errors when I tried to install the VMWare Toolkit from VMWare Fusion, version 2.0.3 (156731). The only error guidance you’ll get is that there isn’t any make file.

There’s a twist here if you’re most familiar with Ubuntu and sudo command execution. You need to su to the root account and run everything as root user. An alternative would be to edit the /etc/inittab file to allow the root user to boot the instance. The default is 5 (X11). You enable the root user by changing it to 3 (full multiuser mode). Don’t forget to change it back, you really shouldn’t log in as the root user. Anyway, you’ll have to do it to run the VMWare Toolkit successfully as shown later in the post.

You fix the incompatibility of the VMWare Fusion Toolkit by downloading the following two missing RPMs. You should be able to find them here. As to why they’re not in the Live DVD distribution, who knows.


You can’t run some of them through the RPM utility, so you should probably run them all at the command line. The command line syntax and sequence for these packages is:

rpm -ivh kernel-headers-
rpm -ivh kernel-devel-
rpm -ivh binutils-
rpm -ivh libgomp-4.3.2-7.i386.rpm
rpm -ivh glibc-headers-2.9-2.i386.rpm
rpm -ivh glibc-devel-2.9-2.i386.rpm
rpm -ivh glibc-2.9-2.i686.rpm
rpm -ivh gcc-4.3.2-7.i386.rpm

As the root user, you can now install the VMWare Toolkit. While running the installation, you’ll receive a prompt to confirm the /usr/src/linux/include. Don’t accept the default path because it won’t work unless you created a symbolic link. The kernel header files require you to enter the following path:


Everything should work finxs e when you compile the modules. Hope this helps a couple folks.

Written by maclochlainn

April 11th, 2009 at 6:01 pm

Posted in Linux,Mac,Red Hat,VMWare

Aborting hung VMWare

without comments

Customizing the toolbar is one of the things that I’ve found important in using VMWare Fusion to test various Linux distributions. It’s nice they put Suspend by default on the toolbar but it would be nicer still if they put Shut Down. I got tired of looking for the PID to manually kill the virtualization from the Terminal command line. It is so much easier to add a Shut Down widget before trying to install VMWare Tools because that’s where some distributions hang.

Here are the steps to customize the toolbar:

1. Right click on the toolbar before running the VMWare instance, and you’ll see this context menu. Choose the Customize Toolbar… choice from the list.


2. The prior step lets you customize the toolbar though the following menu option dialog. Just click on the icon you want and drag it on to the toolbar. I’d suggest dragging Shut Down and Full Screen on to the toolbar.


I prefer putting the Shut Down to the left of the Suspend button, like this:


Hope this helps somebody.

Written by maclochlainn

April 11th, 2009 at 1:39 pm

T-SQL Hierarchical Query

with 5 comments

Playing around with Microsoft SQL Server 2008 Express edition, I’ve sorted through a bunch of tidbits. One that I thought was interesting, is how to perform a recursive or hierarchical query. This describes how you can perform the magic.

The official name of the WITH clause in Oracle’s lexicon (otherwise known as Oraclese) is a subquery factoring clause. You can find more on that in this earlier blog post. Microsoft has a different name for the WITH clause. They call it a Common Table Expression or CTE.

You perform recursive queries in Microsoft SQL Server 2008 by leveraging CTEs. I’ve modified the setup code from that earlier blog post to run in SQL Server 2008. You’ll find it at the bottom of this blog post.

Unless you want to write your own C# (.NET is the politically correct lingo) equivalent to Oracle’s SQL*Plus, you’ll need to run this script in the SQL Server Management Studio. Actually, you can use Microsoft SQL Server 2008’s command-line utility, which is called sqlcmd.exe but it is much less robust than SQL*Plus. In the Management Studio, you click File, then Open, and File… to load the file for execution, and then click the Execute button. You need to be careful you don’t click the Debug button, which is the green arrow to the right of the Execute button.


This is the magic query in the illustration. You can also find it in the source code. At the end of the day, I’m hard pressed to understand why they’d use a UNION ALL to support recursion.


The top-most CTE, or subquery factoring clause, simply joins the ORGANIZATION_NAME to the ORG_PARENT_ID and ORG_CHILD_ID columns to provide a single working source. The second CTE performs the recursion. The top-query sets the starting row, and the second query recursively navigates the tree. After all children are found, the first query moves to the next element in the table and recursively searches for its children.

You should note that the CTE self-references itself from inside the second query. Then, the external query (the non-CTE query) returns the results by querying the same CTE.

This logic behaves more like a nested loop, and actually fails to move down branches of the tree like a recursive program. Otherwise line 19 would be line 14 in the output. You could write another CTE to fix this shortfall, thereby mirroring a true recursive behavior, or you can write a stored procedure.

The illustrated query outputs the following hierarchical relationship, which navigates down the hierarchical tree:


You can also go up any branch of the tree by changing some of the logic. You’ll find the query to navigate up the tree as the second query in the setup script at the end of the blog. It renders the following output:


The blog will be updated if I discover the equivalent to the LEVEL in Oracle’s self-referencing semantics. If you know it, please share it with everybody.

Setup Script

Microsoft SQL Server 2008 Join Script

USE student;
-- Conditionally drop tables when they exist.
-- Create the organization table. 
( organization_id INT
, organization_name VARCHAR(10));
-- Seed the organizations. 
 (1,'One'), (2,'Two'), (3,'Three'), (4,'Four'), (5,'Five')
,(6,'Six'), (7,'Seven'), (8,'Eight'), (9,'Nine'), (10,'Ten')
,(11,'Eleven'), (12,'Twelve'), (13,'Thirteen'), (14,'Fourteen'), (15,'Fifteen')
,(16,'Sixteen'), (17,'Seventeen'), (18,'Eighteen'), (19,'Nineteen'), (20,'Twenty');
-- Create the organization structure table that holds the recursive key. 
CREATE TABLE org_structure
( org_structure_id INT
, org_parent_id INT
, org_child_id INT );
-- Seed the organization structures. 
INSERT INTO org_structure VALUES
 ( 1, 0, 1),( 1, 1, 2),( 1, 1, 3),( 1, 1, 4),( 1, 2, 5)
,( 1, 2, 6),( 1, 3, 7),( 1, 3, 8),( 1, 4, 9),( 1, 4,10)
,( 1, 5,11),( 1, 5,12),( 1, 6,13),( 1, 6,14),( 1, 7,15)
,( 1, 8,16),( 1, 8,17),( 1, 9,18),( 1, 9,19),( 1,14,20);
-- Navigating down the tree from the root node.
WITH org_name AS
 (SELECT   os.org_parent_id AS org_parent_id
  ,        o1.organization_name AS org_parent_name
  ,        os.org_child_id AS org_child_id
  ,        o2.organization_name AS org_child_name
  FROM     dbo.organization o1 RIGHT JOIN dbo.org_structure os 
  ON       o1.organization_id = os.org_parent_id RIGHT JOIN dbo.organization o2
  ON       o2.organization_id = os.org_child_id)
, jn AS
 (SELECT   org_parent_id, org_parent_name
  ,        org_child_id, org_child_name
  FROM     org_name
  WHERE    org_parent_id = 1  
  SELECT   c.org_parent_id, c.org_parent_name
  ,        c.org_child_id, c.org_child_name
  FROM     jn AS p JOIN org_name AS c
  ON       c.org_parent_id = p.org_child_id)
SELECT   jn.org_parent_id, jn.org_parent_name
,        jn.org_child_id, jn.org_child_name
FROM     jn
-- Navigating up the tree from the 20th leaf-node child.
WITH org_name AS
 (SELECT   os.org_parent_id AS org_parent_id
  ,        o1.organization_name AS org_parent_name
  ,        os.org_child_id AS org_child_id
  ,        o2.organization_name AS org_child_name
  FROM     dbo.organization o1 RIGHT JOIN dbo.org_structure os 
  ON       o1.organization_id = os.org_parent_id RIGHT JOIN dbo.organization o2
  ON       o2.organization_id = os.org_child_id)
, jn AS
 (SELECT   org_parent_id, org_parent_name
  ,        org_child_id, org_child_name
  FROM     org_name
  WHERE    org_child_id = 20  
  SELECT   c.org_parent_id, c.org_parent_name
  ,        c.org_child_id, c.org_child_name
  FROM     jn AS p JOIN org_name AS c
  ON       c.org_child_id = p.org_parent_id)
SELECT   jn.org_parent_id, jn.org_parent_name
,        jn.org_child_id, jn.org_child_name
FROM     jn

Written by maclochlainn

April 3rd, 2009 at 8:28 pm