ORACLE
ORACLE CLAUSES
DISTINCT
FROM
ORDER BY
GROUP BY
HAVING
ORACLE TUTORIAL
Oracle Introduction
What Is Oracle
Create Tables
What Is Oracle
ORACLE TABLES
Create Tables
Create Table As
Alter Table
Drop Table
Global Temorary Tables
Local Temorary Tables
ORACLE VIEWS
Create View
ORACLE QUERIES
SELECT
INSERT
INSERT
INSERT ALL
UPDATE
DELETE
TRUNCATE TABLE
ORACLE OPERATORS
UNION
UNION ALL
INTERSECT
MINUS
ORACLE JOINS
INNER JOIN
OUTER JOIN
EQUI JOIN
SELF JOIN
CROSS JOIN
ANTI JOIN
SEMI JOIN
ORACLE ADVANCE
PROCEDURES
FUNCTION
CURSOR
TRIGGER

ORDER BY



Oracle - Order By


In Oracle, ORDER BY Clause is used to sort or re-arrange the records in the result set. The ORDER BY clause is only used with SELECT statement.


Syntax :

SELECT expressions  
FROM tables  
WHERE conditions  
ORDER BY expression [ ASC | DESC ];   

Parameters :

  • expressions: It specifies columns that you want to retrieve.

  • tables: It specifies the table name from where you want to retrieve records.

  • conditions: It specifies the conditions that must be fulfilled for the records to be selected.

  • ASC: It is an optional parameter that is used to sort records in ascending order.

  • DESC: It is also an optional parameter that is used to sort records in descending order.


    Oracle ORDER BY Example: (without ASC/DESC attribute)


    Let's take a table "supplier"


    Supplier table:

    CREATE TABLE  "SUPPLIER"   
       (    "SUPPLIER_ID" NUMBER,   
        "FIRST_NAME" VARCHAR2(4000),   
        "LAST_NAME" VARCHAR2(4000)  
       )  
    /  
    

    SUPPLIER_IDFIRST_NAMELAST_NAME
    1RanveerDesai
    2Noel Sean
    3RenuKapoor

    Execute this Query:

    SELECT *  
    FROM supplier  
    ORDER BY last_name; 
    

    Output:

    SUPPLIER_IDFIRST_NAMELAST_NAME
    1RanveerDesai
    3RenuKapoor
    2Noel Sean

    The above example returns the first_name ordered by last_name in ascending order.


    Oracle ORDER BY Example: (sorting in descending order)


    If you want to sort your result in descending order, you should use the DESC attribute in your ORDER BY clause:


    Execute this Query:
    SELECT *  
    FROM supplier  
    ORDER BY last_name DESC;  
    

    Output :
    SUPPLIER_IDFIRST_NAMELAST_NAME
    2Noel Sean
    3RenuKapoor
    1RanveerDesai

    The above example returns the first_name ordered by last_name in descending order.



    What Is Oracle

    What Is Oracle

    posted on 2019-11-29 01:11:21 - ORACLE Tutorials


    TRIGGER

    ORACLE - Trigger

    posted on 2019-11-28 22:14:22 - ORACLE Tutorials


    CURSOR

    ORACLE - Cursor

    posted on 2019-11-28 22:13:54 - ORACLE Tutorials


    Prompt Examples

    ChatGPT Prompt Examples

    posted on 2023-06-21 22:37:19 - ChatGPT Tutorials


    Use Cases

    Chat GPT Key Use Cases

    posted on 2023-06-21 21:03:17 - ChatGPT Tutorials


    Prompt Frameworks

    Prompt Frameworks

    posted on 2023-06-21 19:33:06 - ChatGPT Tutorials