PLSQL | COS Function

The PLSQL COS function is used to return the cosine of a numeric value. The COS function accepts one parameter which is the number whose cosine needs to be calculated. The COS function returns a value of the numeric data type.

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. If in any case, the argument is BINARY_FLOAT, then the COS function returns BINARY_DOUBLE.

Syntax:



COS(number)

Parameters Used:

number – It is used to specify the number whose cosine needs to be calculated.

Return Value:
The COS 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 value as an argument in the COS function.

DECLARE 
   Test_Number1 number := 0.5;
   
BEGIN 
   dbms_output.put_line(COS(Test_Number1)); 
   
END; 

Output:

0.8775825618903727161162815826038296520119 

Example-2: Using 0 value as an argument in the COS function.

DECLARE 
   Test_Number1 number := 0;
   
BEGIN 
   dbms_output.put_line(COS(Test_Number1)); 
   
END; 

Output:

1 

Example-3: Using 1 value as an argument in the COS function.

DECLARE 
   Test_Number1 number := 1;
   
BEGIN 
   dbms_output.put_line(COS(Test_Number1)); 
   
END; 

Output:


0.5403023058681397174009366074429766037354 

Example-4: Using a negative value as an argument in the COS function.

DECLARE 
   Test_Number1 number := -5;
   
BEGIN 
   dbms_output.put_line(COS(Test_Number1)); 
   
END; 

Output:
0.2836621854632262644666391715135573083265

Example-5: Using COS function with select query and returning the value in degrees.

select (COS(5)) * 57.29  FROM dual; 

Output:

16.25100660518823 

Using the conversion formula of 1 radian = 57.29 degrees.

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



My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.