Wednesday, May 7, 2014

The sign function of SQL

The SQL sign function returns -1, 0, or 1 when the corresponding field of a table in the database is numeric and the value is negative, 0, or positive.

For example

          SELECT sign (dailyChange) PriceChange from PRICE where DATE = to_date('03/21/2014', 'MM/dd/yyyy');

If on March 21, 2014, the price was decreased, that is the dailyChange is a negative value, the output of the query is -1; if the price did not change, the output is 0; and if the price was increased, the output of the query is 1.

Another example

          SELECT sign(TotalCharge - Paid) OweMoney from ORDER where customer_ID = 5588;

If the customer paid less than the total charge, the output is 1; if the customer paid the exact amount of total charge, the output is 0; and if the customer paid more than the total charge, the output is -1.

References
1. ORACLE/PLSQL: SIGN FUNCTION

------------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

No comments:

Post a Comment