Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

literal array in SQL statement?

 
Bob Grossman
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic