SQL - TAN() Function



SQL TAN() is a mathematical function that fetches the tangent of a numerical value as well as an angles value like PI(), PI()/2, PI()/3, PI()/4, and PI()/6, and returns the float expression representing the tangent of the given number in radians.

Syntax

Following is the syntax of the SQL TAN() function −

SELECT TAN(X) AS alias_name

Following is the syntax to use the TAN function in a SQL table −

SELECT TAN(Integer_column_name) AS Alias_Name FROM table_name;

We can use the above syntax, which will accept the column name that accepts the integer value, to perform the TAN function to find the tangent value.

Parameters

  • x − is the numeric value which returns in radians.

Example

In the following example, we are performing the SQL TAN() function, which will show the tangent of the specified number.

Following is the query −

SELECT TAN(10) AS tan;

Output

When we execute the above query, we get the tangent of the 10.

+--------------------+
| tan                |
+--------------------+
| 0.6483608274590866 |
+--------------------+

Example

In the following example, we are fetching the tangent value of the negative and 0 values as well.

Following is the query −

SELECT TAN(0) AS tanOfZero, TAN(-16) AS tanOfNegative;

Output

Following is the output of the above query, which will displays the tangent of zero and a negative value −

+-----------+---------------------+
| tanOfZero | tanOfNegative       |
+-----------+---------------------+
|         0 | -0.3006322420239034 |
+-----------+---------------------+

Example

In the following example, we are fetching the name and the tangent of the salary of the customer's table.

Let’s create a table named customers using the CREATE statement −

CREATE TABLE customers(ID INT NOT NULL PRIMARY KEY(ID), 
NAME VARCHAR(30) NOT NULL, 
AGE INT NOT NULL, 
ADDRESS CHAR(30), 
SALARY DECIMAL(18, 2));

Let’s insert the data into the CUSTOMERS using the INSERT statement −

insert INTO customers VALUES(1, 'Ramesh', 32, 'Ahmedabad', 2000);
insert INTO customers VALUES(2, 'Aman' 23, 'Ranchi', 40000);
insert INTO customers VALUES(3, 'kaushik', 23, 'Kota', 2000);
insert INTO customers VALUES(4, 'Chaitali', 25, 'Mumbai', 6500);
insert INTO customers VALUES(5, 'Rakesh', 24, 'Kota', 30000);
insert INTO customers VALUES(6, 'Vivek', 22, 'Ranchi', 35000);
insert INTO customers VALUES(7, 'Akash', 22, 'Ranchi', 50000);

Let’s display the customers details using the SELECT statement −

SELECT * FROM customers;

Following is the customers table −

+------+----------+------+-----------+--------+
| ID   | NAME     | AGE  | ADDRESS   | SALARY |
+------+----------+------+-----------+--------+
|    1 | Ramesh   |   32 | Ahmedabad |   2000 |
|    2 | Aman     |   23 | Ranchi    |  40000 |
|    3 | kaushik  |   23 | Kota      |   2000 |
|    4 | Chaitali |   25 | Mumbai    |   6500 |
|    5 | Rakesh   |   24 | kota      |  30000 |
|    6 | Vivek    |   22 | Ranchi    |  35000 |
|    7 | Akash    |   22 | Ranchi    |  50000 |
+------+----------+------+-----------+--------+

Following is the query to fetch the name and tangent −

SELECT NAME, TAN(SALARY) AS tanSalary FROM CUSTOMERS;

Output

Following is the output of the above SQL query. It displays the customers’ names and tangent salaries −

+----------+---------------------+
| NAME     | tanSalary           |
+----------+---------------------+
| Ramesh   |  -2.530998328093341 |
| kaushik  |  -2.530998328093341 |
| Chaitali | 0.04482971803926599 |
| Aman     |  2.9342108240743503 |
| Rakesh   |  1.3457841987739905 |
| Vivek    | -0.5253912236027812 |
| Akash    |  55.928056909865184 |
+----------+---------------------+
sql-numeric-functions.htm
Advertisements