ORA-03113: end-of-file on communication channel. This was the error that greeted me after many hours work converting some PL/SQL scripts to run as a package of functions, views and stored procedures.
My first thought was actually that something or someone had terminated my connection to the database. Given that I was working on a DEV/TEST instance, I wouldn’t necessarily have expected to be notified about a momentary disruption to service. After reconnecting and repeating the same and other queries, it became clear the only thing causing this was one of the procedures in a package I had written.
I tried a few changes without any success and then decided to call it a day, with the intention of speaking to the one of the DBAs the following day to see if they could provide any further information.
As it turned out, I didn’t have get in touch with the DBAs… The next morning they were already looking for me!
It turns out that the error which had been unexpectedly terminating my connection had been causing an access violation followed by a core dump on the server. Of course this is the kind of thing that raises all kind of alerts even on a development/test instance.
Continue reading ORA-07445 Error in a MERGE query
At the end of the previous post, I showed the results of a query displaying an organisational hierarchy in tree form.
This post covers the query that was used to produce that.
Continue reading Hierarchical Data Part 3: Displaying the Tree
In the first post of this series, we saw a simple table representing a real-world hierarchy and the simplest of queries on that data, and finished with the question: “What else might we do with this data?”
Maybe we need to know the chain of responsibility leading from a particular position up to the top of the organisation.
Or, perhaps we would like to report on a subsection of the tree – for example, listing everyone working directly or indirectly below the Financial Director.
And what if we want to see what this organisational structure looks like?
For all of these, we can use recursive queries.
Continue reading Hierarchical Data in SQL Part 2: Recursive Queries with an Adjacency List
One of the most obvious examples of hierarchical data frequently stored in a database is the organisational hierarchy of employees and their managers.
Typically this follows a one-to-many parent-child relationship whereby each employee reports to a single manager above them, and may have zero or more employees below them who they manage.
This tree is likely to have a relatively shallow structure, perhaps no more than 10 levels deep even in an organisation of 100,000 employees.
The simplest method of storing and maintaining a tree of this type is for each record to include a reference to its parent.
You may see this referred to as an “Adjacency List Model”.
It is worth noting that an adjacency list is a type of Relationship Graph, and that our example is a special case in which we want the graph to form a tree structure.
Representing a tree in this way allows us to easily write simple queries to access the nodes immediately adjacent to a given node (above or below them in the hierarchy), but requires us to use recursion if we wish to query data spanning further levels of the tree.
Continue reading Hierarchical Data in SQL Part 1: The Adjacency List
Over a series of articles, I will be writing about and demonstrating some of the ways in which hierarchical data can be stored, queried and presented using SQL. The primary focus will be Microsoft SQL Server, followed by Oracle, but there may also be some sections dedicated to other platforms.
I will update this page with links to the subsequent posts as and when they are added.
In a previous post, I wrote about partitioned outer joins in Oracle.
The simple schema and queries in that post are similar to those I used when first learning about this feature. At the time, I came upon an unexpected error which caused some Oracle instances to throw an ORA-600 error from a very simple query.
The original test environment I had been using was Oracle Database 11g Enterprise Edition 22.214.171.124.0 running on Solaris.
I had created a simple schema to experiment with, and written a couple of queries which returned results designed to illustrate the effect of a partitioned join as compared with other types of joins.
Once I had them doing what I wanted, I decided to discuss them with a colleague, who tried running the on his local instance of Oracle Express 126.96.36.199.0 on Windows.
Instead of the expected results, he received the following error:
ORA-00600: internal error code, arguments: [kkoipt:invalid aptyp], , , , 
Continue reading ORA-600 Error in a Partitioned Join
From 10g onwards Oracle has had a type of join called a Partitioned Outer Join, providing a convenient syntax which can be used to fill gaps in sparse data.
The documentation describes the result of a partitioned outer join as “a UNION of the outer joins of each of the groups in the logically partitioned table with the table on the other side of the join.”
To demonstrate what this means in practice, I will run through a simple example.
We will start with two very simple tables, products and sales, which look like this:
Continue reading Partitioned Outer Joins in Oracle
UTL_FILE.GET_RAW fails on long lines if the file is opened in text mode.
Today while debugging a previously developed PL/SQL package, I had to investigate an ORA-29284: file read error.
The cause was not immediately apparent, as the procedure had been reading in and parsing other files ok, and had read in this particular file just fine up until it reached a certain point.
The file being read was text rather than binary, but the code was using GET_RAW not GET_LINE since the process was not interested in line breaks. With a little investigation, it turned out that the place where the error occurred was when the procedure began trying to read from a line which was 175,000 characters long.
If you’ve used the functions in UTL_FILE, then you’ll know that functions like GET_LINE support a maximum line size and buffer size of 32767 bytes. However in this case, the call to GET_RAW was specifying a much smaller number of bytes to read. So why did it fail? Continue reading ORA-29284 File Read Error with UTL_FILE.GET_RAW