It's not a secret anymore!*
The moose likes JDBC 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
JavaRanch » Java Forums » Databases » JDBC
Bookmark "literal array in SQL statement?" Watch "literal array in SQL statement?" New topic
Author

literal array in SQL statement?

Bob Grossman
Ranch Hand

Joined: Dec 18, 2008
Posts: 69
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
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

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: 69
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.


 
Don't get me started about those stupid light bulbs.
 
subject: literal array in SQL statement?