File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes literal array in SQL statement? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "literal array in SQL statement?" Watch "literal array in SQL statement?" New topic

literal array in SQL statement?

Bob Grossman
Ranch Hand

Joined: Dec 18, 2008
Posts: 70
I'm sure there must be a really easy way to do this, but I can't figure out how, and a search hasn't yielded a solution. Here's what I want to do, but it's illegal:

That is, q_type has an integer value, and I want to populate q_name with a string value that depends on the value of q_type. I can do it with a separate set statement for every value of q_type, but I'd rather do it with a single call. Any ideas how to do it without getting into PL/SQL?
Martin Vajsar

Joined: Aug 22, 2010
Posts: 3733

If you're speaking about Oracle, then perhaps the DECODE function (or the more readable, but much more wordy CASE expression) might be useful here.

(Or not, if I haven't understood your requirements properly. Where does q_type come from?)
Bob Grossman
Ranch Hand

Joined: Dec 18, 2008
Posts: 70
First, to answer your questions: Yes, Oracle SQL, and the table already contains a field, q_type, with a numeric value of 0-18. I want to add a field, q_name, that has a text value instead of a numeric value.

Thanks, I guess DECODE would do the trick. I did eventually devise an alternate solution.

I agree. Here's the link:
subject: literal array in SQL statement?
It's not a secret anymore!