• Home
  • Examples of DQL Function

    Examples of DQL Function

    Replace('helloworld', 'o', 'w')
    The result is helloworld.

    Example:

    Round(60.567) -> 60.57
    Round(60.567) -> 61
    Round(60.567, -2) -> 100

    Trunc(column|expression)- truncates the column or the expression to x decimal places.

    Example:

    Trunc(60.567, 2) -> 60.56

    Mod(column|expression) - calculates the remainder after dividing the column or expression by x.

    Example:

    Mod(7000, 5000) -> 2000

    Date functions:

    Sysdate:is a function which does not take any argument but returns the current date and time.

    Example:

    Select sysdate from dual;
    The above query will display the current date.

    Note:the dual table is owned by the SYS and can be accessed by everybody. It contains only one column and one row. The column heading is DUMMY and the value stored in the column is X.
    Month_between( date1, date2) - this function returns the number months between the two months specified.

    Example:

    Select month_between('01-sep-95', '11-jan-94')
    From dual;
    The above example will display the number months between the two dates that is 19.677.

    Group function or multiple-row functions:

    In the above session we knew about single row functions, which operates on a single row to give one result per row. Now we will discuss about multiple-row functions which are also called group functions.
    Group functions operate on sets of rows to give one result per group. These sets may be the whole table or the table is split into groups. Let?s see some of the group functions and their uses.

    Avg([distinct]column):- average value of column, ignoring null values. We can use avg for numeric data.

    Note:-the distinct keyword makes the function consider only non-duplicate values. By default the function includes duplicates.

    Count( *|[distinct] column) : the count function calculates the number of rows including duplicate rows with nulls using the distinct keyword with an eliminate the duplicates.

    Max([distinct] column): the max function finds the maximum value of the column that you have specified.

    Min([distinct] column) :- min function finds the minimum values of the column that you have specified.

    Stddev([distinct] column) : stddev function finds the standard deviation of column that you have specified.

    Sum([distinct] column): sum function finds the sum of all the values of the column that you have specified.

    Example-1:

    Select avg(emp-salary), max(emp-salary), min(emp-salary),
    Sum(emp-salary)
    From employee ;
    The above statement will display the average, maximum, minimum, sum of all the values of the column in the emp-salary column of employee table.

    Example-2:

    Select count( * )
    From employee
    Where dept-id = 50 ;
    The above query will show the count of all the records where dept-id is 50.


    About the Author



    Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

    We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





     PreviousNext