Skip to main content

Useful Oracle Queries

Sometimes we need to find the indexes present for a table or the table structure or db links present etc. To find these details we have some standard DB queries which gives us the required results. The following queries are applicable to only Oracle database.

SELECT * FROM ALL_TABLES  

The following query lists out all the tables present in the database. If you want search a particular table we can use it in the following way

SELECT * FROM ALL_TABLES WHERE TABLE_NAME LIKE '%emp%'

SELECT * FROM ALL_TAB_COLUMNS

This query list out all the columns. If we want to know a particular column is present in which all tables we can frame the query in the following way

SELECT * FROM ALL_TAB_COLUMNS WHERE COLUMN_NAME='ID';

SELECT * FROM ALL_DB_LINKS

This query will return the list of db links present in the database

SELECT * FROM ALL_INDEXES

This query will list out all the indexes present in the database.If we want to find the indexes present for a particular table we can frame the query in the following way

SELECT * FROM ALL_INDEXES WHERE TABLE_NAME='EMP'

If we want to find the DDL of an index we can use the following query

       Select Dbms_Metadata.Get_Ddl
       ( 'INDEX'
       , Index_Name
       , Owner
       )
       From   All_Indexes
       Where  Table_Name  = '<your table>'
      And    Table_Owner = '<your table owner>'
;

SELECT * FROM V$SESSION_LONGOPS

This query will list out all the long running queries that are currently being executed

SELECT * FROM V$LOCKED_OBJECT

This query will list out the all the locked objects list in the database

SELECT * FROM ALL_VIEWS

This query will list out all the views in the database

SELECT * FROM ALL_CONSTRAINTS

This query will list out all the constraints in the database

Hope this article helps you in your oracle working environment


Comments