Saturday, 10 October 2015

Tip : Handling NULL values for integer/Number type parameters in Stored Procedure Reports in Jaspersoft Business Intelligence Reports

Problem Statement : 
# How to pass null values to Integer/Number type parameters in Stored Procedures.

# Usually, we show textual information in the parameter drop down & in the back end pass
      IDs  related to that textual information.

# When we show textual information in the drop down we get --- (triple dashes) for single
        select  query parameter that means NULL(or null).

# When we pass this null value the stored procedure parameter which is Integer/Number type parameter doesn't understand and throws exception.

# Lets say the SQL part inside the SP is handling NULL values with 0 (zero) which will returning
    all the data (B'z Integer/Number type parameters don't accept NULL values in some cases if you won't handle it using nvl function of SQL.



Solution : 
Example : SP with static values
Return all the values of stored procedure when passing 0's.
{
  call procedure_employee(
                                                0,
                                                0,
                                                $P{ORACLE_REF_CURSOR} )
}

Return nothing when pass NULL values
{
  call procedure_employee(
                                                '  ',
                                                '  ',
                                                $P{ORACLE_REF_CURSOR} )
}
Example of SP with parameters which will return all the values of SP.

{
         call procedure_employee(
                                                        nvl($P{param_empID},0) ,       
                                                        nvl($P{param_ManagerID},0),
                                                        $P{ORACLE_REF_CURSOR}
                                              )
}

i.e., nvl function can be used with parameters in SQL stored procedure. 

NOTE : 
# $P{ORACLE_REF_CURSOR} is an java.sql.Resultset type Build in parameter 
     in jasper studio/iReport.  
# Enclose stored procedure call in curly braces {} and select query language type as PL/SQL in studio query dialogue window. 
# For String type single select query parameter it is not required to use nvl function. While writing SQL code inside Stored procedure we can write some thing like 
     WHERE <Field_Name>=<Parameter_Name> OR <Parameter_Name> IS NULL

I hope this helps some one.! I must thank you to my colleague in suggesting this approach to experiment on the SP call with Integer type single select NULL value.

Thank you. 
Sadakar Pochampalli

 

No comments:

Post a Comment