TAN() Function in Oracle

In Oracle, the TAN() function returns the tangent of its argument, where the argument is an angle expressed in radians.

Syntax

The syntax goes like this:

TAN(n)

Where n is an angle expressed in radians. It can be any numeric data type or any nonnumeric data type that can be implicitly converted to a numeric data type.

Example

Here’s an example:

SELECT TAN(2)
FROM DUAL;

Result:

                                      TAN(2) 
____________________________________________ 
   -2.18503986326151899164330610231368254341

Non-Numeric Argument

As mentioned, the argument can be any numeric data type or any nonnumeric data type that can be implicitly converted to a numeric data type.

Here’s what happens when we provide a non-numeric argument that can’t be converted to a numeric data type:

SELECT TAN('Two')
FROM DUAL;

Result:

Error starting at line : 1 in command -
SELECT TAN('Two')
FROM DUAL
Error report -
ORA-01722: invalid number

Null Values

Passing null to TAN() returns null:

SET NULL 'null';

SELECT TAN(null)
FROM DUAL;

Result:

   TAN(NULL) 
____________ 
        null 

By default, SQLcl and SQL*Plus return a blank space whenever null occurs as a result of a SQL SELECT statement.

However, you can use SET NULL to specify a different string to be returned. Here I specified that the string null should be returned.

Incorrect Argument Count

Calling TAN() without passing any arguments returns an error:

SELECT TAN()
FROM DUAL;

Result:

Error starting at line : 1 in command -
SELECT TAN()
FROM DUAL
Error at Command Line : 1 Column : 8
Error report -
SQL Error: ORA-00909: invalid number of arguments
00909. 00000 -  "invalid number of arguments"
*Cause:    
*Action:

And passing the wrong number of arguments results in an error:

SELECT TAN(1, 2)
FROM DUAL;

Result:

Error starting at line : 1 in command -
SELECT TAN(1, 2)
FROM DUAL
Error at Command Line : 1 Column : 8
Error report -
SQL Error: ORA-00909: invalid number of arguments
00909. 00000 -  "invalid number of arguments"
*Cause:    
*Action: