- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
... you know that you can change (format) styles in toad, right?
l.
Admin
That's not the problem, since I don't use TOAD. The real problem is that this feature makes it too easy for my uppercase-prefering co-workers to mess up the code ;-)
Admin
http://www.editplus.com/javacpp.html
Syntax highlighting file for SQL in EditPlus can be had there.
Admin
This is a very good point.
Everyone has "personal styles", but the whole point of case & naming conventions is to make it easy, efficient and umambiguous for development teams (and by extension, the community) to share code.
It's brutal to go into a shop that has wacky (or no) code style standards.
Admin
I used to think there was a bug in the Zope Database Adapter for Oracle, because f2w helpdesk was behaving exactly as though empty strings were NULLs, coming back into Python as None instead of "". I built in a nasty work-around and forgot about it. Today my worst fears are condfirmed.
I think the big giant WTF here is Oracle wilfully breaking string algebra for who-knows-what implementation reason. Did they want to save a few processor cycles checking the field length for zero instead of having a separate NULL bit? Pure genius.
But that function above... Wow, just ...wow.
Admin
I know! The problem is that they forgot to handle uppercase spaces, right?
Admin
I guess they had a PHB dictating ''=NULL; then there were two teams, one defending string algebra (length('')=0) and another one defending NULL semantics (f(NULL)=NULL for f!=NVL). The NULL team one, the losing team eventually went away to build a database that doesn't suck. Unfortunately, they haven't been heard of, since.
Admin
Correction: The NULL team won
Admin
(the story continues)
but the victory of the NULL team was not complete, as one could assume; the string algebra team
somehow managed to force their behaviour of string concetination into the final concept:
NULL||someString = someString||NULL = someString (not NULL, as one could expect)
Admin
correction: concatenation
Admin
Ah, forgot to look back at the declaration... but I think you get my point. Truly a brillant WTF nonetheless!
Admin
v_first_nm := RPAD(COALESCE(v_first_nm,''), 9); v_last_nm := RPAD(COALESCE(v_last_nm,''), 15);
Look, ma, no IFs!
I'm not previewing this because the preview never even looks like my final submissions anyway.
Admin
I think you meant COALESCE(v_first_nm,' ')
(since '' is null) But this use of COALESCE is completely equivalent to NVL.
Admin
I love:
? '' = '' -> false
'test' <> '' -> false
Admin
i no speak orable. but it does look like too much work.
Admin
yes, and also
NOT ('' = '') -> false
NOT ('test' <> '') -> false
because it's actually not "false", but NULL (again!) and NOT(NULL) = NULL; only in the last instance, NULL is treated like FALSE. This trinary logic offer's lots of room for nice effects.
For example, should you ever stumble upon PL/SQL-Code like this:
you should better resist the urge to change that to
because after the change, the program would no longer call
doSomething
ifsomeCondition
is NULL.Admin
I have noticed that when I set up a linked server in MS SQL that points to an Oracle (8i) database, queries written in MS Query analyser against the Oracle database require UPPERCASE for the table name/owner:
Select * from LINKEDSERVERNAME..TABLEOWNER.TABLE
I have always been curious about this. Is it a setting in Oracle, In MS SQL, or just a WTF from two technologies that don't like eachother. It works fine, just very bizarre that the caps matter...oh and it was fun trying to figure it out too! Anyone else seen this behaviour? Anyone know what the cause is?
Admin
Why so many posts?
Admin
Because the WTF forum software won't let me edit my posts.
Oracle is per se not case sensitive, but in it's internal representation, it's all uppercase. Exception: Identifiers in double quotes (like "my identifier with spaces") are case sensitive (and they can contain spaces and other special characters). Accidentally, identifiers without double quotes are identical to the same in uppercase and double quotes; e.g. myTable = "MYTABLE". (But because of that, as said before, myTable != "myTable")
I guess MS-SQL sends all identifiers in double quotes, so only upper case will normally do the trick. You can find out by creating a database Table with double-quoted identifiers:
<code>
create table wtf ( "myWtf" varchar2(5) );
insert into wtf values ( 'WTF?!' );
</code>
and then, from MS-SQL,
<code>
select myWtf from WTF
</code>
Admin
NULL [at least in oracle 9i] is when a column has never had a value (or manually set to NULL). Whereas '' is just that.
Admin
Read the full story here:
http://asktom.oracle.com/pls/ask/f?p=4950:8:8519634631622021894::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:5984520277372
For people using varchar instead of char, the assumption ''=NULL holds.
Admin
quote user="Alex Papadimoulis"
It's actually the recommend way of doing it. Studies have shown that UPPERCASE keywords are much easier to read ...
end quote<FONT face="Courier New">SELECT col1, col2
FROM sometable
WHERE col3 = 'asdf'
AND col4 IS NULL</FONT>
I'm sure studies have ACTUALLY shown that easily distinguished keywords are easier to read. If you have syntax highlighting (which surely even Oracle must have by now) you don't need to uppercase everything.
Uppercasing your SQL in anything but example code is terrible. If you can't read sql, don't.
Admin
How are you supposed to learn it then?
Admin
Oh come on.
Everybody knows that in the nature/nurture debate, SQL fits under 'nature'. You're born with that knowledge!
Admin
Ah, I stand corrected.
Admin
Of course it makes sense! It keeps the CPU warm and the bits moving so the integer pipes won't freeze in a long, cold winter night. Damn, why do people always fail to see the obvious?
Admin
I don't know about MS SQL, but shouldn't (NULL <> NULL) IS NULL?
Admin
I know about MS SQL. And I know about ANSI.
Comparisons (NULL <> NULL) are either true or false, they cannot themselves be null.
MS SQL supports ANSI behavior but you have to turn it on (I did.)
Here's the difference (T-SQL script) - I use the *'s to note LITERAL nulls rather than calculated or selected nulls. " ... = NULL" and "... != NULL" are semantic sugar for "... IS NULL" and "... IS NOT NULL" - this is WRONG, IMHO.
SET ANSI_NULLS OFF
SELECT
'N = N' = CASE WHEN CAST(Null AS BIT) = CAST(Null AS BIT) THEN 'True' ELSE 'False' END,
'N != N' = CASE WHEN CAST(Null AS BIT) != CAST(Null AS BIT) THEN 'True' ELSE 'False' END,
'N = *N' = CASE WHEN CAST(Null AS BIT) = Null THEN 'True' ELSE 'False' END,
'N != *N' = CASE WHEN CAST(Null AS BIT) != Null THEN 'True' ELSE 'False' END,
'1 = N' = CASE WHEN CAST(1 AS BIT) = CAST(Null AS BIT) THEN 'True' ELSE 'False' END,
'1 != N' = CASE WHEN CAST(1 AS BIT) != CAST(Null AS BIT) THEN 'True' ELSE 'False' END,
'1 = *N' = CASE WHEN CAST(1 AS BIT) = Null THEN 'True' ELSE 'False' END,
'1 != *N' = CASE WHEN CAST(1 AS BIT) != Null THEN 'True' ELSE 'False' END,
'1 IS N' = CASE WHEN CAST(1 AS BIT) IS Null THEN 'True' ELSE 'False' END,
'1 IS NOT N' = CASE WHEN CAST(1 AS BIT) IS NOT Null THEN 'True' ELSE 'False' END,
'N IS N' = CASE WHEN CAST(Null AS BIT) IS Null THEN 'True' ELSE 'False' END,
'N IS NOT N' = CASE WHEN CAST(Null AS BIT) IS NOT Null THEN 'True' ELSE 'False' END
N = N FALSE
N != N FALSE
N = *N TRUE
N != *N FALSE
1 = N FALSE
1 != N FALSE
1 = *N FALSE
1 != *N TRUE
1 IS N FALSE
1 IS NOT N TRUE
N IS N TRUE
N IS NOT N FALSE
SET ANSI_NULLS ON
SELECT
'N = N' = CASE WHEN CAST(Null AS BIT) = CAST(Null AS BIT) THEN 'True' ELSE 'False' END,
'N != N' = CASE WHEN CAST(Null AS BIT) != CAST(Null AS BIT) THEN 'True' ELSE 'False' END,
'N = *N' = CASE WHEN CAST(Null AS BIT) = Null THEN 'True' ELSE 'False' END,
'N != *N' = CASE WHEN CAST(Null AS BIT) != Null THEN 'True' ELSE 'False' END,
'1 = N' = CASE WHEN CAST(1 AS BIT) = CAST(Null AS BIT) THEN 'True' ELSE 'False' END,
'1 != N' = CASE WHEN CAST(1 AS BIT) != CAST(Null AS BIT) THEN 'True' ELSE 'False' END,
'1 = *N' = CASE WHEN CAST(1 AS BIT) = Null THEN 'True' ELSE 'False' END,
'1 != *N' = CASE WHEN CAST(1 AS BIT) != Null THEN 'True' ELSE 'False' END,
'1 IS N' = CASE WHEN CAST(1 AS BIT) IS Null THEN 'True' ELSE 'False' END,
'1 IS NOT N' = CASE WHEN CAST(1 AS BIT) IS NOT Null THEN 'True' ELSE 'False' END,
'N IS N' = CASE WHEN CAST(Null AS BIT) IS Null THEN 'True' ELSE 'False' END,
'N IS NOT N' = CASE WHEN CAST(Null AS BIT) IS NOT Null THEN 'True' ELSE 'False' END
N = N FALSE
N != N FALSE
N = *N FALSE
N != *N FALSE
1 = N FALSE
1 != N FALSE
1 = *N FALSE
1 != *N FALSE
1 IS N FALSE
1 IS NOT N TRUE
N IS N TRUE
N IS NOT N FALSE
Admin
Not the same thing; any editor can highlight SQL but few can highlight it in strings inside other languages. SPs are still better in general but some databases don't or didn't until recently support them, and dynamic is useful in other cases anyway.
Admin
I'm lost, should the SQL in my query string be upper, or lowercase?
Admin
I think this WTF is a corker, but fact that any Oracle code posted here is immediately followed by two pages of comments about how the case conventions give it an unfashionable look and how they hate Oracle because of cursors, is a WTF in itself.
SQL is not Java.
Oracle did not invent SQL.
PL/SQL is designed to be an extension of SQL and therefore would be crazy if it did not follow SQL's object naming rules.
For example, if procedure names followed the Java convention so that AddInvoiceItems was not the same as addInvoiceItems or ADDINVOICEITEMS, while tables and columns did not, the language might have a more contemporary feel in some eyes but it would surely be absolute hell to work with. Though of course CREATE PROCEDURE is an SQL command anyway, and procedures and tables reside in the same SQL namespace, even if the procedure is implemented in PL/SQL or Java.
The case conventions of Java make sense and work well for Java, where you can divide pretty much everything into classes (initial capital) and instances of classes (initial lowercase), and "myString" usefully means something different to "MyString". In SQL that makes no sense because it is not object oriented, so should that be InvoiceItems, invoiceItems or what? Especially when it will appear in data dictionary listings as INVOICEITEMS, where the idea of running the words together to save typing doesn't look so clever any more.
Admin
So stop making mistakes in your posts.
You're annoying.
Admin
Quoth Sharon Smith: In most RDBMSs (Oracle, MS SQL, MySQL, PostgreSQL, Ingres) null <> null. Oracle is the only one I've seen where isnull('') = true. It's great (NOT) when you're using trim(firstname) = trim(:c-variable) in your where clause and wondering why your counts are incorrect.
MySQL treats '' as NULL.
If you think of NULL as an unknown value, the whole '' == NULL stops making sense, and is plain wrong. NULL <> NULL because both of them are unknowns.
Admin
I wonder how many recrusions you could do with this before the sqls stack overflows...
Great test!!
Admin
Oracle does not have an arbitrary limit on recursion depth in PL/SQL, but if you run into an endless recursion, nasty things may happen to your server. (Disclaimer: Don't try this on a production server)
Admin
its crap my mum could write that common this is slippin
Admin
RE: It's cr@p like this that reminds me why I prefer to use DB/2 and Microsoft SQL Server.
Let me see if I understand correctly: Somebody writes incredibly dumb code and it's the fault of the vendor of the product that person happened to be using?
Yes, I work for Oracle. No, I am not an Oracle fanatic (having worked for most of the database companies over the years).
Jim
Admin
RE: I'm lost, should the SQL in my query string be upper, or lowercase?
Ahem. I am the editor for all parts of the ANSI and ISO SQL standard. That doesn't mean that I am the expert, but it does mean that I am reasonably familiar with the standard and the history thereof. I also happen to work for Oracle and know a little bit (not much, really) about why things are the way they are regarding zero-length strings and null values.
In the SQL standard, the keywords happen to be defined in uppercase: SELECT, FROM, WHERE, CAST, RECURSIVE, etc. However, SQL is not (generally...see next paragraph) a case-sensitive language, so you can write your keywords in any case you like: select, fRoM, WHErE, etc. They all mean the same thing.
In addition, the SQL standard states that all regular identifiers (including table names, column names, variable names, parameter names, etc.) are implicitly upcast when an SQL statement is parsed. (SQL's delimited identifiers, identified in an earlier post as identifiers in double-quotes, are case sensitive and are not changed by the parser in any way; by the way, such identifiers can contain arbitrary characters, including spaces.)
The SQL standard defines the semantics of comparison when the null value is involved by saying (paraphrasing) that the null value is never equal to any value, including the null value. Because one "expects" that a null value is only a placeholder for a value that is not known, not supplied, missing, not applicable, etc., it could be substituted by any value (of the appropriate data type, that is). Thus, to allow NULL = NULL to be true would be misleading, since the first might be substituted by 42 and the second by 10, which aren't equal (except in base 42).
Oracle was first released 'way back when lots of current programmers were still in short pants. At that time, the SQL standard did not even have the notion of variable/varying-length character strings; it had only the fixed-length character string data type (CHARACTER or CHAR). When, in SQL-92, variable-length strings were added (CHARACTER VARYING, or VARCHAR), a heady debate ensued over the meaning of "no characters in the string" (zero-length strings).
In very large part because the C language referred to zero-length strings as "the null string", a lot of database implementors (and not just at Oracle, either...check your history of SQL Server!) conflated the notion of SQL's null value with the notion of "strings with no characters". Without the SQL standard to guide them, Oracle's implementors used the C-inspired conflation and equated zero-length variable-length character strings with the null value.
Once the SQL standard defined VARCHAR and its semantics that differentiate between the null value and "no characters", one might have hoped that Oracle, SQL Server, et al, would be "fixed". But there's that nasty little detail of the installed user base, in which there were (arguably) millions of SQL statements already used in production applications that depended on the old semantics. Oracle made what is certainly the right business decision not to break all of their customers, but to violate a very small piece of the standard. I have heard rumors that Oracle may be on the way to fixing this problem, but I do not know any facts to support or eliminate that rumor.
Hope this helps,
Jim