The formula will score 0 if suppl_id is between 1 and 10.However, you can try to create a formula that will define one number for one range and another number for another range, and so on.ĭECODE(TRUNC ((suppl_id - 1) / 10), 0, 'cat 1', Unfortunately, you cannot use the DECODE function for number ranges. 1-10 = ‘category 1’, 11-20 = ‘category 2’, instead of decoding each number individually.
![decode sql decode sql](https://4.bp.blogspot.com/-ofqG3QAasZY/V9Yp1DpgCFI/AAAAAAAAAqs/CpyZpiyUmiI1yy1TA2Pdf_4dy7P1-mU7gCEw/s1600/2.png)
![decode sql decode sql](http://4.bp.blogspot.com/--OdjzbJTgZs/U4ADdMD4WjI/AAAAAAAAFj4/ztDL2pIoUhg/w1200-h630-p-k-no-nu/2014-05-24_101535.png)
I would like to know if it is possible to use the DECODE function for number ranges, i.e. One of our readers suggested using the LEAST function (instead of DECODE) as follows:Īn example with dates above can be modified as follows: The combination of SIGN / DECODE is also useful for digital comparisons such as bonus sales.ĭECODE(SIGN(actual-target), -1, ‘No bonuses for you’, 0, ‘Just do it’, 1, ‘Congratulations, you are the winner’) The example with the dates above can be modified as follows:ĭECODE(SIGN(date1-date2), 1, date2, date1) One of our readers suggested combining the SIGN function with the DECODE function as follows: The formula below is 0 if date1 is greater than date2: To do so, use the DECODE function as follows:ĭECODE((date1 - date2) - ABS(date1 - date2), 0, date2, date1) Otherwise, the DECODE function should return date1.
DECODE SQL HOW TO
One of our readers wanted to know how to use the DECODE function to compare two dates (that is: date1 and date2), where date1 > date2, the DECODE function should return date2. The DECODE function will compare each suppl_id value, one after the other. Request using DECODE is equivalent to the IF-THEN-ELSE design. You can use the DECODE function in an SQL query as follows: DECODE in the following versions of Oracle/PLSQL Oracle 12c, Oracle 11g, Oracle 10g, Oracle 9i If no match is found, DECODE will return NULL (if no match is found). If no matches are found, the DECODE function will return the default value. result_id – value returned if the expression coincided with the sought search.ĭefault – optional.expression_id – is an expression for comparison.Oracle/PLSQL syntax of the DECODE functionĭECODE( expression_id, search_id, result_id. SQL tutorial: DECODE function in Oracle Database.DECODE in the following versions of Oracle/PLSQL.
![decode sql decode sql](https://www.oracletutorial.org/images/9-available-fields-report-wizard-reports-11g.jpg)
Oracle/PLSQL syntax of the DECODE function.