Skip to Main Content

APEX

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!

Excel export ordering

704127Nov 3 2009 — edited Nov 3 2009
hello, i used excel export package from denes kubicek and it works fine..

but there is a problem: i want to export report in it's own ordering , as it is displayed..
in excel file i have other column order :(

what can i do?

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
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Dec 1 2009
Added on Nov 3 2009
1 comment
253 views