Saturday, May 30, 2009

Sorry. We Get the Support Documentation We Deserve

We programmers love to mumble to ourselves in abject silence about how poorly a commercial framework, api, server app, etc is documented. Though such complaints might be understandable, I suspect that the lack of effective documentation is many instances at least partly a function of apathy on the part of the user base.

Recently, I ran into perhaps the vauguest and cryptic Oracle error messages of all time: "ORA-01461 can bind a LONG value only for insert into a LONG column."

Huh? LONG? LONG is a defunct data type. Hey Oracle, what I really need to know is which column? And which table? And what exactly is meant by a "LONG value?" It's just a string characters.

Eventually I figured out that the offending insert statement referred to a column that was varchar2(4000 characters). But my string only had 2020 characters. So I should be good. Right?

Turns out Oracle has a built-in global limitation of 4000 bytes, not characters, for a varchar2. See http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/datatype.htm#CNCPT01. Even if you specify 4000 characters, the 4000 byte limit overrides. Depending on the encoding a character can be and usually is greater than one byte. Characters are typically 2 bytes. So my 2020-character string actually occupies 4040 bytes. Thus, my insert was over the global limit.

But why does the error message use the term LONG? The LONG data type can be up to 2 gigabytes. Evidently, this error message dates back to yesteryear when the only way to upload a character string longer than 4000 bytes to a table was to use a LONG column. Today, you can use a bunch of different LOB data types, instead of LONG.

Here's what really burns me: Googling "ORA-01461" provided no answers. Hmmm. What's up with that, my fellow Oracle programmers? Okay, so Oracle is not connecting the error message with the likely context in which you would see error message. Yes, that sucks. But what about our responsibilities? I haven't run across anyone on the interwebs complaining about how utterly lame and useless this error message is. If we don't complain with specificity and articulation, don't expect old-line software vendors such as Oracle to give a hoot.


Thursday, May 14, 2009

Variables in Sql Developer

Ever find yourself having to remember how to to use variables in Oracle's handy tool Sql Developer? Me, I can never remember. That's why this post is here.

There are two types of variables in the Oracle world: substitution variables and bind variables. It's important to remember that you can't use substitution variables in Sql Developer, but you can use bind variables. The syntax for bind variables is the following:

variable custno number
exec : custno := 99
Select * from customer where customerId = : custno;

Now I'll remember.