-
Notifications
You must be signed in to change notification settings - Fork 0
Number Functions
ABS | SIGN | MOD | ROUND | TRUNC | FLOOR | CEIL | BETWEEN |
---|
- Returns Absolute value of inputted value
SELECT ABS(-666), ABS(6969), ABS(0)
FROM Dual;
Output:
ABS(-666) | ABS(6969) | ABS(0) |
---|---|---|
666 | 6969 | 0 |
- Returns sign of given value. (-1,0,1)
Code:
SELECT SIGN(-69), SIGN(666), SIGN(0)
FROM DUAL;
Output:
SIGN(-69) | SIGN(666) | SIGN(0) |
---|---|---|
-1 | 1 | 0 |
- Returns remainder
Simple Query for Modulus Calculation
SELECT MOD(8,3), MOD(8,4), MOD(8,5)
FROM Dual;
MOD(8,3) | MOD(8,4) | MOD(8,5) |
---|---|---|
2 | 0 | 3 |
Query for all even numbers using MOD |
SELECT *
FROM Student.Student
WHERE MOD(Zip, 2) = 0;
First_Name | Last_Name | Zip |
---|---|---|
Josh | Kennedy | 66666 |
Chad | Jensen | 66224 |
-
Will round given value to the provided precision
-
Precision parameter relies on a given number.
-
If NULL, then SQL Developer assumes 0 precision and therefore will Round and then truncate all decimals
-
Negative numbers count left of the decimal
-
Positive numbers count right of the decimal
-
SELECT ROUND(638.51,0), ROUND(638.51), ROUND(638.51, -1), ROUND(638.51, 1)
FROM Dual;
Output:
ROUND(638.51,0) | ROUND(638.51) | ROUND(638.51, -1) | ROUND(638.51, 1) |
---|---|---|---|
639 | 639 | 640 | 638.5 |
- Truncates value
- Precision parameter relies on a given number.
-
If NULL, then SQL Developer assumes 0 precision and therefore will truncate all decimals.
-
Negative numbers count left of the decimal
-
Positive numbers count right of the decimal
-
SELECT TRUNC(638.51,0), TRUNC(638.51), TRUNC(638.51, -1),
TRUNC(638.51, 1), TRUNC(638.51, -2)
FROM Dual;
Output:
TRUNC(638.51,0) | TRUNC(638.51) | TRUNC(638.51, -1) | TRUNC(638.51, 1) | TRUNC(638.51, -1) |
---|---|---|---|---|
638 | 638 | 630 | 638.5 | 600 |
- Returns the largest integer less than or equal to the specified numeric expression
SELECT FLOOR(5.33), FLOOR(.99), FLOOR(1.00001)
FROM Dual;
Output:
FLOOR(5.33) | FLOOR(.99) | FLOOR(1.0001) |
---|---|---|
5 | 0 | 1 |
- Returns the smallest integer greater than or equal to the specified numeric expression.
SELECT CEIL(5.33), CEIL(.99), CEIL(1.00001)
FROM Dual
Output:
CEIL(5.33) | CEIL(.99) | CEIL(1.0001) |
---|---|---|
6 | 1 | 2 |
- Returns a range of numbers between value1, and value 2
- NOT BETWEEN will return numbers outside this range
SELECT Section_ID
FROM Student.Section
Where Section_ID between 10 and 90;
SELECT Section_ID
FROM Student.Section
Where Section_ID NOT BETWEEN 10 and 90;
Code examples contained herein are created by Chad Jensen (@cbjjensen) and/or Josh Kennedy (@JoshuaKennedy) and are placed in the public domain.
THE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE CODE.