Showing posts with label Oracle. Show all posts
Showing posts with label Oracle. Show all posts

Thursday, 12 December 2024

Postgres and Migrating Databases

So, it's doable to transfer all data from an Oracle database structure into a similar (hopefully exactly the same) database structure in Postgres.

One of the problems you encounter, is the Foreign Keys. These will get triggered when inserting data .

Now, in a perfect scenario, you know that the Oracle database structure, which also has the same Foreign Keys, is fine, so we won't need to check the Foreign Keys in Postgres when inserting data.

You cannot turn off Foreign Keys in Postgres, however, Postgres automatically creates system triggers for Foreign Keys that check if referential integrity is maintained.

So it simply comes down to temporarily disabling those triggers.

ALTER TABLE some_table DISABLE TRIGGER ALL;

And afterwards, enable them again.

ALTER TABLE some_table ENABLE TRIGGER ALL;

Problem

But what is not all data was successfully transferred? (due to network problems for instance). Now you have a Postgres database that no longer has referential integrity in all cases and you might not find out about this until God knows when.

So, you need to check afterwards if all the Foreign Keys are accounted for, i.e. does every value for a foreign key have an equivalent row in the related table?

I found a script for this at [1].

References

[1] Github.com - enrico-lt/ForeignKeyCheck
https://github.com/enrico-lt/ForeignKeyCheck

Friday, 23 February 2024

Migrating Oracle to PostgreSQL

So at work we're currently trying to see if we can move away from Oracle and onto PostgreSQL.

I expect this to be a long process.

This blog post is here to document some of the issues we ran into and also remember references I found.

Migrating schema and data

There are several tools that can migrate the schema and the data from Oracle to Postgres.

There are some differences in what both database support. See reference [1].

Make changes to SQL Scripts

References

[1] Hackermoon - How to Migrate from Oracle to PostgreSQL
https://hackernoon.com/how-to-migrate-from-oracle-to-postgresql
Postgres Wiki - Oracle to Postgres Conversion
https://wiki.postgresql.org/wiki/Oracle_to_Postgres_Conversion
PostgreSQL Manuals
https://www.postgresql.org/docs/
Ora2Pg - Moves Oracle and MySQL database to PostgreSQL
https://ora2pg.darold.net/
Life in USA - install ora2pg on mac osx
https://vcfvct.wordpress.com/2016/10/18/install-ora2pg-on-mac-osx/

Friday, 29 December 2023

The DUAL table

I'm working with Oracle databases (version 19 for now), and I always wondered about the weird DUAL table1 that I require in my work.

Things like this:

select sysdate from dual;
select seq_s_ordertable.nextval from dual;

Well, apparently we have Charles "Chuck" Weiss2 to thank for it.

One of the reasons is that the FROM clause in Oracle SQL syntax is mandatory.

Interestingly, Charles originally created the DUAL table with two rows, hence the name DUAL. Nowadays it's one row, but the name's stuck.

It's part of the Data Dictionary of the SYS user. Changing the DUAL table will cause problems!3

References

[1] Wikipedia - DUAL table
https://en.wikipedia.org/wiki/DUAL_table
[2] Wikipedia - Charles Weiss
https://en.wikipedia.org/wiki/Charles_Weiss
[3] Ask tom - All about the DUAL table
https://asktom.oracle.com/ords/f?p=100:11:0::::P11_QUESTION_ID:1562813956388

Saturday, 30 July 2022

How to UPSERT (INSERT or UPDATE) rows with MERGE in Oracle Database

It's awesome! A colleague of mine uses merge for batch jobs, as it is a great deal quicker.

Unfortunately, performance seems to drop when using it to insert/update individual entries.

Thursday, 20 February 2020

Spatial Information in an Oracle Database

SDO_GEOMETRY

This is here for me to remember how much magic is used in inserting spatial (geometry) information into an Oracle database1.

CREATE TYPE sdo_geometry AS OBJECT (
SDO_GTYPE NUMBER,
SDO_SRID NUMBER,
SDO_POINT SDO_POINT_TYPE,
SDO_ELEM_INFO SDO_ELEM_INFO_ARRAY,
SDO_ORDINATES SDO_ORDINATE_ARRAY);

A point geometry:

MDSYS.SDO_GEOMETRY(
    2001, -- 2-dimensional (2), non-linear referencing geometry or default (0), point (01)
    28992, -- Amersfoort / RD New
    NULL, 
    MDSYS.SDO_ELEM_INFO_ARRAY(1, 1, 1),
    MDSYS.SDO_ORDINATE_ARRAY(81431.756, 455218.921))

A polygon geometry:

MDSYS.SDO_GEOMETRY(
    2003, -- 2-dimensional (2), non-linear referencing geometry or default (0), polygon (03)
    28992, -- Amersfoort / RD New
    NULL,
    MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1), -- first coordinate (1), exterior (1003), polygon (1)
    MDSYS.SDO_ORDINATE_ARRAY(
        -1041172.16,1407540.16,
        -958596.8,-591471.68,
        1363835.2,-625878.08,
        1319106.88,1428184,
        -1041172.16,1407540.16) -- coordinates
)

A multipolygon geometry:

MDSYS.SDO_GEOMETRY(
    2007, -- 2-dimensional (2), non-linear referencing geometry or default (0), MULTIPOLYGON or MULTISURFACE (07)
    28992, -- Amersfoort / RD New
    NULL, 
    MDSYS.SDO_ELEM_INFO_ARRAY(1, 1003, 1, 11, 2003, 1), 
    MDSYS.SDO_ORDINATE_ARRAY(42, 78, 41, 85, 46, 82.7, 45, 79, 42, 78, 43.5, 72.5, 52.5, 72.5, 54.5, 79.5, 79, 60, 93, 46, 53, 32, 54, 25, 49, 22, 45, 17, 41, 16, 37, 23, 33, 24, 25, 20, 33, 46, 39, 53, 43.5, 72.5))

The only thing that makes sense among all the magic numbers are the coordinates. The last coordinate is the same as the first coordinate to close the polygon.

I since have found some more information after some digging regarding the SDO_ELEM_INFO.

It's an array of triplets, where a triplet consists of:

SDO_STARTING_OFFSET
offset within the coordinates array, the first triplet usually has "1" as being the first coordinate in the coordinate array
SDO_ETYPE
type of element
SDO_INTERPRETATION
depends on if SDO_ETYPE is a compound element

I found more information in [2].

WKT - Well-known text representation of geometry

"POLYGON ((194232.738 467652.498, 194232.774322728 467652.19885542, 194232.881179968 467651.917096035, 194232.738 467652.498))"
"POINT (31256.383 393077.6)"
"MULTIPOLYGON(((42 78, 41 85, 46 82.7, 45 79, 42 78),(43.5 72.5, 52.5 72.5, 54.5 79.5, 79 60, 93 46, 53 32, 54 25, 49 22, 45 17, 41 16, 37 23, 33 24, 25 20, 33 46, 39 53, 43.5 72.5)))"

It's possible to create SDO_GEOMETRY in PL/SQL based on WKT strings.

Like so:

SELECT SDO_GEOMETRY('MULTIPOLYGON(((42 78, 41 85, 46 82.7, 45 79, 42 78),(43.5 72.5, 52.5 72.5, 54.5 79.5, 79 60, 93 46, 53 32, 54 25, 49 22, 45 17, 41 16, 37 23, 33 24, 25 20, 33 46, 39 53, 43.5 72.5)))') FROM DUAL;

Convenient if you want to do something quick, but you cannot provide additional information regarding the dimensions, and coordinate system, etc.

Let me rephrase that sentence. It means your resulting geometrie has NO SRID, and you'll get in trouble using it in geometry queries! This is not a joke!

The reverse (if you want to find out the geometrie in WKT format, basically because it reads easier) is of course also possible, like so:

SELECT SDO_UTIL.TO_WKTGEOMETRY(geometry) FROM buildinggeo;

Geometry Functions

So I was playing around with ConvexHull, ConcaveHull and ConcaveHull-Boundary functions.

I took the MultiPolygon in the paragraph above as an example.

SELECT SDO_GEOM.SDO_CONVEXHULL(MDSYS.SDO_GEOMETRY(
2007, -- 2-dimensional (2), non-linear referencing geometry or default (0), multipolygon (07)
28992, -- Amersfoort / RD New
NULL,
MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1,11,2003,1), -- first coordinate (1), Simple polygon whose vertices are connected by straight line segments (1003,1), 11th coordinate (11), Simple polygon whose vertices are connected by straight line segments (1003,1)
MDSYS.SDO_ORDINATE_ARRAY(42, 78, 41, 85, 46, 82.7, 45, 79, 42, 78,
43.5, 72.5, 52.5, 72.5, 54.5, 79.5, 79, 60, 93, 46, 53, 32, 54, 25, 49, 22, 45, 17, 41, 16, 37, 23, 33, 24, 25, 20, 33, 46, 39, 53, 43.5, 72.5) -- coordinates
), 1)
FROM dual;
-- creates MDSYS.SDO_GEOMETRY(2003, 28992, NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1, 1003, 1), MDSYS.SDO_ORDINATE_ARRAY(41, 16, 45, 17, 93, 46, 79, 60, 54.5, 79.5, 41, 85, 25, 20, 41, 16))
SELECT SDO_GEOM.SDO_CONCAVEHULL(MDSYS.SDO_GEOMETRY(
2007, -- 2-dimensional (2), non-linear referencing geometry or default (0), multipolygon (07)
28992, -- Amersfoort / RD New
NULL,
MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1,11,2003,1), -- first coordinate (1), Simple polygon whose vertices are connected by straight line segments (1003,1), 11th coordinate (11), Simple polygon whose vertices are connected by straight line segments (1003,1)
MDSYS.SDO_ORDINATE_ARRAY(42, 78, 41, 85, 46, 82.7, 45, 79, 42, 78,
43.5, 72.5, 52.5, 72.5, 54.5, 79.5, 79, 60, 93, 46, 53, 32, 54, 25, 49, 22, 45, 17, 41, 16, 37, 23, 33, 24, 25, 20, 33, 46, 39, 53, 43.5, 72.5) -- coordinates
), 0.1)
FROM dual;
-- creates MDSYS.SDO_GEOMETRY(2003, 28992, NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1, 1003, 1), MDSYS.SDO_ORDINATE_ARRAY(41, 85, 42, 78, 43.5, 72.5, 39, 53, 33, 46, 25, 20, 41, 16, 45, 17, 54, 25, 53, 32, 93, 46, 79, 60, 54.5, 79.5, 46, 82.7, 41, 85))
SELECT SDO_GEOM.SDO_CONCAVEHULL_BOUNDARY(MDSYS.SDO_GEOMETRY(
2007, -- 2-dimensional (2), non-linear referencing geometry or default (0), multipolygon (07)
28992, -- Amersfoort / RD New
NULL,
MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1,11,2003,1), -- first coordinate (1), Simple polygon whose vertices are connected by straight line segments (1003,1), 11th coordinate (11), Simple polygon whose vertices are connected by straight line segments (1003,1)
MDSYS.SDO_ORDINATE_ARRAY(42, 78, 41, 85, 46, 82.7, 45, 79, 42, 78,
43.5, 72.5, 52.5, 72.5, 54.5, 79.5, 79, 60, 93, 46, 53, 32, 54, 25, 49, 22, 45, 17, 41, 16, 37, 23, 33, 24, 25, 20, 33, 46, 39, 53, 43.5, 72.5) -- coordinates
), 0.1, 0.01)
FROM dual;
-- creates MDSYS.SDO_GEOMETRY(2003, 28992, NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1, 1003, 1), MDSYS.SDO_ORDINATE_ARRAY(41, 85, 33, 46, 25, 20, 41, 16, 45, 17, 54, 25, 53, 32, 93, 46, 79, 60, 54.5, 79.5, 41, 85))

I will expand on this blog post, as my knowledge in this area is expanded.

References

[1] Spatial and Graph Developer's Guide - 2.2 SDO_GEOMETRY Object Type
https://docs.oracle.com/database/121/SPATL/sdo_geometry-object-type.htm#SPATL489
[2] Spatial and Graph Developer's Guide - 2.2.4 SDO_ELEM_INFO
https://docs.oracle.com/database/121/SPATL/sdo_geometry-object-type.htm#SPATL494
Spatial and Graph Developer's Guide - 2.1 Simple Example: Inserting, Indexing, and Querying Spatial Data
https://docs.oracle.com/database/121/SPATL/simple-example-inserting-indexing-and-querying-spatial-data.htm#SPATL486

Tuesday, 22 August 2017

Opening Up Java EE

DZone mentioned1 that David Delabassee said on The Aquarium2 that Oracle wishes to move JEE technologies including reference implementations and test compatibility kit to an Open Source Foundation.

For more information on how and why, you'll have to check out the original post of David Delabassee.

References

[1] DZone - Oracle Opening Up Java EE
https://dzone.com/articles/oracle-opening-up-java-ee
[2] The Aquarium - Opening Up Java EE
https://blogs.oracle.com/theaquarium/opening-up-java-ee
AgileJava by Ivar Grimstad
http://www.agilejava.eu/2017/08/18/oracle-opening-up-java-ee/

Sunday, 19 April 2015

Java 8 - Beta Exam Attempt

Well, last Wednesday, 15 April 2015, I tried to get certified in Java 8 by taking the Upgrade to Java SE 8 Programmer Exam. It contained 126 questions and I was given 3 hours to provide all the answers.

For more information on what topics are required reading, see reference [1].

Given the fact that I am not yet comfortable with the new features of Java 8, answering the questions took a lot of time. I was unable to complete the last 12 questions due to this.

The beta exam is now no longer available.

I'll have to wait approximately 11 weeks for a result, though. A long time to wait, but that's always the case with Beta exams.

At least it's behind me now. Next up is trying to get certified with Scrum.

Thoughts

Here are some of my thoughts:
  • there were a number of 'trick' questions
  • learn the method signatures of java.util.function, luckily the naming scheme is extremely consistent
  • learn the difference between the source of stream, the intermediate operations, and the terminal operations. Here's some pointers:
    • a stream, once evaluated, can no longer be used. Trying causes an InvalidStateException.
    • omitting a terminal operation, causes the Stream to not be evaluated at all.
    • using two terminal operations, of course, causes a compile error
    • a stream doesn't change the underlying source
  • learn the additional operations now available (using Lambdas) on the already existing Collections of the Collection framework
  • learn when an interface is a functional interface. Here's some pointers:
    • @FunctionalInterface is not a requirement
    • what happens when you add default methods?
    • what happens when you add an abstract method?
    • what happens when you add an abstract method, whose signature is equivalent to an existing method in the Object class?
    • what happens when you add a static method?
    • what happens to a functional interface that inherits from another interface
  • Remember what Daylight Saving Time is, the clock is advanced by one hour during summer months (in March), the clock is returned to normal time (turned back one hour) during the winter months (in October)
  • practice,... a lot ([2] is a good reference with exercises)

References

[1] 1Z1-810 Upgrade to Java SE 8 Programmer
https://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=5001&get_params=p_exam_id:1Z0-810
[2] Java SE8 for the Really Impatient
Cay S. Horstmann

Wednesday, 4 March 2015

Sequence Generators and Hibernate

Hibernate has a Hi-Lo Sequence Generator that maps to a Database Sequence (for example Oracle Sequence) with a multiplication.

What this means is, when you retrieve the next value from the Database Sequence (which returns 1), Hibernate will multiply that with a "allocationSize", the default for which is 50.

Now Hibernate can (stored at application level) use it to create PK numbers from 1 to 50.

The next time a Database Sequence value is retrieved (for example 2), Hibernate gets to create PK numbers 51 to 100.

Conclusion

This seems to be a valuable strategy, if your database sees a lot of inserted records and high loads and the sequence starts to be a bottleneck.

This can be a valid issue, for example when you run Batch jobs that cause a lot of inserts for every transaction.

Caveat Emptor

The reason for this blog is that a Colleague of mine at work, got a customer on the phone who was spooked, as his new PKs suddenly were a noticable factor bigger.

And, of course, it is a living hell to change this sequence schema afterwards to something more simple, as you run the risk of duplicate PKs.

Quote

“Only think of database sequences as unique - nothing more, nothing less.”
This means that the one task of a sequence generator is to provide you with values that have not been used yet, not will they be ever again.

It is an error, to assume that there is any kind of ordering in the numbers issued, or that there are no 'holes' in the sequence.

References

Vlad Mihalcea's Blog - The hi/lo algorithm
http://vladmihalcea.com/2014/06/23/the-hilo-algorithm/
JavaDocs 7 - SequenceGenerator
http://docs.oracle.com/javaee/7/api/javax/persistence/SequenceGenerator.html
StackOverflow - Hibernate, @SequenceGenerator and allocationSize
http://stackoverflow.com/questions/12745751/hibernate-sequencegenerator-and-allocationsize
Fixing JPA2 Sequence Generator Problem With Hibernate 3.5
http://www.petrikainulainen.net/programming/tips-and-tricks/fixing-jpa2-sequence-generator-problem-with-hibernate-3-5/

Sunday, 1 February 2015

Java SE 8 Certification


SInce the beginning of the year, this year, 2015, it is possible to enter the Beta Exam for the Oracle Certified Professional, Java SE 8 Programmer.

Naturally, I'm going to give it a go.

The Beta Exam has only recently been (informally) announced, so it might be a while before I can post any more information about how it was.

References

[1] 1Z1-810 Upgrade to Java SE 8 Programmer
https://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=5001&get_params=p_exam_id:1Z0-810

Tuesday, 25 March 2014

Java 8 - Launch!

I have just witnessed the Live Webcast1 of the Oracle Java 8 Launch. It seems that Java 8 is officially2 launched.

I hear Java 8 was already released in the wild on the 18th of March, but this seems to be the Live Webcast of the Launch. Introducing Java 8 was Mark Reinhold3, the Chief Architect of the Java Platform Group at Oracle.

He was joined by some well known Software Developers:
  • Brian Goetz, core Java Language Architect at Oracle.
  • Robert Vandette, Technical Lead for Mobile Edition, does Compact Profiles.
  • Roger Riggs, new Date and Time API. Spec lead of ME 8.
  • Richard Bair, Java Client Architect, JavaFX 8.
  • John Rose, JVM Architect.
Java 8 Powers the Internet Of Things
Some notes in the promotional blurb at the beginning of the webcast:
  • Nine Million Java Developers
  • #1 Development Platform
  • Increased Developer Productivity
  • Revolutionary Platform Release
Some non-exhaustive list of things available in the new release for Java 8:
  • Lambda Expressions
  • Streams
  • Type Annotations
  • Date and Time API
  • Compact Profiles
  • Nashorn Javascript Engine
Java 8 is a Community Technology
There are several Java 8 sessions available to watch at [1].

References

[1] Java 8 Launch Webcast
http://www.oracle.com/events/us/en/java8/index.html
[2] Java 8 Launch Webcast - Overview
http://eventreg.oracle.com/profile/web/index.cfm?PKWebId=0x637279c68
[3] Mark Reinhold’s Blog - JDK 8: General Availability
http://mreinhold.org/blog/jdk8-ga
Everything about Java 8
http://www.techempower.com/blog/2013/03/26/everything-about-java-8/
A deeper look into the Java 8 Date and Time API
http://www.mscharhag.com/2014/02/java-8-datetime-api.html

Wednesday, 29 January 2014

1Z0-807 Java EE 6 Enterprise Architect Certified Master Exam

follow-up of [2]

Pfew! Made it! Woohoo! I had answered 73% of questions correctly, and I needed 71%. I should've studied more.

It is Multiple-Choice, and some of the wrong possible answers are really quite close to correct.

Then again, who has to answer a Architectural Question in their business careers in less than 2.5 minutes on average, really?

On to the next step, the Assignment!!

The exam

Most of the exam questions were regarding business use cases.

The exam questions can be broadly separated into three distinct categories:
use cases
of imaginary companies seeking to change/re-evaluate (a part of) their current outdated infrastructure in some fashion
questions on design patterns
when to use them, what their characteristics are, etc. *)
questions on JEE technologies
when would you apply which technologies, given some Non-Functional Requirements (NFR)

*) Seems the books "Core J2EE Patterns", "Real World Java EE Patterns: Rethinking Best Practices" and "Design Patterns: Elements of Reusable Object-Oriented Software" really did help, and were fascinating reads in and of themselves.

References

[1] 1Z0-807 Java EE 6 Enterprise Architect Certified Master Exam
http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=5001&get_params=p_exam_id:1Z0-807
[2] Architect Enterprise Applications with Java EE - Course
http://randomthoughtsonjavaprogramming.blogspot.nl/2013/09/architect-enterprise-applications-with.html

Sunday, 1 December 2013

Oracle Timestamp vs. Date

Recently have been hitting a brick wall due to a bug at work.

Query doesn't return any results if the date is "2009-06-01 00:00:00:01". But for the date "2009-06-01 00:00:00:00" it works fine.

The table is as follows:

And contains:
ID CODE STARTDATE ENDDATE
103581900/01/01 00:00:00:000000(null)

/* Formatted on 28/11/2013 17:02:58 (QP5 v5.227.12220.39754) */
SELECT *
FROM MUNICIPAL municipal1_  
WHERE municipal1_.code='0358'
AND (TO_TIMESTAMP('2009/06/01:00:00:01:01', 'yyyy/mm/dd:hh24:mi:ss:FF2') BETWEEN municipal1_.startdate
AND NVL (municipal1_.enddate - 1, TO_TIMESTAMP('2009/06/01:00:00:01:01', 'yyyy/mm/dd:hh24:mi:ss:FF2')))
The query above returns no rows. Why?

Some notes:
  1. the (null) for enddate means the timeperiod reaches into the future
  2. the sql function BETWEEN[5] checks to see if a value is within a certain range. The boundaries are inclusive.
  3. The enddate is a timestamp(6)
  4. enddate - 1 is no longer a timestamp, but a common date. An implicit datatype conversion takes place.[4]
  5. date doesn't store anything smaller than seconds [2]
  6. we lose the milliseconds
  7. NVL tries, if the first argument is null, to cast the second argument to the same type as the first argument (a date) [3]
  8. even though enddate is null, the data conversion still takes place
  9. ergo, the timestamp used now falls outside the range, and no results are returned.

Solution

There is one good solution to this. Don't use BETWEEN with timestamps if the range is exclusive the enddate. Use greater than/equals (>=) and lesser than (<) instead.

If you do wish to change a TIMESTAMP, use INTERVAL instead of arithmetic. [4]

/* Formatted on 28/11/2013 17:02:58 (QP5 v5.227.12220.39754) */
SELECT *
FROM MUNICIPAL municipal1_  
WHERE municipal1_.code='0358'
AND (TO_TIMESTAMP('2009/06/01:00:00:01:01', 'yyyy/mm/dd:hh24:mi:ss:FF2') >= municipal1_.startdate
AND TO_TIMESTAMP('2009/06/01:00:00:01:01', 'yyyy/mm/dd:hh24:mi:ss:FF2') < nvl(municipal1_.enddate, 
                            TO_TIMESTAMP('2009/06/01:00:00:01:01', 'yyyy/mm/dd:hh24:mi:ss:FF2')))

Conclusion


Do NOT use Arithmetic with Timestamps! You will get an automatic conversion to datatype Date and lose millisecond precision!

It is quite ugly to substract a day from a DATE, just so that you could use BETWEEN and not worry about the last boundary being included.

I guess it is my own fault for appropriating a bit of SQL code that was originally designed for DATES instead.

References

[1] Timestamp
http://docs.oracle.com/javase/7/docs/api/java/sql/Timestamp.html
[2] PL/SQL Data Type
http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/datatypes.htm#CIHBCJEG
[3] NVL
http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions105.htm
[4] Math with Timestamp
https://blogs.oracle.com/knutvatsendvik/entry/math_with_timestamp
[5] BETWEEN
http://docs.oracle.com/cd/B28359_01/server.111/b28286/conditions011.htm#SQLRF52147

Wednesday, 25 September 2013

Architect Enterprise Applications with Java EE - Course

I had the opportunity to attend the Oracle course on "Architect Enterprise Applications with Java EE"[1] from Monday 09/09/2013 to Friday 13/09/2013. (after forking over a big sack of money)

The Course does have a number of Lab exercises, mostly based on UML or open questions (that created several discussions, which I enjoyed immensely). UML diagrams were drawn using UMLet[3].

I took the course as I wish to prepare for the 'Oracle Certified Master, Java EE 6 Enterprise Architect' certification.

This is the first step in the Certification Process [2].

I did receive some very interesting Course material along with it. However, it's been licensed to me specifically. (I could let you read it, but then I would have to kill you. Oracle licensing rules say so.)

References

[1] Architect Enterprise Applications with Java EE
http://education.oracle.com/pls/web_prod-plq-dad/ou_product_category.getAllProductsPage
[2] Oracle Certified Master, Java EE 6 Enterprise Architect
http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=458&get_params=p_track_id:OCMJEE6EA
[3] UMLet
http://www.umlet.com/

Wednesday, 27 February 2013

(+) to LEFT/RIGHT OUTER JOIN

Recently had to transform an Oracle SQL Query into a Standard SQL Query. One of the three steps to take was changing the Oracle notation for outer joins into a "LEFT OUTER JOIN" and "RIGHT OUTER JOIN".

(+) is an Oracle specific function[1].

Let's go with the old and trivial example of the employees and the departments in a company, before we dive any deeper. It seems to work for everyone else, so it should work here.

As we see if the (+) is on the right of the expression, it is a "LEFT OUTER JOIN" and vice versa.

The example comes straight from [3]. It will show NULL for the department values for all employees that are not assigned to a department. Wikipedia has a nice article on the behaviour of outer joins.[4]

Multiple Outer Join


This is an example of how you could use left join multiple times.
In my work, what I usually find, is a query that selects from a master table that needs to provide all records, left joined with the rest of the world, just in case the records in other tables do not exist.

This won't work


You can write conditions in the "ON" clause, however, these conditions must be related to the SLAVE table. The following, for example, will not work.[2]

It will show all employees, even the ones that are no longer working for the company.

The solution here is to move the offending condition into the WHERE clause.

Odd one out

The example below, I encountered, is a bit odd, as it is not really an outer join between tables. It is used here to prevent having to write the 'or is null' part.

References

[1] Oracle (+)
http://docs.oracle.com/cd/B28359_01/server.111/b28286/queries006.htm
[2] The ON condition
http://www.oreillynet.com/pub/a/network/2002/10/01/whatsinacondition.html>
[3] Example Oracle Left Outer Join
http://www.dba-oracle.com/tips_oracle_left_outer_join.htm
[4] Wikipedia JOIN SQL
http://en.wikipedia.org/wiki/Join_%28SQL%29
Outer joins in Oracle
https://blogs.oracle.com/optimizer/entry/outerjoins_in_oracle
A Visual Explanation of SQL Joins
http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html

Thursday, 21 February 2013

DECODE to CASE

Recently had to transform an Oracle SQL Query into a Standard SQL Query. One of the three steps to take was changing the DECODE into a CASE.

DECODE is an Oracle specific function[1].

The case statements, though more standard, are a bit more wordy than the decode statements. As shown in the following, slightly more complex example.


References

[1] Oracle DECODE
http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions040.htm
[2] Case and decode two powerfull constructs of sql t181
http://www.club-oracle.com/forums/case-and-decode-two-powerfull-constructs-of-sql-t181/

Thursday, 14 February 2013

NVL to COALESCE

Recently had to transform an Oracle SQL Query into a Standard SQL Query. One of the three steps to take was changing the NVL into a COALESCE.

NVL is a Oracle specific function[1].

A simple "search & replace" did the trick.


COALESCE requires the same data types, where NVL does not.

References

Oracle NVL
http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions105.htm
Stackoverflow - Oracle differences between nvl and coalesce
http://stackoverflow.com/questions/950084/oracle-differences-between-nvl-and-coalesce

Tuesday, 13 November 2012

The network was the computer?


What happened to http://thenetworkisthecomputer.com/[1]? It used to point to a Tribute website regarding Sun, but now it just points to Oracle.

I guess all things pass.

P.S. Startling how back then (1984[3]!!) "The network is the computer" could nowadays be translated as "All your stuff's in the Cloud" (2006[4], 22 years later). I guess they were ahead of their time.

References

[1] a Tribute to Sun Microsystems
http://www.thenetworkisthecomputer.com/
[2] Screenshot : a Tribute to Sun Microsystems
http://dawhois.com/site/thenetworkisthecomputer.com.html
[3] Celebrate 25 years of SPARC Innovation
http://www.oracle-downloads.com/sparc25info/
[4] The Google Podium transcript
http://www.google.com/press/podium/ses2006.html