This content has been marked as final. Show 14 replies
You can apply more then one condition in the decode
Example SELECT DECODE(myvalue, iffirstvalue , writethisvalue, ifsecondvalue, writethisvalue, whenallothersthenthisvalue) xx
You can also put DECODEs around DECODE's..
More info at:
Case is used like this in a select statement:
SELECT CASE WHEN sysdate=sysdate THEN 1 ELSE 2 END firstcase
If your DECODE did not work the it is explained then you might have made an error somewhere.
Here's a solution using the CASE statement that Joni touched on in the previous post.
In this example, the checkbox will be checked if deptno in (10,20) else it will be unchecked.
select apex_item.checkbox2(1,empno,case when deptno in (10,20) then 'CHECKED' else 'UNCHECKED' end , null) "Select", ename, job from emp order by 1
Hope this helps.
Sorry, I couldn't delete this extra comment.
Edited by: Najla on Jan 21, 2013 10:45 PM
Thank you for both of you, but I didn't mean that. My condition must check two columns, so I have two values for two columns, not tow values for one column.
You can still use Keiths code, you can use AND/OR statements in a CASE, so you just have to make a small adjustment:
select apex_item.checkbox2(1,empno,case when deptno = 10 AND job = 'Manager' then 'CHECKED' else 'UNCHECKED' end , null) "Select", ename, job from emp order by 1
I already tried this syntax, but this error raises up always
"Query cannot be parsed, please check the syntax of your query. (ORA-00907: missing right parenthesis) "
I am sure the rest of the query is okay, It works well without this sentence.
Edited by: Najla on Jan 22, 2013 12:47 AM
I was afraid of that, but why not put the case around the entire checkbox?
CASE when ... THEN checkbox1
Edited by: Joni Vandenberghe on 22-jan-2013 4:14
As Joni stated in the previous post, using case logic around the entire checkbox item will work fine.
I couldn't get the idea exactly, would you please write the whole syntax? What is Checkbox and checkbox2?
1 person found this helpful
Edited by: Joni Vandenberghe on 23-jan-2013 0:34
select CASE WHEN deptno = 10 AND job = 'Manager' THEN apex_item.checkbox2(1,empno, 'CHECKED' , null) ELSE apex_item.checkbox2(1,empno, 'UNCHECKED', null) END "Select" from emp order by 1
Query cannot be parsed, please check the syntax of your query. (ORA-00918: column ambiguously defined
That means that you have two columns in your query that have the same name, and you did not specify what column he should use by using a prefix.
More info about this in the first two results that google gave me:
But what query? It's useful if you always show us your code, now we have to "guess".
Edited by: Joni Vandenberghe on 24-jan-2013 0:25
for the same query that contains the checkboxes condition, when I tried to use the case conditions you posted, this error raised up.
How to add a code to the comment?
Anyways, I got it finally, I used this statement ...
decode( test.a, 0, decode( b.TYPE, 'fhfhfg', 0, -1 ), -1 )
this is equal to
CASE WHEN (test.a = 0 AND b.TYPE ='fhfhfg' )THEN 0.
Edited by: Najla on Jan 24, 2013 4:22 AM