PLSQL | ACOS Function
The PLSQL ACOS function is used to return the arc cosine of a number. The ACOS function only one parameter which is a number and the argument number must be in the range of -1 to 1, and the function returns a value in the range of 0 to pi, expressed in radians.
This function takes as an argument any numeric data type or any non-numeric data type that can be implicitly converted to a numeric data type.
Syntax:
ACOS( number )
Parameters Used:
number – It is used to specify the number arc cosine needs to be calculated.
Return Value:
The ACOS function in PLSQL returns a numeric value.
Supported Versions of Oracle/PLSQL:
- Oracle 12c
- Oracle 11g
- Oracle 10g
- Oracle 9i
- Oracle 8i
Example-1: Using a positive numeric value as an argument in the ACOS function.
DECLARE Test_Number number := 0.5; BEGIN dbms_output.put_line(ACOS(Test_Number)); END;
Output:
1.04719755119659774615421446109316762805
Example-2: Using a negative numeric value as an argument in the ACOS function.
DECLARE Test_Number number := -0.5; BEGIN dbms_output.put_line(ACOS(Test_Number)); END;
Output:
2.09439510239319549230842892218633525615
Example-3: Using a numeric value which doesn’t fall in the range between -1 and 1 as an argument in the ACOS function.
DECLARE Test_Number number := 4.5; BEGIN dbms_output.put_line(ACOS(Test_Number)); END;
Output:
ERROR ORA-01428: argument '4.5' is out of range
The above program throws an error since the argument passed is exceeding the range which can be accepted.
Example-4: Using ACOS function with select query.
SELECT ACOS(.3) FROM dual;
Output:
0.3046926540153975
Example-5: Using ACOS function with select query and returning the value in degree.
select (ACOS(.4)) * 57.29 FROM dual;
Output:
66.41512145087323
Using the conversion formula of 1 radian = 57.29 degrees.
Advantages:
The ACOS function accepts any numeric datatype or any non-numeric datatype as an argument that can be implicitly converted to a numeric datatype.