OCT() function in MySQL is used to convert decimal number to octal. It returns equivalent octal value of a decimal number.
Syntax :
OCT(number)
Parameter : This method accepts only one parameter.
- number : The decimal number which we want to convert.
Returns : It returns octal value of a decimal number.
Example-1 :
Octal representation of the decimal number 0 using OCT Function.
SELECT OCT(0) AS Oct_number ;
Output :
Example-2 :
Octal representation of the decimal number 2020 using OCT Function.
SELECT OCT( 2020 ) AS Oct_number ;
Output :
Example-3 :
Using OCT Function to find octal representation of all decimal number present in a column. To demonstrate, let us create a table named Player.
CREATE TABLE Player(
Player_id INT AUTO_INCREMENT,
Player_name VARCHAR(100) NOT NULL,
Playing_team VARCHAR(20) NOT NULL,
Run_Scored INT NOT NULL,
PRIMARY KEY(Player_id )
);
Now, insert some data to the Player table -
INSERT INTO
Player(Player_name, Playing_team, Run_Scored)
VALUES
('Virat Kohli', 'RCB', 60 ),
('Rohit Sharma', 'MI', 45),
('Dinesh Karthik', 'KKR', 26 ),
('Shreyash Iyer', 'DC', 40 ),
('David Warner', 'SRH', 65),
('Steve Smith', 'RR', 52 ),
('Andre Russell', 'KKR', 70),
('Jasprit Bumrah', 'MI', 10),
('Risabh Panth', 'DC', 34 ) ;
So, the Player Table is -
SELECT * FROM Player;
Player_id |
Player_name |
Playing_team |
Run_Scored |
1 |
Virat Kohli |
RCB |
60 |
2 |
Rohit Sharma |
MI |
45 |
3 |
Dinesh Karthik |
KKR |
26 |
4 |
Shreyash Iyer |
DC |
40 |
5 |
David Warner |
SRH |
65 |
6 |
Steve Smith |
RR |
52 |
7 |
Andre Russell |
KKR |
70 |
8 |
Jasprit Bumrah |
MI |
10 |
9 |
Risabh Panth |
DC |
34 |
Now, we will find run scored by each player in octal number using OCT Function.
SELECT
Player_id, Player_name,
Playing_team, OCT(Run_Scored) AS RunInOctal
FROM Player ;
Output :
Player_id |
Player_name |
Playing_team |
RunInOctal |
1 |
Virat Kohli |
RCB |
74 |
2 |
Rohit Sharma |
MI |
55 |
3 |
Dinesh Karthik |
KKR |
32 |
4 |
Shreyash Iyer |
DC |
50 |
5 |
David Warner |
SRH |
101 |
6 |
Steve Smith |
RR |
64 |
7 |
Andre Russell |
KKR |
106 |
8 |
Jasprit Bumrah |
MI |
12 |
9 |
Risabh Panth |
DC |
42 |
Similar Reads
TAN() Function in MySQL TAN() function : This function in MySQL is used to return the tangent of a specified number. In any right triangle, the tangent of an angle is the length of the opposite side divided by the length of the adjacent side. Similarly, this can also be defined as tangent of x is the sine of x divided by t
1 min read
ORD() Function in MySQL ORD() function in MySQL is used to find the code of the leftmost character in a string . If the leftmost character is not a multibyte character, it returns ASCII value. And if the leftmost character of the string str is a multibyte character, ORD returns the code for that character, calculated from
3 min read
SQRT() Function in MySQL The SQRT() function in MySQL calculates the square root of a non-negative number, returning NULL for negative inputs. It is a built-in function that provides high precision and is optimized for performance and making it ideal for mathematical and scientific applications.In the article, we will cover
3 min read
TIME() Function in MySQL The TIME() function in MySQL is used to extract the time portion from a date or datetime expression, returning the time in the format 'HH:MM'. This function is particularly useful when working with time components in databases, such as scheduling or logging systems. In this article, We will learn ab
4 min read
TRIM() Function in MySQL TRIM() function in MySQL is used to clean up data. It is also used to remove the unwanted leading and trailing characters in a string. Syntax : TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str) Parameter : This method accepts three-parameter as mentioned above and described below : BOTH | LEADIN
2 min read