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
STD() function in MySQL
With the help of STD() function we can calculate population Standard deviation of an expression in MySQL. But, if there are no matching rows in the given expression it returns Null. Syntax : STD(expr); Parameter : This method accepts only one parameter. expr : Input expression from which we want to
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 cove
4 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
PI() function in MySQL
PI() function in MySQL is used to return the Pi value. The default number of decimal places displayed is seven, but MySQL uses the full double-precision value internally. Syntax : PI() Parameter : This method does not accept any parameter. Returns : It returns the Pi value i.e. 3.141593. Example-1 :
2 min read
SUM() Function in MySQL
The SUM() function in MySQL is a powerful aggregate function used to calculate the total sum of values in a numeric column. By summing up the values in the specified column, this function helps in generating overall totals and performing calculations that provide meaningful insights from our data. I
4 min read
RIGHT() Function in MySQL
RIGHT() function in MySQL is used to extract a specified number of characters from the right side of a given string. Second argument is used to decide, how many characters it should return. Syntax : RIGHT( str, len ) Parameter : This function accepts two parameter as mentioned above and described be
3 min read
SPACE() Function in MySQL
SPACE() function in MySQL is used to return a string consisting of specified empty space characters. Syntax : SPACE(num) Parameter : This method accepts one parameter as mentioned above and described below : num : It is an integer which indicates how many spaces are being contained. Returns : It ret
1 min read