Javatpoint Logo
Javatpoint Logo

ACOS Function in SQL

The ACOS() is a mathematics function which returns the arc cosine value of the given number in the Structured Query Language. We have to specify the number between -1 to 1, otherwise this function returns NULL value in output.

Syntax of ACOS Function

In this SELECT syntax, we have to pass that numeric number in the function whose arc cosine value we want to find.

In the Structured Query Language, we can also use the ACOS function in SELECT query with the table field:

In this SELECT query, we have to define the name and field of that table on which we want to perform the ACOS function.

Examples of ACOS function

Example 1: This example returns the arc cos value of the specified number:

Output:

arc_cos_value_of_90
-

Example 2: This example returns the arc cos value of the specified number:

Output:

arc_cos_value_of_0.45
1.1040309

Example 3: This example returns the arc cos value representation of 19:

Output:

arc_cos_value_of_-0.19
1.7619

Example 4: This example uses the ACOS function with the SQL table.

In this example, we will create the new table through which we will perform the ACOS function on the numeric fields of the table:

The following shows the syntax to create the new table in SQL:

The following CREATE statement creates the Product_Details table for storing the price and quantity of products:

The following multiple INSERT queries insert the records of products with their selling and purchasing price into the Product_Details table:


Product_ID Product_Name Product_Quantity Purchasing_Price Selling_Price Release_Date Product_Rating
0.1 P1 0.250 0.5 NULL 2022-04-30 NULL
0.2 P4 0.500 0.45 -0.8 2022-01-28 0.25
0.3 P2 0.350 0.85 0.250 2022-02-18 0.15
0.4 P7 0.850 0.355 NULL 2021-12-25 0.45
0.5 P6 0.900 0.5 -0.500 2021-10-15 NULL
0.6 P8 0.750 0.110 -0.95 2022-01-28 -0.9
0.7 P10 0.250 0.550 0.258 2022-04-11 NULL

Query 1: The following SELECT query uses the ACOS function with the Product_Quantity column of the above Product_Details table:

This query shows the arc cos value of product id of each product.

Output:

Product_ID arc_cos_value_of_Product_ID
0.1 1.4706289056
0.2 1.369438
0.3 1.266103
0.4 1.1592794
0.5 1.04719755
0.6 0.92729
0.7 0.7953988

Query 2: The following SELECT query uses the ACOS function with the and Purchasing_Price and Selling_Price column of the above Product_Details table:

This query shows the arc cosine value of purchasing price of each product.

Output:

Purchasing_Price arc_cos_value_of_PurchasingPrice
0.5 1.04719
0.45 1.10403
0.85 0.55481
0.355 1.20788
0.5 1.04719
0.110 1.46057
0.550 0.98843

Query 3: The following SELECT query uses the ACOS function with the Product_Rating column of the above Product_Details table:

This query shows the arc cosine value of rating of each product from the above table.

Output:

Product_Rating arc_cos_value_of_productrating
NULL -
0.25 1.31811
0.15 1.42022
0.45 1.10403
NULL -
-0.9 2.69056
NULL -

Query 4: The following SELECT query uses the ACOS function with the Product_Quantity column of the above Product_Details table:

This query shows the arc cosine value of quantity of each product from the above table.

Output:

Product_Quantity arc_cos_value_of_productquantity
0.250 1.31811
0.500 1.04719
0.350 1.21322
0.850 0.55481
0.900 0.45102
0.750 0.722734
0.250 1.31811

Query 5: The following SELECT query uses the ACOS function with the and Purchasing_Price and Selling_Price column of the above Product_Details table:

This query shows the arc cosine value of purchasing and selling price of each product.

Output:

Selling_Price arc_cos_value_of_SellingPrice
NULL -
-0.8 2.49809
0.250 1.31811
NULL -
-0.500 2.09439
-0.95 2.82403
0.258 1.8397






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA