Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to check if select one choice component only contains 1 option?

Roger MarquisSep 28 2021

Hello all.
On the page I'm currently developing there is a popup which contains a tree table component with multiple columns and select one choice components, and one child disclosure also containing an soc component.
I am seeking a way to check if there is only one select item choice in the soc dropdown, and if so, I want the soc to default to the only available choice.
The soc components are populated dynamically and so may contain a varying number of elements in each dropdown. I have been trying to find a way to count the number of elements in the dropdown but have not found a successful way to count the number of items for both parent and child node lov/soc components.
So basically, I want to check if the soc item list count equals "1". If there is only "1" item option, then default the soc to that value.
Thank you for reading.
My Jdeveloper version is 12.2.1.4

Comments

cormaco
Answer

You can write it down explicitly like this:

select * from employee_view  
where 
    :p_cnic = 'YES' and emp_cnic is not null or 
    :p_cnic = 'NO'  and emp_cnic is null
    
Marked as Answer by Muhammad Masoom Ansari · Aug 23 2021
BluShadow

undefined (0 Bytes)
Whilst order of precedence works, for clarity of reading (and to ensure future lazy developers don't break it so easily), I always prefer to use parentheses/brackets around my OR clauses...

select * from employee_view  
where 
    (    :p_cnic = 'YES'
     and emp_cnic is not null
    )
    or
    (    :p_cnic = 'NO'
     and emp_cnic is null
    )

Just makes it absolutely clear which clauses belong with which other clauses. Nothing worse than a future developer coming along adding another "and" clause thinking it will apply to everything but they've not seen the OR statement and then it's not working as it should.

Jan Gorkow

Hi Muhammad,
here's a little correction of the query of cormaco and BluShadow to satisfy your requirement to select all records if no value is passed:

SELECT *
  FROM employee_view
 WHERE    ( :p_cnic = 'YES' AND emp_cnic IS NOT NULL)
       OR ( :p_cnic = 'NO' AND emp_cnic IS NULL)
       OR ( :p_cnic IS NULL)

Best regards
Jan

Hi Cormaco
after little bit change giving me right answer such as
select emp_id,emp_name,emp_cnic
from employee_view a
where a.emp_id in ( select distinct emp_id from hml_emp_attend_register where month_id = :p_month )
and ( (:p_cnic = 'YES' and emp_cnic is not null) or
( :p_cnic = 'NO' and emp_cnic is null)
)
Many thanks Jan n Blue Shadow

Frank Kulash

Hi, [Muhammad Masoom Ansari](/ords/forums/user/Muhammad Masoom Ansari)
Here's another way to write the WHERE clause, that's a little more concise:

WHERE  :p_cnis IS NULL
OR     :p_cnis = NVL2 (emp_cnis, 'YES', 'NO')

I tried with decode function but I think it don't support the "not null"
Right. DECODE must return a value in one of the SQL data types, such as VARCHAR2 or NUMBER. That means, the 3rd, 5th, ... arguments must all be expressions that result in the same kind of SQL data type. But
emp_cnis is not null
is a BOOLEAN expression, and there is no BOOLEAN data type in SQL.

Jan Gorkow

Hi Muhammad,
be aware that your "... all records should be viewed" requirement is not met by your query.
Best regards
Jan

User_H3J7U

@frank-kulash
a little more concise
lnnvl(:p_cnis = NVL2 (emp_cnis, 'NO', 'YES'))

Hi @Jan Gorkow
Thank you very much for pointing out, now its fine.
select emp_id,emp_name,emp_cnic
from employee_view a
where a.emp_id in ( select distinct emp_id from hml_emp_attend_register where month_id = :p_month )
and ( (:p_cnic = 'YES' and emp_cnic is not null) or
( :p_cnic = 'NO' and emp_cnic is null)
or (:p_cnic is null and (emp_cnic is not null or emp_cnic is null))
)

Frank Kulash

Hi, [Muhammad Masoom Ansari](/ords/forums/user/Muhammad Masoom Ansari)
There's no point in saying
 or  (:p_cnic is null and (emp_cnic is not null or emp_cnic is null))  
Simply say

 or  (:p_cnic is null)  

instead.

Hi @frank-kulash
Yes, correct working suggested by you.
Thank you.

1 - 10

Post Details

Added on Sep 28 2021
3 comments
284 views