In Oracle, the ATAN2() function returns the arctangent (inverse tangent) of its two arguments.
Syntax
The syntax goes like this:
ATAN2(n1 , n2)
Where n1 can be in an unbounded range and returns a value in the range of –pi to pi, depending on the signs of n1 and n2, expressed in radians.
Example
Here’s an example:
SELECT ATAN2(0.3, 0.7)
FROM DUAL;
Result:
ATAN2(0.3,0.7) ____________________________________________ 0.404891786285083423312072929009442616553
Non-Numeric Argument
The arguments 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 ATAN2('One', 0.2)
FROM DUAL;
Result:
Error starting at line : 1 in command -
SELECT ATAN2('One', 0.2)
FROM DUAL
Error report -
ORA-01722: invalid number
However, here’s what happens when we change the one to 1 and keep the quotes:
SELECT ATAN2('1', '0.2')
FROM DUAL;
Result:
ATAN2('1','0.2')
___________________________________________
1.37340076694501586086127192644496114865
Null Values
If any argument is null, the result is null:
SET NULL 'null';
SELECT
ATAN2(null, 0.3),
ATAN2(0.3, null),
ATAN2(null, null)
FROM DUAL;
Result:
ATAN2(NULL,0.3) ATAN2(0.3,NULL) ATAN2(NULL,NULL)
__________________ __________________ ___________________
null null null
By default, SQLcl and SQL*Plus return an empty string 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 ATAN2() without passing any arguments returns an error:
SELECT ATAN2()
FROM DUAL;
Result:
Error starting at line : 1 in command - SELECT ATAN2() 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 ATAN2(1)
FROM DUAL;
Result:
Error starting at line : 1 in command - SELECT ATAN2(1) 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: