Javatpoint Logo
Javatpoint Logo

OCT Function in SQL

The OCT is a SQL string function which converts the given decimal number to its octal equivalent.

Syntax of OCT Function

In the OCT syntax, we have to pass that decimal number whose octal equivalent we want to find.

In the Structured Query Language, we can also use the OCT function with the column of the table as shown in the following block:

In this syntax, we have to define the name and column of that table on which we want to perform the OCT function.

Examples of OCT function

Example 1: This example returns the octal representation of the specified number:

Output:

octal_of_101
145

Example 2: This example returns the octal representation of the specified number:

Output:

octal_of_2
2

Example 3: This example returns the representation of 8:

Output:

octal_of_8
10

Example 4: This example returns the octal representation of 255:

Output:

octal_of_255
377

Example 5: This example returns the octal representation of NULL:

Output:

octal_of_NUL
NULL

Example 6: This example returns the octal representation of NULL:

Output:

21 22 23 24 25 26 27 28 29 30
25 26 27 30 31 32 33 34 35 36

Example 7: This example uses the OCT function with the SQL table.

In this example, we will create the new table through which we will perform the OCT function on the columns of the table:

The following shows the syntax to create the new table in SQL:

The following CREATE statement creates the Product_Details table for storing the price and quantity of products:

The following multiple INSERT queries insert the records of products with their selling and purchasing price into the Product_Details table:

The following SELECT statement displays the inserted records of the above Product_Details table:


Product_ID Product_Name Product_Quantity Purchasing_Price Selling_Price Release_Date Product_Rating
104 P1 10.250 945 NULL 2022-04-30 NULL
202 P4 15.500 45 75 2022-01-28 5
103 P2 18.250 25 NULL 2022-02-18 4
111 P7 25.250 5 15 2021-12-25 9
210 P6 15.500 50 70 2021-10-15 NULL
212 P8 19.750 110 250 2022-01-28 4
112 P10 10.250 550 835 2022-04-11 NULL

Query 1: The following SELECT query uses the OCT function with the Product_Quantity column of the above Product_Details table:

This query shows the octal representation of product id of each product.

Output:

Product_ID octal_of_Product_ID
104 150
202 312
103 147
111 157
210 322
212 324
112 160

Query 2: The following SELECT query uses the OCT function with Selling_Price column of the above Product_Details table:

This query shows the octal representation of purchasing and selling price of each product.

Output:

Selling_Price octal_of_SellingPrice
NULL NULL
75 113
NULL NULL
15 17
70 106
250 372
835 1503

Query 3: The following SELECT query uses the OCT function with the Product_Rating column of the above Product_Details table:

This query shows the octal representation of rating of each product from the above table.

Output:

Product_Rating octal_of_productrating
NULL NULL
5 5
4 4
9 11
NULL NULL
4 4
NULL NULL






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA