MySQL OCT() Function
The MySQL OCT() function converts a decimal number to a octal number and returns the result as a string value.
The OCT() function is equivalent to using the CONV() function with CONV(number, 10, 8) syntax.
Syntax
OCT(number)
Parameters
number |
Required. Specify the number to convert to a octal representation. |
Return Value
Returns the octal representation of a decimal number.
Example 1:
The example below shows the usage of OCT() function.
mysql> SELECT OCT(1); Result: '1' mysql> SELECT OCT(8); Result: '10' mysql> SELECT OCT(10); Result: '12' mysql> SELECT OCT(64); Result: '100' mysql> SELECT OCT(500); Result: '764' mysql> SELECT OCT(1000); Result: '1750'
Example 2:
Consider a database table called Sample with the following records:
Data | x |
---|---|
Data 1 | 10 |
Data 2 | 20 |
Data 3 | 30 |
Data 4 | 40 |
Data 5 | 50 |
The statement given below can be used to get the octal representation of values of column x.
SELECT *, OCT(x) AS OCT_Value FROM Sample;
This will produce the result as shown below:
Data | x | OCT_Value |
---|---|---|
Data 1 | 10 | 12 |
Data 2 | 20 | 24 |
Data 3 | 30 | 36 |
Data 4 | 40 | 50 |
Data 5 | 50 | 62 |
❮ MySQL Functions