MySQL Tutorial MySQL Advanced MySQL Database Account Management MySQL References

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:

Datax
Data 110
Data 220
Data 330
Data 440
Data 550

The query 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:

DataxOCT_Value
Data 11012
Data 22024
Data 33036
Data 44050
Data 55062

❮ MySQL Functions

5