Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Databases
  • SQL
  • MySQL
  • PostgreSQL
  • PL/SQL
  • MongoDB
  • SQL Cheat Sheet
  • SQL Interview Questions
  • MySQL Interview Questions
  • PL/SQL Interview Questions
  • Learn SQL and Database
Open In App
Next Article:
ORD() Function in MySQL
Next article icon

OCT() function in MySQL

Last Updated : 01 Oct, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

OCT() function in MySQL is used to convert decimal number to octal. It returns equivalent octal value of a decimal number.

Syntax :

  OCT(number)  

Parameter : This method accepts only one parameter.

  • number : The decimal number which we want to convert.

Returns : It returns octal value of a decimal number.

Example-1 :
Octal representation of the decimal number 0 using OCT Function.

  SELECT OCT(0) AS Oct_number ;  

Output :

Oct_number
0

Example-2 :
Octal representation of the decimal number 2020 using OCT Function.

  SELECT OCT( 2020 ) AS Oct_number ;  

Output :

Oct_number
3744

Example-3 :
Using OCT Function to find octal representation of all decimal number present in a column. To demonstrate, let us create a table named Player.

  CREATE TABLE Player(    Player_id INT AUTO_INCREMENT,    Player_name VARCHAR(100) NOT NULL,  Playing_team VARCHAR(20) NOT NULL,  Run_Scored INT NOT NULL,  PRIMARY KEY(Player_id )    );  

Now, insert some data to the Player table –

  INSERT INTO    Player(Player_name, Playing_team, Run_Scored)  VALUES  ('Virat Kohli', 'RCB', 60 ),  ('Rohit Sharma', 'MI', 45),  ('Dinesh Karthik', 'KKR', 26 ),  ('Shreyash Iyer', 'DC', 40 ),  ('David Warner', 'SRH', 65),  ('Steve Smith', 'RR', 52 ),  ('Andre Russell', 'KKR', 70),  ('Jasprit Bumrah', 'MI', 10),  ('Risabh Panth', 'DC', 34 ) ;  

So, the Player Table is –

  SELECT * FROM Player;  
Player_id Player_name Playing_team Run_Scored
1 Virat Kohli RCB 60
2 Rohit Sharma MI 45
3 Dinesh Karthik KKR 26
4 Shreyash Iyer DC 40
5 David Warner SRH 65
6 Steve Smith RR 52
7 Andre Russell KKR 70
8 Jasprit Bumrah MI 10
9 Risabh Panth DC 34

Now, we will find run scored by each player in octal number using OCT Function.

  SELECT    Player_id, Player_name,  Playing_team, OCT(Run_Scored) AS RunInOctal  FROM Player ;  

Output :

Player_id Player_name Playing_team RunInOctal
1 Virat Kohli RCB 74
2 Rohit Sharma MI 55
3 Dinesh Karthik KKR 32
4 Shreyash Iyer DC 50
5 David Warner SRH 101
6 Steve Smith RR 64
7 Andre Russell KKR 106
8 Jasprit Bumrah MI 12
9 Risabh Panth DC 42


Next Article
ORD() Function in MySQL
author
jana_sayantan
Improve
Article Tags :
  • SQL
  • DBMS-SQL
  • mysql

Similar Reads

  • TAN() Function in MySQL
    TAN() function : This function in MySQL is used to return the tangent of a specified number. In any right triangle, the tangent of an angle is the length of the opposite side divided by the length of the adjacent side. Similarly, this can also be defined as tangent of x is the sine of x divided by t
    1 min read
  • ORD() Function in MySQL
    ORD() function in MySQL is used to find the code of the leftmost character in a string . If the leftmost character is not a multibyte character, it returns ASCII value. And if the leftmost character of the string str is a multibyte character, ORD returns the code for that character, calculated from
    3 min read
  • STD() function in MySQL
    With the help of STD() function we can calculate population Standard deviation of an expression in MySQL. But, if there are no matching rows in the given expression it returns Null. Syntax : STD(expr); Parameter : This method accepts only one parameter. expr : Input expression from which we want to
    3 min read
  • SQRT() Function in MySQL
    The SQRT() function in MySQL calculates the square root of a non-negative number, returning NULL for negative inputs. It is a built-in function that provides high precision and is optimized for performance and making it ideal for mathematical and scientific applications. In the article, we will cove
    4 min read
  • TIME() Function in MySQL
    The TIME() function in MySQL is used to extract the time portion from a date or datetime expression, returning the time in the format 'HH:MM'. This function is particularly useful when working with time components in databases, such as scheduling or logging systems. In this article, We will learn ab
    4 min read
  • TRIM() Function in MySQL
    TRIM() function in MySQL is used to clean up data. It is also used to remove the unwanted leading and trailing characters in a string. Syntax : TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str) Parameter : This method accepts three-parameter as mentioned above and described below : BOTH | LEADIN
    2 min read
  • PI() function in MySQL
    PI() function in MySQL is used to return the Pi value. The default number of decimal places displayed is seven, but MySQL uses the full double-precision value internally. Syntax : PI() Parameter : This method does not accept any parameter. Returns : It returns the Pi value i.e. 3.141593. Example-1 :
    2 min read
  • SUM() Function in MySQL
    The SUM() function in MySQL is a powerful aggregate function used to calculate the total sum of values in a numeric column. By summing up the values in the specified column, this function helps in generating overall totals and performing calculations that provide meaningful insights from our data. I
    4 min read
  • RIGHT() Function in MySQL
    RIGHT() function in MySQL is used to extract a specified number of characters from the right side of a given string. Second argument is used to decide, how many characters it should return. Syntax : RIGHT( str, len ) Parameter : This function accepts two parameter as mentioned above and described be
    3 min read
  • SPACE() Function in MySQL
    SPACE() function in MySQL is used to return a string consisting of specified empty space characters. Syntax : SPACE(num) Parameter : This method accepts one parameter as mentioned above and described below : num : It is an integer which indicates how many spaces are being contained. Returns : It ret
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences