The cos() is a Math function of MySQL. This function is used to get the cosine of the given number. In this article, we will explore the concept of MySQL COS() function in detail along with its various practical examples.
Num: It is the number to get cosine value.
This function returns the cosine of the given number.
Explanation: On the execution of above query, the cos() function returns the cosine value of the given angles.
Output: Following is the output is given below.

Explanation: On the execution of above query, the cos() function returns the cosine value of the given angles.
Output: Following is the output is given below.

Output:

Explanation: On execution of the above query, in the COS() function, we can pass the COS() function as an argument, returning the cos value.
Output: The output of this example is given below.
| RESULT |
| 1.2246467991473532e-16 |
Explanation: On execution of the above query, in the COS() function calculate the cosine value of 0 radians.
Output: The output of this example is given below.
| RESULT |
| 0 |
The MySQL COS function is used to find the cosine value of given column value.
Follow the steps given below to perform the MySQL COS() functionality in a table column.
Step 1: First, create a table named Math_Figure using the CREATE TABLE statement.
Step 2: After that INSERT data into a table using the INSERT TABLE statement.
Step 3: To check the information with the use of SELECT statement, whether the data is inserted or not.
| ID | Diagram | Color | Value |
|---|---|---|---|
| 1 | ABC | Red | -1.22 |
| 2 | PQR | Blue | -0.5 |
| 3 | RST | Green | 0 |
| 4 | DEF | Yellow | 0.25 |
| 5 | XYZ | Pink | 1.55 |
Explanation: On execution of the above statement, the COS function is used to return the COS value of the Value column in a Math_Figure table.
Output: The output of this example is given below.
| ID | Diagram | Color | Value | Result |
|---|---|---|---|---|
| 1 | ABC | Red | -1.22 | 0.34364574631604705 |
| 2 | PQR | Blue | -0.5 | 0.8775825618903728 |
| 3 | RST | Green | 0 | 1 |
| 4 | DEF | Yellow | 0.54 | 0.9689124217106447 |
| 5 | XYZ | Pink | 1.55 | 0.020794827803092428 |
The MySQL COS function is used to find the COS value of a given column value with restricted data using the WHERE clause.
Sample Table: Math_Figure
| ID | Diagram | Color | Value |
|---|---|---|---|
| 1 | ABC | Red | -1.22 |
| 2 | PQR | Blue | -0.5 |
| 3 | RST | Green | 0 |
| 4 | DEF | Yellow | 0.54 |
Explanation: On execution of the above statement, the COS function is used to return the cos value from the Value column in a Math_Figure table where the value of the ID column is greater than 1.
Output: The output of this example is given below.
| ID | Diagram | Color | Value | Result |
|---|---|---|---|---|
| 2 | PQR | Blue | -0.5 | 0.8775825618903728 |
| 3 | RST | Green | 0 | 1 |
| 4 | DEF | Yellow | 0.54 | 0.9689124217106447 |
| 5 | XYZ | Pink | 1.55 | 0.020794827803092428 |
In MySQL, the COS() function does not change the data in the table. With the use of the UPDATE statement we can update the data.
Take an example of the Math_Figure table, which contains the following information.
| ID | Diagram | Color | Value |
|---|---|---|---|
| 1 | ABC | Red | -1.22 |
| 2 | PQR | Blue | -0.5 |
| 3 | RST | Green | 0 |
| 4 | DEF | Yellow | 0.54 |
| 5 | XYZ | Pink | 1.55 |
Step1: First, add a new column i.e. COSINE_VALUE to the existing table using the ALTER statement.
Step2: After that use an UPDATE statement to set the value of the COSINE_VALUE column.
Explanation: On execution of the above statement, the COS function is used to return the COS value of the Value column in a Math_Figure table and the UPDATE statement is used to update the required changes in the table.
If you want to check whether the content is updated in the table or not, then use the following statement.
Output: The output of this example is given below.
| ID | Diagram | Color | Value | COSINE_VALUE |
|---|---|---|---|---|
| 1 | ABC | Red | -1.22 | 0.34364574631604705 |
| 2 | PQR | Blue | -0.5 | 0.8775825618903728 |
| 3 | RST | Green | 0 | 1 |
| 4 | DEF | Yellow | 0.54 | 0.9689124217106447 |
| 5 | XYZ | Pink | 1.55 | 0.020794827803092428 |
We request you to subscribe our newsletter for upcoming updates.