Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use * / Column in sql query

 
Anand Karia
Ranch Hand
Posts: 156
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All

I have 5 column
1 Col = Code numeric [ 1,2,3 ]
2 Col = Name varchar [David, Anand, Peter ]
3 Col = Salary numeric [ 5000,6000,70000]
4 col = factor char [ * , * , / ]
5 Col = rate numeric [ 10,10,0.5]

How can I use column # 4 in SQL query. Please help.

i.e. select code,name,salary, (salary + factor + rate) as amount from salary_table . This query is not working


 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do I understand it right that you want to use the operator stored in the factor column? It's not possible to do it directly - SQL doesn't evaluate expressions dynamically. The closest you can get probably is:

Hopefully your database supports the case expression, but even if it doesn't, it probably has an if function or a similar construct.

You'll need to hard code every possible operator into the query. It would be a good idea to put a check constraint on the factor column to only allow characters representing supported operators.
 
Anand Karia
Ranch Hand
Posts: 156
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh Yah.... Sorry I forgot.

Thank you a lot Martin.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic