Thursday, December 22, 2005

Bracketing frenzy

I just found myself decyphering this:

SELECT ...
FROM report_results rpt
WHERE NOT ( (substr(rpt.report_type,2,1) in ('1','2','3','4','5')) and
          (rpt.sig_type = 'ISDNMA') and
          ((rpt.group_ctn != rpt.ctn_prefix||rpt.ctn_suffix) and
           (length(rpt.group_ctn) != length(rpt.ctn_prefix||rpt.ctn_suffix)) and
           ((length(rpt.group_ctn) != (length(rpt.ctn_prefix||rpt.ctn_suffix)-1)
           ))));

Which turns out to mean this:

SELECT ...
FROM   report_results rpt
WHERE  NOT (     SUBSTR(rpt.report_type,2,1) IN ('1','2','3','4','5')
            AND  rpt.sig_type = 'ISDNMA'
            AND  rpt.group_ctn != rpt.ctn_prefix||rpt.ctn_suffix
            AND  LENGTH(rpt.group_ctn) != LENGTH(rpt.ctn_prefix||rpt.ctn_suffix)
            AND  LENGTH(rpt.group_ctn) != LENGTH(rpt.ctn_prefix||rpt.ctn_suffix)-1 );

No wonder there are no brackets left in the shops.

10 comments:

Pete_S said...

Yikes!
I've often seen query tools generate excessive brackets - not fun for the old amongst us to work out what belongs to what - I've given up on bracket matching and paste the sql in to Jdeveloper and let that match the brackets for me.

Michael Dinh said...

Brackets should only be used if the operation is to supercede the order of operation. You think that is bad, how about (x*y)/z?

Covenant said...

Actually ,to be picky...

those are parenthesis.

a bracket as all good computing people know is '[', whereas a brace is '{'

you should know better Robertson!

William Robertson said...

In English, "bracket" is another word for "parenthesis". If C programmers want to use the word for something else, that is not my problem.

Covenant said...

oh, im sorry, I mistakenly thought that the oracle-wtf was a software oriented blog dedicated to nit picking, but I guess the normal computer programming rules and conventions don't apply here :P

Please accept my humble apologees ( in my best hugh laurie inspired fake german accent )

William Robertson said...

We certainly do not nitpick here. We present examples of monumental cockups, by idiots, for public admiration, because in our own warped way we find them amusing.

Apologies also to anyone looking for the World Taekwondo Federation.

Tony Andrews said...

>Actually ,to be picky...
>
>those are parenthesis.

Actually, to be picky...

"Parenthisis" is singular, you should have said "parentheses".

But like William, I call them brackets anyway. Brackets come in 3 subtypes: round (the default), square, and squiggly.

Covenant said...

yeah! I noticed that after I posted, but I thought no one had noticed but that wil teach me to be a pedant on this particular blog. :S

Noons said...

where is the Phantom Nitpicker when one needs him?....

Scott Swank said...

Pity more folk don't learn the word "commutative" before they start coding.