OCT Function in SQLThe OCT is a SQL string function which converts the given decimal number to its octal equivalent. Syntax of OCT FunctionIn 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 functionExample 1: This example returns the octal representation of the specified number: Output:
Example 2: This example returns the octal representation of the specified number: Output:
Example 3: This example returns the representation of 8: Output:
Example 4: This example returns the octal representation of 255: Output:
Example 5: This example returns the octal representation of NULL: Output:
Example 6: This example returns the octal representation of NULL: Output:
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:
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:
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:
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:
Next TopicSIGN Function in SQL |