MySQL COS() Function

Last Updated : 26 Feb 2026

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.

Syntax

Parameters:

Num: It is the number to get cosine value.

Returns

This function returns the cosine of the given number.

Example 1

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.

MySQL Math COS() Function

Example 2

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.

MySQL Math COS() Function

Example 3

Output:

MySQL Math COS() Function

Example 3:

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

Example 4:

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

Using the MySQL COS() function in a Table

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.

IDDiagramColorValue
1ABCRed-1.22
2PQRBlue-0.5
3RSTGreen0
4DEFYellow0.25
5XYZPink1.55

Example:

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.

IDDiagramColorValueResult
1ABCRed-1.220.34364574631604705
2PQRBlue-0.50.8775825618903728
3RSTGreen01
4DEFYellow0.540.9689124217106447
5XYZPink1.550.020794827803092428

Using the MySQL COS() function in a Table column with a WHERE clause

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

IDDiagramColorValue
1ABCRed-1.22
2PQRBlue-0.5
3RSTGreen0
4DEFYellow0.54

Example:

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.

IDDiagramColorValueResult
2PQRBlue-0.50.8775825618903728
3RSTGreen01
4DEFYellow0.540.9689124217106447
5XYZPink1.550.020794827803092428

MySQL COS function with an UPDATE Statement

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.

IDDiagramColorValue
1ABCRed-1.22
2PQRBlue-0.5
3RSTGreen0
4DEFYellow0.54
5XYZPink1.55

Syntax:

Example: Write a MySQL query to calculate the COSINE value.

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.

IDDiagramColorValueCOSINE_VALUE
1ABCRed-1.220.34364574631604705
2PQRBlue-0.50.8775825618903728
3RSTGreen01
4DEFYellow0.540.9689124217106447
5XYZPink1.550.020794827803092428

Next TopicMySQL Math