lundi 15 janvier 2018

Check all the value in table and return one value oracle

I have below query which i want to use in stored procedure and which is returning the status with value 0 or 1 or 2.

Select NAME,STATUS 
 FROM TEST_LOG
 where NAME = 'TT' and ID = 19
 AND P_DATE >= to_date( TRUNC ( SYSDATE - 1 , 'MM' ) , 'YYYYMMDD' ) 
   AND P_DATE < to_date ( TRUNC ( SYSDATE), 'YYYYMMDD' )

But i want to use logic such that if any of the status from this query returns 2 then it should return as 2. If all the status returns 0 then only return 0. If all the status return 1 then only return 1. If status return between 0 and 1 then return 1. If status return between 1 and 2 then return 2.

So instead of getting too many values i want to restrict the result to only one value status which i want to pass as OUT paramter to another function.

Aucun commentaire:

Enregistrer un commentaire