Making the most of Oracle 18c XE – Pluggable Databases and the Oracle Eco-System

This was going to be a simple post about creating multiple Pluggable Databases (PDBs) in Oracle 18cXE.
But you know what it’s like, you get your lego database set out and then you spot those unusual shaped bricks… and the transparent ones… oh, that one has a wheel on…and get a bit carried away.
What follows is a guide on how to create three concurrent PDBs on an Oracle 18cXE database. However, I have taken the opportunity to investigate other areas of the Express Edition platform and so will be making use of Advanced Compression as well as Oracle Enterprise Manager Express.
In fact, I wouldn’t be surprised if SQLDeveloper put in an appearance as well.
I’ve also included a couple of the more notable members of Oracle’s small-but-perfectly-formed eco-system into the final design. On top of all that, I’ll be performing a magic trick to ensure that I only have to install each piece of software once, even though it may end up in multiple PDBs…
Continue reading

Running a shell script from inside an Oracle database using DBMS_SCHEDULER

As I write, various parts of the United Kingdom are still under variations of the theme of “lockdown”. Not that I’m stir crazy or anything but I’ve now decided it’s time to explore one way of escaping, from the confinements of my database, at least.

Specifically I’m going to :

  • create an OS user on the database server
  • create an OS group to allow both the new user and the oracle user to access to a common location
  • create a shell script owned by the OS user which writes to that common location
  • create a credential to access that user from inside the database itself
  • setup and run a scheduler job to execute a shell script as the new OS user
  • read the output file generated by the shell script from inside the database

For this exercise, I’m using my trusty 18cXE database running on CentOS… Continue reading

To Boldly gzip from PL/SQL

Lempel-Ziv. Sounds like something you might find on a starship. I mean, you can just imagine Scotty telling Kirk that they can’t go to warp because the Lempel-Ziv compressors are offline.
In fact, the Lempel-Ziv algorithm is what GNU’s Gzip program uses to compress files.
Fortunately, the UTL_COMPRESS package employs the same algorithm, which means that you can create archives using one tool that can be manipulated by the other…
Continue reading

Reading an OS file from inside an Oracle Database using an External Table

Two weeks into lockdown and some are looking to break the monotony by varying their diet…

For my part, I’ve decided to amuse myself by making a couple of “Top five” lists – the five best things about the lockdown and five things I’ve now finally got time to watch.

These lists are in text files are somewhere on my Database server and therefore provide the basis for the examples that follow.

When using Oracle, if you find yourself in a situation where you don’t have access to the Database Server file system, or would just rather use SQL to find what you’re looking for in a data set, you’re in luck.
The technique that used to be a neat way of viewing the database alert log from inside the database can now be re-purposed to look at any text file that’s located in a directory referenced by a Directory Object in the database.

What we’re going to look at here is :

  • Setting up an external table for reading from files
  • How to point the external table specific files and directories using EXTERNAL MODIFY
  • How achieve the same thing in 11gR2 databases with the help of DBMS_LOCK

First of all though, just in case you’re wondering….
Continue reading

Generating CSV files from PL/SQL the Very Easy Way.

This post is dedicated to Morten Braten and William Robertson.
Thanks to both of you for saving me a lot of time (and typing)…

XML, YAML, JSON. When it comes to transferring data between systems, they’ve all been flavour of the month at one time or another. However, good old CSV is still the format of choice when the batch window opens.
Not only is it simple, it adds comparatively little overhead to the size of the data file being generated.

OK – CSV used to mean “Comma-delimited” but these days it’s become synonymous with delimited data.
Whatever separator character you use, generating CSV is considerably easier these days…unless you’re using PL/SQL in a batch (as opposed to interactive) process.
That said, Connor MacDonald does have a clever way of utilising the functionality available in a command line tool such as SQL*Plus by means of a DBMS_SCHEDULER job.

If for some reason that won’t work for you, it looks like you’re going to have to hack out some custom PL/SQL to get the job done…or you could have a look at a couple of the options available in what other technologies would refer to as “the ecosystem”.
What I’m going to cover is :

  • The pain of hand-cranking delimited SQL
  • A solution offered in Morten Braten’s Alexandria PL/SQL Utility Library
  • An alternative solution made available by William Robertson
  • The final PL/SQL procedure
  • Continue reading

    Running a “background” job in PL/SQL

    Teddy has observed the recent General Election campaign with some interest and has concluded that he has what it takes to be the next Prime Minister.

    It’s not just the haircut, which does now look extremely Prime Ministerial…

    Politics is a robust business but Teddy’s more than capable of playing “ruff” :

    He firmly believes in the need to streamline Government at Cabinet level, which has the incumbent Chief Mouser to the Cabinet Office a little nervous.
    He’s also well used to being followed around by a “pooper scooper”. And not to put too fine a point on it, there’s more than one reason that he’s known as a “shaggy” dog.

    If he’s going to make it in politics, Teddy knows that he doesn’t have time to waste waiting for that pesky long-running job he’s just started. Oh no, he needs to use his evenings to get on with building his power base.
    Fortunately, Oracle facilitates detached execution of PL/SQL blocks by means of the DBMS_SCHEDULER package. Now, I know what you’re thinking, that’s going to involve a lot of fiddly setup with schedules and windows and chains and stuff. Well, you may be pleasantly surprised…
    Continue reading

    Putting VALIDATE_CONVERSION front and centre, or possibly center

    I recently had an interesting conversation with Suzanne, a native of Pittsburgh PA, about how the Americans and British spell some words differently.
    Adding some local colour ( color) to the discussion, Suzanne recounted the story of when the US Postal service, seeking to save money on printing, proposed removing “superfluous” characters from place names.
    Well, the burghers of Pittsburgh weren’t having any of that thank-you-very-much and so the City’s name remains unabridged to this day. The denizens of Harrisburg weren’t so fortunate.
    Whilst we may be separated by a common language, as programmers who work with Oracle, Suzanne and I do share the challenge of loading data into tables when the format of that data may not be entirely what we were expecting.
    If you’re fortunate enough to inhabit the sunlit uplands of Oracle 12c R2 and beyond, we’re about to explore the shiny new VALIDATE_CONVERSION function which promises to make your life that little bit easier.
    For those languishing on 11g, we’ll explore how we might implement a similar function in PL/SQL.
    Continue reading

    Making yourself at home in SQLDeveloper

    I had to configure a new work laptop recently. This task was complicated somewhat by many of the usual issues us techies face when working for a large organization.
    Admin privileges are out of the question. Pre-packaged applications are out-of-date and modern open-source development tools tend to fall foul of seemingly arbitrary security policies.
    As a result, I’ve had to rely even more than usual on the Swiss Army Knife of the Oracle database.
    Fortunately, there’s more to SQLDeveloper than getting stones out of horses hooves. So much so, in fact, that I’ve decided to arbitrarily declare that it’s now SQLDeveloper Appreciation Month. This is largely because, in exploring it’s capabilities, I’ve found myself with enough material to knock out a number of posts over the next few weeks.
    It seems appropriate to begin this journey with a look at how you can make SQLDeveloper feel a bit more homely.
    How can you encourage this most configurable of tools to do all the things you find so helpful whilst at the same time curbing some of it’s less endearing habits ?
    Quite often, the answer can be found in the Preferences Tree.

    About now, I’d normally give you a list of topics I’ll be covering. First of all though, for anyone who has found their way here in a desparate search for how to tweak something specific in this tool, here are links to the relevant sections of the post :

    Note that the steps for navigating from the menu to the Preferences tree is included in each of these sections.
    If you’ve the time and inclination to read the post from the top, I hope that you’ll forgive the repitition. Oh, and you’ll probably also still want to know what I’m going to cover :

    • Customising the Look and Feel of the Code Editor
    • Getting SQLDeveloper to Format your code just the way you like it
    • Saving yourself lots of typing with a code template
    • Customising SQLDeveloper Utilities defaults because life’s too short to be ticking boxes
    • Miscellaneous tweaks to make you feel more at home
    • If all else fails, ask Jeff Smith

    One more thing before we get started. This post is intended to show you where these settings are. The values I set them to are according to my preferences which may not be shared by everyone (anyone ?) even though they’re absolutely the right way to do things because…well…they just are OK ?!

    Right then, from the Tools menu select Preferences…

    Continue reading

    Oracle and Alternative Facts – generating test data with DBMS_RANDOM

    There’s a bug in DBMS_RANDOM.VALUE. It consistently fails to return the correct set of lotter numbers.
    On the plus side, it is surprisingly useful when you find yourself in a situation which is all too common for a Data Warehouse developer.
    There’s a requirement for a new feed into your Warehouse from another system. You’ve managed to agree the file specification – what data will be included in the file, datatypes etc, but the developers working on the upstream system won’t be able to start providing test files for loading for weeks yet. Meanwhile, you need to start writing your code to ingest the feed.
    Fortunately, you have all the tools available to :

    • Generate lots of rows of test data
    • Generate random values for strings, numbers and dates
    • Use a set of pre-defined values randomly in your data generation

    First of all, let’s take a look at…
    Continue reading