How OCT() Works in MariaDB

In MariaDB, OCT() is a built-in function that returns a string representation of the octal value of its argument.

Syntax

The syntax goes like this:

OCT(N)

Where N is a longlong (BIGINT) number.

The function returns a string representation of the octal value of N. It’s equivalent to CONV(N,10,8).

Example

Here’s an example to demonstrate:

SELECT OCT(9);

Result:

+--------+
| OCT(9) |
+--------+
| 11     |
+--------+

Compared to CONV()

OCT() is equivalent to using the CONV() function to convert from base 10 to base 8, like this: CONV(N,10,8)

Example:

SELECT 
    OCT(84),
    CONV(84, 10, 8);

Result:

+---------+-----------------+
| OCT(84) | CONV(84, 10, 8) |
+---------+-----------------+
| 124     | 124             |
+---------+-----------------+

Non-Numeric Argument

Here’s an example of what happens when we provide a non-numeric argument:

SELECT OCT('Brush');

Result:

+--------------+
| OCT('Brush') |
+--------------+
| 0            |
+--------------+

Null Arguments

OCT() returns null if its argument is null:

SELECT OCT(null);

Result:

+-----------+
| OCT(null) |
+-----------+
| NULL      |
+-----------+

Missing Arguments

Calling OCT() with the wrong number of arguments, or without any arguments results in an error:

SELECT OCT();

Result:

ERROR 1582 (42000): Incorrect parameter count in the call to native function 'OCT'

And:

SELECT OCT(10, 2);

Result:

ERROR 1582 (42000): Incorrect parameter count in the call to native function 'OCT'