JDBCs setMaxRows and the SELECT … FOR UPDATE clause

Today following question came up: Would the JDBC driver of Oracle regonize it, when you set the setMaxRows and perform a SELECT using the FOR UPDATE clause. Example: You’ve a table with 40 rows. Now you call setMaxRows(20) so that you only would get the first 20 rows and perform the select without any where clause (I know, not really a pretty solution: Instead of using rownum, you would select all rows and just stop fetching at the 21th row, but however). Would you now lock all 40 rows or just 20. Well, the answer is (I’ve expected it): You get a row lock on the entry table, not only the first 20 lines. With rownum in the where clause it is now problem. You just lock the selected 20 rows and the other 20 are available for other transactions. So developers: Use the rownum pseudo column instead of the setMaxRows function specially if you perform a select… for update!

But the nicest thing on this little test: I wrote my first Java code since 4 years! 🙂

Possibility of object-oriented programming in PL/SQL

Oh damn, I just get through a presentation of Steven Feuerstein and found out, that PL/SQL supports object-oriented programming. I’m sure, now you think: Why does this stupid guy mean “oh damn…”. Because this “feature” is available since 8i and got strong on 9i. And now they already released 11g! So I didn’t know this possibility several years ago! Well but now I know it and I find it pretty cool, because PL/SQL gets more and more powerful (there are also supported functions for file I/O, HTTP, XML and many many more). Also external or java stored procedures were a big step forward. I just can recur me: Pretty cool!

How to spend a Friday night

What do you usually do on a Friday night? Go out with your friends, finish some work, or just watch TV and then go to bed? Well, today I spent my Friday night in the office (like real DBA’s). Why? Well, our unix admin change the configuration of the servers and of course the DBA also has to check afterwards, if everything is right with the databases. And it was a good decision to came. Actually all database were down except of one. And it was a good chance to patch one of them. Well, now it’s 12:09 AM (on a Saturday morning), the unix admin is still working, but I’ll now drive home and go to bed.

New Oracle 11g features

Oracle 11g is already available and I just finished reading the “New features guide” of Oracle 11g. There are some really nice features in it: Flashback Transactions, CONTINUE-Clause in PL/SQL, Data Revovery Advisor, SQL Test Case Builder, Automatic Health Monitor, SQL Performance Analyzer just to name some few. I’m really excited if all this features work as Oracle promises, but I’ll finally see, when I’ve installed the database on my test system.

Why I like Oracle much more than MySql

I’ve to get a little MySql database running on a local test system and import a “dump” file of a database to verify, if the file is valid. Sounds easy, but first you have to find out, how you get the dump file into the database. For that you must know, that MySql doesn’t write a “normal” dump file as default, but a simple SQL-file including all the statements to get the status from the database back. Ok, also not very hard. Then you import the file, but not with @ like in Sql*Plus. The correct syntax is ‘source <sourcefile>;’. While executing this you get pissed on with “value bigger than max_allowed_packet”. You spend 1 hour to get yourself throw the documentation, found 4 ways to set this damn variable but – just one way works. Ok, you throw away the database, recreate it, set the variable and get sure that it is set and before you reexecute the file you would like to spool the result. But, MySql doesn’t know “spool” like Sql*Plus. No it doesn’t know anything like that as I saw on spending some minutes on the documentation and Google. The only thing you have is a .mysql_history file, but it also didn’t protocol the echo from the database, no just the commands you typed in. Ok, well no spooling, you have the shell open and will some critical error.  So restart the import from the file and see: Same max_allowed_packet error again though the variable is set to the highest value. I’m really pissed on MySql at the moment. Sure I know, if I would know it better, it would not be a problem, but my Dad has his birthday today and it’s already 6:30 PM. I don’t want to spent more time on it in the office!