The View From the Moon
A very interesting summary of economic happenings across the world. Where does India stand? Read and find out. Just click here.
Do I believe him? Having studied some economics myself, I guess I do agree with what he has to say. I am quite sure that the Sensex at >11000 is far away from reality. Something closer to 8500 to 9000 is more like the real thing.
So whats the best place to invest today? Definitely not the stock markets. Property? According to Sanjeev Pandiya that is expected to fall as well. Umm…actually, if you can invest in gold, silver and oil stocks, that would form the best investment for a long time to come. Assured returns for a lifetime..thats what I call investment in these areas.
But alas!!! poor men like me dont have the cash or the avenues to invest in these sectors. What the %^#$%#!!!
Anonymous Blocks in DB2
SQL Blocks (a.k.a. Anonymous blocks in Oracle) in DB2 which are not inside any stored procedure or trigger were the bane of my entire team for quite a while. H requested me to take care of the same since I am the only one qualified enough (being DB2 700 certified and stuff). So I set about doing this yesterday. Finally managed to get it to work. Strong recommendation if you are interested in this stuff or work on it everyday, join this Google group.
Here’s the code that works in Command Center (obviously the logic is useless, this is just to explain the syntax to you):
BEGIN ATOMIC
declare a integer default 5;
declare b integer default 5;
delete from test.table1;
Set a = (select count(*) from test.table2);
Set b = (select count(*) from test.table3);
if a=b then
insert into test.table1(’A');
else
insert into test.table1(’B');
end if;
END
@
Need an explanation? Here goes…
The first statement (BEGIN ATOMIC) is like any other Begin statement you would encounter in a Oracle PL/SQL Block. It tells the compiler that a block is beginning. But there is something additional. The keyword ATOMIC, which basically means that the **entire** statement contained inside the BEGIN…END clauses is either executed in full or not at all. So in case there is an error while executing one of the SQL queries (say the insert query), the whole of the statement is rolled back.
The next 2 lines of code obviously declare 2 variables a and b each assigned a default value of 5. You could also leave out the default value.
Next up the delete statement. Note that DB2 does NOT have a TRUNCATE statement. So you either have to use a DELETE FROM without giving a where condition, or try the REPLACE INTO command with a blank file. The difference? Well, a DELETE FROM will log all the rows being deleted, thereby increasing the log size and also taking more time. This is not the case with the TRUNCATE statement on other DBMSs. In DB2, using the LOAD COMMAND with the REPLACE INTO statement accomplishes this. Much much more on this here.
The Set statement is assigning values to the declared variables. Please note, SELECT INTO or equating the variables to functional expressions (eg. a=count(*)) does not work and neither do you need to prefix the variable names with a colon(:) or an at(@). Just use the variable names as they are.
The IF conditional. Hmm…Note the syntax. IF..THEN..(ELSEIF..THEN..)ELSE..END IF;.
And the semi-colon must come after the END IF to indicate the end of the IF statement.
Whats the @ doing right at the end? Hmm…You havent been reading my blog regularly…have you? Read this. You will omit the @ symbol in case you are using this code elsewhere in DB2.
Happy New Year!!!
Today is Ugadi here in Bangalore. I have no idea what that means. But I found out that it is the time they celebrate their new year.
Besides, I also found out something about the educational system here in Karnataka. Strange as it may sound but the CET conducted by VTU does not allow students from other states to apply for admissions into colleges here in Karnataka. Hmm…that means that if I am from, say Kanpur, I cannot apply for enginering courses conducted by colleges in Karnataka. What the %^#$%#!!! Why protect education?
If you are an economist like me (who does not know the difference between monopoly and monpolistic) then read more about Protectionism and its effects here. And this is what Wikipedia says about Protectionism.
Astrology Expert. Who…Me??
People have started thinking that I am an expert at Astrology. Now I am getting requests by mail to read into people’s lives and provide solutions to their problems. Never thought that would happen.
Anyone who has read and understood astrology like it is meant to be, knows that the solutions dont lie in astrology. They lie within yourself. They lie inside your being and spirit. If there are boundaries, they are created by you. If there are barriers they are created by you. If there is stress, it is created by you. So important to realize that.
But even when you do realize that, it becomes quite difficult to actually do something about it. Knowing that everything is created by you, it still requires a lot of courage and strength to break out of imaginary cells. Life can be hell for some and heaven for others. All based on what they make of it. Not on what they get, but what they create out of it. You may be given broken pieces of glass that cut your fingers, but if you can use them to write a letter in blood, then you have made perfect use of them.
The essence: everything depends on what you do; not on what others do. Astrology just tells you who you are and what you can be. It never takes decisions for you. Decisions are your own. And they are what make you or break you. Right decisions take you higher, wrong ones take you higher still.
Enough from me for one day?? Being so philosophical has its own disadvantages as well. High thoughts come at a price. Most of the times people think you are crazy. Imagine…a IT Pro with a Masters degree…and practising astrology!!! What the %^#$%#!!! Doesnt make sense does it?? Well what does??
Function Calls in DB2
The biggest DB2 gotcha(s) that you will ever come across. Whenever you are calling a DB2 function or stored procedure, make sure all the parameters you pass are typecasted to the datatype the function accepts. For example, if the function abc_func() accepts a timestamp and a character datatype as parameters, this is how you would call it:
select abc_func(CAST(’2004-03-29-04:20:40.323426′ as TIMESTAMP), CAST(’A’ as CHARACTER(1))) from sysibm.sysdummy1;
Note the explicit typecasting. In all other calls, you would probably get a “No authorized routine named ‘ABC_FUNC’ of type ‘FUNCTION’ having compatible arguments was found” error. This has been killing me for days now!!!
Even greater problems arise in case you are using a function which accepts nulls as input parameters. All nulls that you pass as values to a function accepting nulls must be typecasted into the destination datatype.
Continuing the example of abc_func, lets assume it also accepts a nullable third parameter, an INTEGER. And, lets assume you actually do want to pass a NULL into this parameter. This is how you will call this function:
select abc_func(CAST(’2004-03-29-04:20:40.323426′ as TIMESTAMP), CAST(’A’ as CHARACTER(1)), CAST(NULL as INTEGER)) from sysibm.sysdummy1;
Hope this helps someone who managed to land himself into a lot of mess on calling functions in DB2.





