Related Articles
PLSQL | ATAN2 Function
• Last Updated : 29 Oct, 2019

The PLSQL ATAN2 function is used to return the arc tangent of n and m. The ATAN2 function is generally used if you want to convert cartesian coordinates to polar coordinates. The ATAN2 function accepts two parameters which are numbers and the range accepted by the argument n is unbounded.

The ATAN2 function returns a value in the range of -pi to pi depending upon the signs of n and m, expressed in radians. This function takes as an argument any numeric data type as well as any non-numeric data type that can be implicitly converted to a numeric data type.

Syntax:

`ATAN2( n, m )`

Parameters Used:

number – It is used to specify the numbers for calculating the arc tangent.

Return Value:
The ATAN2 function in PLSQL returns a numeric value.

Supported Versions of Oracle/PLSQL:

1. Oracle 12c
2. Oracle 11g
3. Oracle 10g
4. Oracle 9i
5. Oracle 8i

Example-1: Using positive numeric values as arguments in the ATAN2 function.

```DECLARE
Test_Number1 number := 0.5;
Test_Number2 number := 0.3;

BEGIN
dbms_output.put_line(ATAN2(Test_Number1, Test_Number2));

END; ```

Output:

`1.03037682652431246378774332703115153196 `

Example-2: Using a positive and a negative numeric value as arguments in the ATAN2 function.

```DECLARE
Test_Number1 number := 0.5;
Test_Number2 number := -0.3;

BEGIN
dbms_output.put_line(ATAN2(Test_Number1, Test_Number2));

END; ```

Output:

`2.11121582706548077467490005624835135224 `

Example-3: Using both negative numeric values as arguments in the ATAN2 function.

```DECLARE
Test_Number1 number := -0.5;
Test_Number2 number := -0.3;

BEGIN
dbms_output.put_line(ATAN2(Test_Number1, Test_Number2));

END; ```

Output:

`-2.11121582706548077467490005624835135224 `

Example-4: Using ATAN2 function with select query and returning the value in degree.

`select (ATAN2(.4, .3)) * 57.29  FROM dual; `

Output:

`53.12474303931237 `

Using the conversion formula of 1 radian = 57.29 degrees.

Advantages:
The ATAN2 function accepts any numeric datatype as well as any non-numeric datatype as an argument that can be implicitly converted to a numeric datatype.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up