The COS function in Oracle SQL is a trigonometric function that returns the cosine of a given angle.
It's important to remember that this function, like all trigonometric functions in Oracle, expects the input angle to be in radians, not degrees.
What is the COS Function in Oracle?
The COS function takes a single number (an angle in radians) and returns its cosine, which is a value between -1 and 1.
- Input: An angle expressed in radians.
- Output: The cosine of the angle, as a number.
- To convert degrees to radians: Use the formula
degrees * (pi / 180). A common approximation for pi is3.14159265359.
COS Function Syntax
The syntax for COS is:
COS(n)
Let's break that down:
n: The angle, expressed in radians, for which you want to find the cosine.
Oracle COS Function Examples
Here are two practical examples of how to use COS.
Example 1: Finding the Cosine of 0 Radians
This example finds the cosine of 0, which is 1.
Query:
SELECT
COS(0) AS "Cosine_of_0"
FROM DUAL;
Result:
Cosine_of_0
-----------
1
Example 2: Finding the Cosine of 180 Degrees
To find the cosine of 180 degrees, you must first convert it to radians. The radian equivalent of 180 degrees is pi (approx. 3.14159).
Query:
SELECT
COS(3.14159265359) AS "Cosine_of_180_Deg"
FROM DUAL;
Result:
Cosine_of_180_Deg
-----------------
-1
This query correctly returns -1, which is the cosine of 180 degrees (pi radians).
