TAN Function in SQL

The TAN() is a mathematics function which returns the tangent value of the given number in the Structured Query Language.

Syntax of TAN Function

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

In the Structured Query Language, we can also use the TAN 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 TAN function.

Examples of TAN function

Example 1: This example returns the tangent value of the specified number:

Output:

tan_value_of_1.75
-5.5203799225093304

Example 2: This example returns the tangent value of the specified number:

Output:

tan_value_of_45
1.6197751905438615

Example 3: This example returns the tangent value representation of 19:

Output:

tan_value_of_19
0.15158947061240008

Example 4: This example returns the tangent value representation of the numbers from 21 to 30:

Output:

21222324252627282930
-1.5278.85151.5881-2.1348-0.1331.1787-3.273-0.28140.8871-6.4053

Example 5: This example uses the TAN function with the SQL table.

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

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:

The following SELECT statement displays the inserted records of the above Product_Details table:


Product_IDProduct_NameProduct_QuantityPurchasing_PriceSelling_PriceRelease_DateProduct_Rating
64P110.250945NULL2022-04-30NULL
88P415.50045752022-01-285
95P218.25025NULL2022-02-184
58P725.2505152021-12-259
26P615.50050702021-10-15NULL
85P819.7501102502022-01-284
91P1010.2505508352022-04-11NULL

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

This query returns the tangent value of product id of each product from the table.

Output:

Product_IDtan_value_of_Product_ID
642.3478603091954366
883.5420501339376929E-2
950.9357524720632393
588.335086
261.1787
850.17787
91-0.1065878

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

This query shows the tangent value of purchasing price of each product.

Output:

Purchasing_Pricetan_value_of_PurchasingPrice
945-0.71298
451.61977
25-0.1335
5-3.30581
50-0.271900611
1100.0442860
5500.224969

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

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

Output:

Product_Ratingtan_value_of_productrating
NULL-
5-3.3808515
41.15782
9-0.452315
NULL-
41.15782
NULL-

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

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

Output:

Product_Quantitytan_value_of_productquantity
10.2501.08299
15.500-0.211014
18.250-0.6834
25.2500.117799
15.500-0.211014
19.7501.2613
10.2501.08299