SQL | Advanced Functions

Following are some of the advanced functions defined in SQL:

  1. BIN(): It converts a decimal number to a binary number.
    Syntax:

    SELECT BIN(18);
    

    Output:

  2. BINARY(): It converts a value to a binary string
    Syntax:

    SELECT BINARY "GeeksforGeeks";

    Output:

  3. COALESCE(): It returns the first non-null expression in a list.
    Syntax:

    SELECT COALESCE(NULL,NULL,'GeeksforGeeks',NULL,'Geeks');
    

    Output:

  4. CONNECTION_ID(): It returns the unique connection ID for the current connection.
    Syntax:

    SELECT CONNECTION_ID();
    

    Output:

  5. CURRENT_USER(): It returns the user name and host name for the MySQL account used by the server to authenticate the current client.
    Syntax:

    SELECT CURRENT_USER();
    

    Output:

  6. DATABASE(): It returns the name of the default database.
    Syntax:

    SELECT DATABASE();
    

    Output:

  7. IF(): It returns one value if a condition is TRUE, or another value if a condition is FALSE.
    Syntax:

    SELECT IF(200<500, "YES", "NO");
    

    Output:

  8. LAST_INSERT_ID(): It returns the first AUTO_INCREMENT value that was set by the most recent INSERT or UPDATE statement.
    Syntax:

    SELECT LAST_INSERT_ID();
    

    Output:

    • NULLIF(): It Compares two expressions.

    • Syntax:
      SELECT NULLIF(25.11, 25);
      

      Output:

    • Syntax:
      SELECT NULLIF(115, 115);
      

      Output:

  9. SESSION_USER(): It returns the user name and host name for the current MySQL user.
    Syntax:

    SELECT SESSION_USER();

    Output:

  10. SYSTEM_USER(): It returns the user name and host name for the current MySQL user.
    Syntax:

    SELECT SYSTEM_USER();
    

    Output:

  11. USER(): It returns the user name and host name for the current MySQL user.
    Syntax:

    SELECT USER();
    

    Output:

  12. VERSION(): It returns the version of the MySQL database.
    Syntax:

    SELECT VERSION();
    

    Output:



My Personal Notes arrow_drop_up

I like to do coding in C++C and java programming languages HTML and CSS always intersts me Sharing knowleged is the best way according to me to increase ones knwoledge

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.