Archiwum autora: Przemysław Kruglej

Ho ho ho!

Sorry for not posting anything for a long time, but I’ve caught a terrible cold.

Anyway, I’d like to wish you a Merry Christmas and a Happy New Year! I also wish you health, fast SELECTs, interesting projects and raise_salary being called for you often!

PK

Answer to Quiz #1: Package Dependency

Packages and Dependent Objects

In my last post, I’ve challenged you with a quiz about package dependency. The question was about when a dependent object will be invalidated by Oracle when the package on which it depends is recreated.

The choices which give the „INVALID” status are:
Czytaj dalej

Quiz #1: Package Dependency

Packages and Dependent Objects

I’ve got the following quiz for you today:

After running which of the following code snippets will the 'INVALID’ status be returned?

Assumptions:

  • Version of Oracle: 11g R2.
  • Before each snippet is run, both dummy_pkg and print_message objects do not exist.

I’ll provide the answer in my next post.

The choices:
Czytaj dalej

Text Index With a Sync Parameter

Oracle Text Index with SYNC (EVERY …) Parameter

Just a quick tip for today. Oracle allows us to create special kind of indexes on columns containing long texts. One of them is the CONTEXT type. You don’t need any particular privileges to create an index of this type (other than being able to create indexes in you schema). At least, that’s what the documentation says.

There was a question about creating a CONTEXT index on StackOverflow:

Can’t create oracle text index with sync every

Czytaj dalej

Unit testing in Python

Unit Testing in Python Using unittest Module

The goal of this article is to provide a quick introduction to Python’s unit testing module called unittest. It is the essence, the very basic information you need to quickly start unit testing in Python.

Introduction to the unittest Module

Key points about unit testing in Python:

  • modules with tests should import unittest module,
  • tests should be defined inside a class extending the unittest.TestCase class,
  • every test should start with the test word,
  • if a test has a doc. comment (between a pair of ''', i. e. three apostrophes), the comment will be printed when the test is being run (if verbose mode was set),
  • tests can have setUp and tearDown methods – those methods will be called, respectively, before and after each of the tests; there are also class-level set up and tear down methods,
  • to execute the tests when the module is run, unittest.main() should be called,
  • to see which tests are called with additional info, the -v (verbose) parameter should be specified when the module with tests is executed.

Czytaj dalej

Returning BLOB From Embedded Java

Returning a BLOB from a Java Method Embedded in a Database

You’re about to learn your future

Oracle supports embedding Java classes in its database. Different SQL types are mapped to corresponding Java classes to allow us to make the most of this feature. Author of the following question on StackOverflow:

create-java-sql-blob-instance-in-java-stored-procedure

had an issue with returning a BLOB object from Java method back to PL/SQL context. In the beginning, I didn’t even think you could return a new BLOB object from an embedded class. Fortunately, there was a BLOB in my Java, too. Czytaj dalej

How to Pass an Array of Object Type
To Static Function of That Type

Array of an Object Type Argument in a Function of That Object Type

Interesting question regarding Object Types was asked not a long ago on StackOverflow:

How to Pass a Nested Table of Object Type to a Function of That Object Type?

What author was trying to accomplish was to declare a static function in an object type which would take as a parameter an array of objects of the object type in which it was declared.

Is that even possible? (dramatic pause) Czytaj dalej

Top-N Queries & The New Row Limiting Clause
11g & 12c

Getting the Top-N Records From an Ordered Set &
The New Row Limiting Clause – 11g & 12c

and a cup of tea if you’re lucky

I bet my cup of raspberry-juiced black tea that, somewhere along your journey with Oracle, you had to write a query which was supposed to return only the top-n rows from an ordered set. Unlike some of the other databases, MySQL, for instance, Oracle does not provide a dedicated solution to this problem.

At least, not before the 12c hit the stage.

Before I introduce you to the nice Row Limiting Clause, let me show you why the first solution that comes to mind to solve the problem at hand, in Oracle’s versions prior to 12c, is not the right one, and what voodoo tricks one has to perform to achieve the expected result. Czytaj dalej

Connecting to Oracle Database
Using TNSNAMES.ORA in Java

Utilizing TNSNAMES.ORA in Java

– You have to use TNSNAMES.ORA.
– TNS-what?
– TNSNAMES.
– What-names?
– T N S N A M E S!
– What-what?

In the following thread on StackOverflow:

how-to-connect-jdbc-to-tns-oracle

a question concerning usage of net service names, stored in the TNSNAMES.ORA file, was asked. Let me briefly explain how to connect to Oracle using this approach. Czytaj dalej

Three-valued Boolean Logic

Shortly about chickens and roads…

Why did the chicken cross the road?
Because 1 > NULL AND cross_the_road()

I bet you have heard about the chicken and you know at least a dozen reasons why it had crossed the road. I wouldn’t bet, though, that you have heard about the three-valued logic. And this one is interesting, it even makes the chicken cross the road. The answer to the above question could also be given as: Because it (the chicken) didn’t short-circuit evaluate. What does it all mean? Czytaj dalej