Sunday, February 26, 2012

What are these dollar signs doing in my code ?

I've had the good fortune, in my current role, to be doing a fair amount of PL/SQL development in 11gR2. Boy, it feels good to be actually using up-to-date versions. Being picky, we are on Apex 4.0, rather than 4.1 but that's not a biggie.

One item I've found myself using more and more are the $$PLSQL_UNIT and $$PLSQL_LINE inquiry directives. I think they are great for logging.

Here's a handy example

create or replace procedure fizz_buzz as
  for i in 1..15 loop
    if i/2 = trunc(i/2) then
      if i/3 = trunc(i/3) then
        dbms_output.put_line($$plsql_unit||'('||$$plsql_line||') - Fizz Buzz');
        dbms_output.put_line($$plsql_unit||'('||$$plsql_line||') - Fizz');
      end if;
    elsif i/3 = trunc(i/3) then
      dbms_output.put_line($$plsql_unit||'('||$$plsql_line||') - Buzz');
      dbms_output.put_line($$plsql_unit||'('||$$plsql_line||') - '||i);
    end if;
  end loop;
end fizz_buzz;

When executed, you get a "poor man's trace" of the path the process takes through the logic.

SQL> exec fizz_buzz
FIZZ_BUZZ(13) - 1
FIZZ_BUZZ(8) - Fizz
FIZZ_BUZZ(11) - Buzz
FIZZ_BUZZ(8) - Fizz
FIZZ_BUZZ(13) - 5
FIZZ_BUZZ(6) - Fizz Buzz
FIZZ_BUZZ(13) - 7
FIZZ_BUZZ(8) - Fizz
FIZZ_BUZZ(11) - Buzz
FIZZ_BUZZ(8) - Fizz
FIZZ_BUZZ(13) - 11
FIZZ_BUZZ(6) - Fizz Buzz
FIZZ_BUZZ(13) - 13
FIZZ_BUZZ(8) - Fizz
FIZZ_BUZZ(11) - Buzz

By automatically substituting in the actual program name (eg the package name) and the line, you don't have to worry that refactoring the code is going to mess up any debug or logging logic. Refactoring is a fancy name for taking chunks of code and moving them into specialised procedures and functions so you can reuse them. Most developers do refactoring but may not know the name of it, or even that it has a name. Mostly you only need to know the buzzwords at interviews.

So that is what those $$ directives are doing in my code.

Friday, February 10, 2012

Why I don't (always) care if you follow me....

This one is inspired by Jeff Smith's (yes, That Jeff Smith) post "Why I don't follow you" post.

I don't care if you follow me.

Okay, that's not completely true. I hope you didn't stop reading then. What I really meant was that I don't expect all the people that I follow to follow me back.

Here's why.

I read a lot of blogs and articles to learn stuff I don't know about. I'll subscribe to RSS feeds and add people to my Google Plus circles if they write or link to 'quality' material. By quality, I mean stuff that I find interesting or useful.

I write stuff here (occasionally, and will do an Oracle based one in the next day or too) and link to articles through Google plus. These are things that I think / hope other people may find interesting or useful.

So I follow some people and some people follow me. Inevitably there will be some overlap when people are interested in the same topics. But there are some people who know far more about a topic than I do and won't learn anything new from my posts. Or they post on a topic which I 'consume but don't publish'.

So I'm not offended if you don't follow me. Please don't be offended if I don't follow you.

Ongoing frustrations with Twitter mean that I've mostly replaced it by Google Plus.
Contrary to what I've said here, if you circle me there and have something like 'DBA' in your profile, I will circle you back because I have a special circle for DBAs. As did Dante, I believe.

I'm very flattered to be followed on Twitter, but I grew fed up of trying to twist sentences into something that is accurate and useful but still brief.