
- SQL Tutorial
- SQL - Home
- SQL - Overview
- SQL - RDBMS Concepts
- SQL - Databases
- SQL - Syntax
- SQL - Data Types
- SQL - Operators
- SQL - Expressions
- SQL Database
- SQL - Create Database
- SQL - Drop Database
- SQL - Select Database
- SQL - Rename Database
- SQL - Show Databases
- SQL - Backup Database
- SQL Table
- SQL - Create Table
- SQL - Show Tables
- SQL - Rename Table
- SQL - Truncate Table
- SQL - Clone Tables
- SQL - Temporary Tables
- SQL - Alter Tables
- SQL - Drop Table
- SQL - Delete Table
- SQL - Constraints
- SQL Queries
- SQL - Insert Query
- SQL - Select Query
- SQL - Select Into
- SQL - Insert Into Select
- SQL - Update Query
- SQL - Delete Query
- SQL - Sorting Results
- SQL Views
- SQL - Create Views
- SQL - Update Views
- SQL - Drop Views
- SQL - Rename Views
- SQL Operators and Clauses
- SQL - Where Clause
- SQL - Top Clause
- SQL - Distinct Clause
- SQL - Order By Clause
- SQL - Group By Clause
- SQL - Having Clause
- SQL - AND & OR
- SQL - BOOLEAN (BIT) Operator
- SQL - LIKE Operator
- SQL - IN Operator
- SQL - ANY, ALL Operators
- SQL - EXISTS Operator
- SQL - CASE
- SQL - NOT Operator
- SQL - NOT EQUAL
- SQL - IS NULL
- SQL - IS NOT NULL
- SQL - NOT NULL
- SQL - BETWEEN Operator
- SQL - UNION Operator
- SQL - UNION vs UNION ALL
- SQL - INTERSECT Operator
- SQL - EXCEPT Operator
- SQL - Aliases
- SQL Joins
- SQL - Using Joins
- SQL - Inner Join
- SQL - Left Join
- SQL - Right Join
- SQL - Cross Join
- SQL - Full Join
- SQL - Self Join
- SQL - Delete Join
- SQL - Update Join
- SQL - Left Join vs Right Join
- SQL - Union vs Join
- SQL Keys
- SQL - Unique Key
- SQL - Primary Key
- SQL - Foreign Key
- SQL - Composite Key
- SQL - Alternate Key
- SQL Indexes
- SQL - Indexes
- SQL - Create Index
- SQL - Drop Index
- SQL - Show Indexes
- SQL - Unique Index
- SQL - Clustered Index
- SQL - Non-Clustered Index
- Advanced SQL
- SQL - Wildcards
- SQL - Comments
- SQL - Injection
- SQL - Hosting
- SQL - Min & Max
- SQL - Null Functions
- SQL - Check Constraint
- SQL - Default Constraint
- SQL - Stored Procedures
- SQL - NULL Values
- SQL - Transactions
- SQL - Sub Queries
- SQL - Handling Duplicates
- SQL - Using Sequences
- SQL - Auto Increment
- SQL - Date & Time
- SQL - Cursors
- SQL - Common Table Expression
- SQL - Group By vs Order By
- SQL - IN vs EXISTS
- SQL - Database Tuning
- SQL Function Reference
- SQL - Date Functions
- SQL - String Functions
- SQL - Aggregate Functions
- SQL - Numeric Functions
- SQL - Text & Image Functions
- SQL - Statistical Functions
- SQL - Logical Functions
- SQL - Cursor Functions
- SQL - JSON Functions
- SQL - Conversion Functions
- SQL - Datatype Functions
- SQL Useful Resources
- SQL - Questions and Answers
- SQL - Quick Guide
- SQL - Useful Functions
- SQL - Useful Resources
- SQL - Discussion
SQL - RADIANS() Function
RADIANS() is a function in SQL that is very useful for the conversion, which converts the degree to the radians and returns the radians value.
Suppose we have a database table that stores the angles in a column. If we want to convert all angles’ degrees to radians, then we can pass the name of the table's column to the RADIANS() function.
Syntax
Following is the syntax of the SQL Radians() function −
SELECT RADIANS(numeric expression) AS Alias_name;
The numeric expression is the angle specified in radians. Except for bit data types, it can be the expression of the exact numeric or approximate numeric data types.
Following is the syntax of the RADIANS() function that is used in the SQL and fetches the data from the created table.
SELECT RADIANS(column_name) AS Alias_Name FROM table_name;
In the above syntax, we are using the table name that we have created, and we have to define the name of the column on which we want to perform the RADIANS() function.
Example
In the following example, we are finding the radians values of the given degree value of the exact numeric value using the RADIANS() function in SQL.
Following is the query −
SELECT RADIANS(90) AS Radians_value;
Output
When the above SQL query is executed, it gives the 1 radians value of the 90 degree because 90 is the exact numeric data type.
+--------------------+ | Radiansvalue_of_90 | +--------------------+ | 1 | +--------------------+
Example
In the following example, we are finding the radians value of the given fractional degree.
Following is the query −
SELECT RADIANS(180.0) AS radians_of_180;
Output
When the above SQL query is executed, it gives the fractional radians value of the 180.0 degree because 180.0 is an approximate numeric data type.
+---------------------+ |radians_of_180 | +---------------------+ |3.141592653589793116 | +---------------------+
Example
In the following example we are calculating the radians value of PI using the RADIANS() function in SQL.
Following is the query −
SELECT RADIANS(pi()) AS radians_of_180;
Output
Following is the output of the above SQL query −
+---------------------+ | radians_of_180 | +---------------------+ | 0.05483113556160755 | +---------------------+
Example
In the following example we are fetching the ID and calculating the radians value of the ID from the customers table.
Let’s create a table named customers using the CREATE statement −
CREATE TABLE customers(ID INT NOT NULL PRIMARY KEY(ID), NAME VARCHAR(30) NOT NULL, AGE INT NOT NULL, ADDRESS CHAR(30), SALARY DECIMAL(18, 2));
Let’s insert the data into the customers using the INSERT statement −
insert INTO customers VALUES(1, 'Ramesh', 32, 'Ahmedabad', 2000); insert INTO customers VALUES(2, 'Aman' 23, 'Ranchi', 40000); insert INTO customers VALUES(3, 'kaushik', 23, 'Kota', 2000); insert INTO customers VALUES(4, 'Chaitali', 25, 'Mumbai', 6500); insert INTO customers VALUES(5, 'Rakesh', 24, 'Kota', 30000); insert INTO customers VALUES(6, 'Vivek', 22, 'Ranchi', 35000); insert INTO customers VALUES(7, 'Akash', 22, 'Ranchi', 50000);
Let’s display the customers details using the SELECT statement −
SELECT * FROM customers;
Following is the customers table −
+------+----------+------+-----------+--------+ | ID | NAME | AGE | ADDRESS | SALARY | +------+----------+------+-----------+--------+ | 1 | Ramesh | 32 | Ahmedabad | 2000 | | 2 | Aman | 23 | Ranchi | 40000 | | 3 | kaushik | 23 | Kota | 2000 | | 4 | Chaitali | 25 | Mumbai | 6500 | | 5 | Rakesh | 24 | kota | 30000 | | 6 | Vivek | 22 | Ranchi | 35000 | | 7 | Akash | 22 | Ranchi | 50000 | +------+----------+------+-----------+--------+
Following is the query to fetch the ID and converting them into the radians and displaying the radians value of ID −
SELECT ID, RADIANS(ID) AS Radians_of_ID FROM customers;
Output
When we execute the above SQL query, we get the ID and its radians value. In SQL, the radians of each ID are 0 because IDs are not approximate numeric data types.
+----+---------------+ | ID | Radians_of_ID | +----+---------------+ | 1 | 0 | | 2 | 0 | | 3 | 0 | | 4 | 0 | | 5 | 0 | | 6 | 0 | | 7 | 0 | +----+---------------+