OCT | Syntax: | OCT(Integer) | Return value: | CHAR | Function type: | Conversion function | |
|
|
The OCT() function returns a string representing the octal value of "Integer".
OCT() corresponds to the function CONV(Number,10,8), floating point values are rounded down to an integer.
Character strings are interpreted as integers.
If the value of the argument is not a number, the function returns 0.
If the value of the argument is NULL, OCT() returns NULL. |
SQL Examples for the OCT function |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
|
SELECT oct(128);
SELECT oct(15);
SELECT oct(-128);
SELECT conv(128,10,8);
SELECT conv(15,10,8);
SELECT oct(1.2);
SELECT oct(1.6);
SELECT oct('Test');
SELECT oct('128');
SELECT oct(null);
|
|
oct(128) |
varchar(64) BINARY |
200 |
|
|
oct(15) |
varchar(64) BINARY |
17 |
|
|
oct(-128) |
varchar(64) BINARY |
1777777777777777777600 |
|
|
conv(128,10,8) |
varchar(64) BINARY |
200 |
|
|
conv(15,10,8) |
varchar(64) BINARY |
17 |
|
|
oct(1.2) |
varchar(64) BINARY |
1 |
|
|
oct(1.6) |
varchar(64) BINARY |
1 |
|
|
oct('Test') |
varchar(64) BINARY |
0 |
|
|
oct('128') |
varchar(64) BINARY |
200 |
|
|
oct(null) |
varchar(64) BINARY |
NULL |
|
|
|
The examples were created with the MyWAY SQL manager: |
How to use the OCT() function in MySQL and MariaDB databases |
The OCT() function in MySQL and MariaDB is used to convert an integer value to its octal representation. The function takes a numeric value as input and returns a string of characters "0-7" representing the octal form of that value, for example to work with legacy systems or certain data formats that use octal notation use.
The octal representation returned by the OCT() function is a string and not a true octal data type. If octal arithmetic is to be performed or octal values are to be stored, conversion and interpretation of octal strings may need to be performed accordingly. |
|
Further MySQL und MariaDB SQL Conversion functions |
|