Oracle Order by - oracle tutorial - sql tutorial




What is Oracle ORDER BY Clause ?

  • 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.
  • Oracle distinct order by clause

    Oracle distinct order by clause

Syntax:

 SELECT expressions
FROM tables
WHERE conditions
ORDER BY expression [ ASC | DESC ];
click below button to copy the code. By - oracle tutorial - team

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 tutorial , sql tutorial , sql , pl sql tutorial , oracle , pl sql , plsql

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

  • Let's take a table "wikitechy_supplier"

Supplier table:

 CREATE TABLE  "WIKITECHY_SUPPLIER" 
   (	"SUPPLIER_ID" NUMBER, 
	"FIRST_NAME" VARCHAR2(4000), 
	"LAST_NAME" VARCHAR2(4000)
   )
/
click below button to copy the code. By - oracle tutorial - team

Execute this Query:

 SELECT *
FROM wikitechy_supplier
ORDER BY last_name;
click below button to copy the code. By - oracle tutorial - team

Output

  • 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 wikitechy_supplier
ORDER BY last_name DESC;
click below button to copy the code. By - oracle tutorial - team

Output

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

This tutorial provides an indepth knowledge on the following items such as oracle tutorial , sql tutorial , sql , pl sql tutorial , oracle , pl sql , mysql tutorial , sql tutorial for beginners , learn sql , oracle database tutorial , sql query tutorial , oracle dba tutorial , plsql tutorial , oracle tutorial pdf , oracle pl sql tutorial , oracle sql tutorial , sql tutorial point , oracle tutorial for beginners , learn oracle online free , learn oracle online , learning pl sql programming , learn sql online for free , sql learning online , dba oracle tutorial , oracle sql tutorial advanced , oracle 11g dba tutorial with examples , oracle online learning , oracle learning online , how to learn pl sql , sql coding tutorial , sql learning websites , sql basic learning

Related Searches to Oracle Order by