Passing parameters in SQL*Plus – or What’s the opposite of a Chick Flick ?

Watching Iron Man 2 the other night, I was somewhat surprised by a brief appearance on screen of someone who looked remarkably like Larry Ellison.
No, he wasn’t the villain although – depending on what Oracle ends up doing to MySQL – he could be a candidate for the role in Iron Man 3.
As a result of riding this cinematic rollercoaster, I experienced two profound revalations.
The first is that, despite it’s poor relation status in the array of tools available to the Oracle developer, SQL*Plus can still be incredibly useful ( OK, I’ve always thought this – but I’m flashing my Poetic License here and no, it hasn’t expired yet).
The second is that the opposite of a Chick Flick must be a Bloke Buster. I know, I should really just stick to the programming stuff.
Continue reading


Slave Driving – Getting SQL*Plus to do it for you

In my haste to play around in my shiny new Oracle XE instance, I’ve forgotten to set the Default Tablespace for any new users I create.
As a result I’ve got few tables and indexes in the SYSTEM tablespace. Fortunately, I don’t have to go through the drudgery of moving all of them by hand, I can get SQL*Plus to do it for me. Continue reading

Installing Oracle XE on Ubuntu 9.10

Right, time to install XE on Ubuntu 9.10. Here goes….

Before we go any further, I think I should point out that I’m running the 32-bit desktop version of Ubuntu – Ubuntu Server is for another machine on another day.

My reasons for installing Oracle are simply to have a database to play around with, so I don’t have to worry about multiple concurrent connections, or even setting up the Oracle client on machines I want to be able to connect from. I’ll be connecting from the machine I’m running the database on.

Update – since I wrote this post, Oracle have released 11gXE. You can find installation instructions for this newer version for Mint and Ubuntu here.

Something else worth mentioning is that I’ve got a bit of “previous” on this score.

I installed XE on Ubuntu 8.10 a while back, and hit a few issues with being able to run the menu options that get added to the Applications menu.

Something else I noticed about the process was the need to run lots of commands that were doing stuff I wasn’t necessarily up to speed on. This meant lots of referencing various man pages to make sure I wasn’t doing anything rash.

So this time, I’m going to try and do as much as possible through GUI tools…and try to get everything working properly.

One of the big pluses in getting Oracle to run on Linux is that you can then mess around doing clever things with shell scripts. However, interacting with the database via a script does require that you’ve configured everything to allow SQL*Plus to be invoked from the command line.

Bearing all this in mind, I’m approaching the task this time with the following objectives :-

  • Get Oracle XE up and running with minimal command-line intervention
  • Get the menus working from the Ubuntu desktop
  • Get SQL*Plus up and running from the shell

Getting the software

Right, first thing we need is the software itself. Rather than following the usual routine of going to the oracle site and downloading the software, I thought I’d see if I could take advantage of the Linux software package management utilities.

We’re in luck. Oracle does indeed provide a repository containing a variety of goodies, including XE.

So, what we’ll need to do first is to add the repository to the package repository database.

In 9.10, there’s this new utility called the Ubuntu Software Centre, so I thought I’d start there.

  1. From the Ubuntu Applications menu, select Ubuntu Software Centre
  2. From the Edit menu, select Software sources…At this point you’ll be prompted for your password
  3. In the Software Sources window, select the Other Software Tab.
  4. Click Add

In the pop-up window, type in the following as the APT line :-

deb unstable main non-free

and click Add Source

You should now see this repository in the list.

  1. Check the box next to the repository and click Close
  2. Close the Ubuntu Software Centre window

If you want to double-check that the repository is now added, just open a Terminal session and type :-

cat /etc/apt/sources.list

You should see the new repository as the last entry in this list.

Unfortunately, the Ubuntu Software Centre doesn’t recognise this repository , so in order to actually obtain the software, we’ll need to use Synaptic Package Manager
To actually download the software from the repository :-

  1. From the Ubuntu System menu select Administration and then Synaptic Package Manager. Enter your password when prompted.
  2. In the Quick search field, type oracle-xe
  3. Remember, I’m going to be running the database and connecting to it all from one machine, so I don’t need the oracle-xe-client package. So, as I just want the Western European Edition, I just select the oracle-xe package.
    NOTE – if you want a language other than English, I think you need to choose the oracle-xe-universal package instead.
  4. Once you’ve marked the appropriate package, hit the Apply button.
  5. Synaptic now downloads two packages – libaio and oracle-xe.

Once the download is complete, we’re ready to install the software.


At this point, we really do need to go to the command line.

In a new Terminal session type the following :-

sudo /etc/init.d/oracle-xe configure
You will now be prompted for 4 bits of information :-

  • the Oracle Application Express (APEX) http port ( defaults to 8080)
  • the port for the database (TNS) listener ( 1521)
  • the password to be used for the SYS and SYSTEM database accounts
  • whether or not you want the database to start on boot (y)

NOTE – I’ve made a couple of changes to the default – I already have Apache installed so I need to use a different port. Also, I want the database to start when I choose, rather than automatically.

The TNS listener port can safely be set to 1521 ( or 1526) as these ports are known as defaults for the TNS listener so no other automatically configured software on your system should be using it.

The session looks something like this.

Oracle Database 10g Express Edition Configuration


This will configure on-boot properties of Oracle Database 10g Express

Edition. The following questions will determine whether the database should

be starting upon system boot, the ports it will use, and the passwords that

will be used for database accounts. Press <Enter> to accept the defaults.

Ctrl-C will abort.

Specify the HTTP port that will be used for Oracle Application Express [8080]:8081

Specify a port that will be used for the database listener [1521]:

Specify a password to be used for database accounts. Note that the same

password will be used for SYS and SYSTEM. Oracle recommends the use of

different passwords for each database account. This can be done after

initial configuration:

Confirm the password:

Do you want Oracle Database 10g Express Edition to be started on boot (y/n) [y]:n

Starting Oracle Net Listener...Done

Configuring Database... Done

Starting Oracle Database 10g Express Edition Instance...Done

Installation Completed Successfully.

To access the Database Home Page go to ""

To check that the database is up and running, try accessing your database home page via a web browser.
If the page comes up, you’re up and running.

Getting the Menu Options to Work

You’ll also notice that the Ubuntu Applications Menu now has an entry called Oracle Database 10g Express Edition which has a number of options in it’s sub-menu…none of which will work right now.

In order to run these options, you’ll need to make yourself a member of the os DBA group that’s been created as part of the installation.

To do this :-

  1. Go to the Ubuntu System menu and select Administration and then Users and Groups
  2. Click the button with the picture of the keyring and enter your password
  3. Go to the dba group and then click Properties
  4. Click the checkbox next to your user
  5. Exit the Users and Groups tool.

Hey presto, the menu options will now work.

To test this :-

  1. Go to Applications / Oracle Database 10g Express Edition and click Stop Database This will stop the tns listener, shutdown the database, and the http listener.
  2. To verify this, try accessing the Database Home Page again. This time you should get a Page Not Found error.
  3. Now go back to the menu and this time click on Start Database. Give it a few seconds then try to access the Database Home Page again.
    This time, it should come up. If it doesn’t, it’s possible that the database is still starting up, so give it a bit more time and then try again.

Getting SQL*Plus to run from the shell

There is a menu option in the Oracle Database 10g Express Edition menu that lets you connect to the database via SQL*Plus.

All you need to do is click on this then at the SQL prompt type :-

connect system/password_you_set_during_install@XE
What I’m trying to do here is a bit different. I want to be able to invoke SQL*Plus from a Terminal session ( or a batch script).

Once again, we have to go to the command line to achieve this.

Remember, Oracle “sort of” supports Ubuntu as an OS for XE, but only sort of. The oracle supplied shell script that sets the environment variables to allow it’s command line utilities ( including SQL*Plus) to run, isn’t especially happy in the bash shell. So, you need to make a minor change to one line to get it to execute.

The file in question is /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/

Open this file in whatever editor takes your fancy and change the line :-


To :-


Assuming you’re using the default Ubuntu setup ( bash is your shell), you can either copy the contents of this file wholesale into the .bashrc file in your home directory, or you can point to it in this file. Either way, after saving the change to .bashrc the next time you start a terminal session, you’ll find three new environment variables set on startup. To check this, open a Terminal session and type


This should return /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/


This should return XE

echo $NLS_LANG

This will return the character set for your database setup ( in my case ENGLISH_UNITED KINGDOM.AL32UTF8 )

And finally, you can now invoke SQL*Plus from the command line :-

$ sqlplus uid/pwd

SQL*Plus: Release - Production on Mon Dec 7 01:16:38 2009

Copyright (c) 1982, 2005, Oracle. All rights reserved.

Connected to:

Oracle Database 10g Express Edition Release - Production


Conclusion…and an acknowledgement

Oracle XE is now up and running on Ubuntu. Now I can do some real damage 😀

My initial ( mostly) successful installation attempt on 8.10 was done with reference to the guide at

If you prefer your installations done on the command line, this is worth checking out, but I hope I’ve brought this a bit more up to date.

One final note of caution – Oracle XE is pretty much delivered “as is”. Whilst it is wonderfully useful for playing around with an Oracle database, it does have some limitations. Not least of these is that, unlike it’s big brother (currently Oracle 11g Release 2), Oracle don’t produce quarterly security patches for it. This means that you should think carefully before you go and use it in a production environment.

I was lucky enough to attend a presentation by Alexander Kornbrust at UKOUG in 2006 in which he graphically demonstrated these limitations. You can find his presentation here.

Edit – Cannot reach Database Home Page after restart

Hmmm….I thought that was too easy !
After re-starting my computer, I found I could no longer get the Database Home Page coming up.
After much cursing and puzzlement, I’ve tracked down the problem to the listener.ora file.

This file is used to control the configuration of the TNS Listener which process traffic to APEX, which sits inside the database.

To fix this annoying glitch…

Open up a Terminal session

cd $ORACLE_HOME/network/admin
sudo gedit listener.ora

change the line




Effectively you are commenting out this line.

Save and exit.

Go to the Start Database option in the Oracle Menu (under applications).

You need to give it a couple of minutes because the TNS listener gets started after the database does.

You should now be able to get to the Home Page.

Please let me know if this works for you.

UPDATE – I’ve now written an Installation Troubleshooting Guide, which you may want to check out if things still aren’t working as they should.
There’s also an introduction to PL/SQL here if you’re interested.

SQLDeveloper or TOAD

Judging by the title I suppose your expecting some exhaustive ( exhausting ?) comparison between the giants of the Oracle IDE world ( or if you’ve been here before, another ramble through the remnants of my sanity).

So, before I launch into my treatise on why SQL*Plus is better than both, it’s only fair that I share with you the fruits of my in depth, impartial research.

Only one test was required – put them into Googlefight.

In case your not aware of it, is the URL – simply put in two search terms and watch them fight it out !

For the record, “TOAD” beats “SQLDeveloper”, “SQLDeveloper” beats “Quest TOAD” and, most gratifyingly, “SQL*Plus” knocks seven bells out of the pair of them !

That’s the pretence of impartiality out of the way, now for the bias and invective. Are you sitting comfortably ?

When I’m writing anything more complex than a simple, one time SQL statement, I’ll use Textpad. Syntax highlighting, no annoying code auto-completion popping up and inserting an option or keyword I don’t want, and when I want to compile/test, I just shell out and run SQL*Plus. Simple.

If I want to do any admin on the database, I’ll always use the command line – whether it’s running object creation scripts or general housekeeping tasks, I want to know that the database is doing exactly what I’ve asked it to do and the IDE isn’t trying to do anything clever behind my back.

One major reason for my reluctance to use an IDE for DDL is the propensity for it to crash partway through the statement, leaving the target object locked by a zombie session that you then have to hunt down and kill in the OS. Toad was particularly renowned for this at one point.

Another amusing “quirk” of both tools is that they tend to let you get away with some funky stuff where escaped quotes inside strings are concerned. Whereas SQL*Plus will give you an ORA-01756 “Quoted string not properly terminated”, the IDEs will just chug on. The results are likely to be other than what was intended.

In SQLDeveloper especially, when you do get an error message, it seems to be a bit hazy on the line number. Sometimes it’s a bit reluctant to divulge the actual error message.

At this point I usually just cut and paste the offending statement into SQL*Plus and magically…it still doesn’t run. However, I do get a better idea of what’s going on and where.

I do use an IDE to browse database program units and other schema objects, and maybe take advantage of the explain plan or session monitor features from time to time.

The one utility I did find invaluable at some point is TOAD’s schema comparison tool, so much help when trying to synchronize code between environments without being able to just replicate the database.

Having said all of that, I must confess a preference for SQLDeveloper over it’s amphibian rival ( what is it about animals and software – toads, penguins, koalas – it’s a veritable menagerie).

OK, it’s not a smooth as Toad ( a by-product of being a Java Application), but it has a couple of things going for it that really appeal.

First, it’s cheap ( i.e. free). In the current climate, it’s worth considering that, if your shelling out tens of thousands of pounds for any software site license, that more or less equates to someone’s job.

Secondly, it’s easily extensible. You can write your own reports and save them for easy reference. More impressively, you can add your own tabs to an object view window.

Also, I’ve now found the setting that turns of the automatic code completion feature unless I specifically invoke it.

I’ve already posted about creating a report in SQLDeveloper and I’ll probably write something on adding a tab in the future.

In the meantime, hello Textpad, my old friend.