QUERIES in Oracle

Select, Insert, Update, Delete, Drop, Alter table, and Create are the few queries among many that can be executed in an Oracle database.

Oracle Select Query:
Uses: To fetch records from the database.

Syntax: To select records from a table.

SELECT * from table_name;  


SELECT * from students;  

Oracle Insert Query:
Uses: To insert records into a table.

INSERT into table_name VALUES(value1, value2, .. valuen);  


INSERT into students VALUES(10, 'Joy', 5);  

Oracle Update Query:
Uses: To update records of a table.


UPDATE table_name SET column_name1 = value1, column_name2 = value2 WHERE conditions;   


UPDATE students SET name = 'Joy', age = 5 WHERE id = 10;   

Oracle Delete Query:
Uses: To delete records of a table.


DELETE from table_name WHERE conditions;  


DELETE from students WHERE id = 10;   

Oracle Truncate Table Query:
Uses: To truncate or remove records of a table but not the structure.


TRUNCATE TABLE table_name;   


TRUNCATE TABLE students;   

Oracle Drop Query: To drop a table or a view.

Syntax: To drop a table.

DROP TABLE table_name;   

Syntax: To drop a view.

DROP VIEW view_name;   

Example: Dropping a table.

DROP TABLE students;   

Oracle Create Query:
Uses: To create a sequence, procedure, table, view, or a function.

Syntax: To create a table.

CREATE TABLE table_name
  column_1 data_type [ NULL | NOT NULL ],  
  column_2 data_type [ NULL | NOT NULL ],  
  column_n data_type [ NULL | NOT NULL ]  

Syntax: To create a view.

CREATE VIEW view_name AS  
SELECT column_1, column_2, … column_n  
FROM tables  
WHERE view_conditions; 

Example: Creating a table.

( id number(10) NOT NULL,    
  name varchar2(50) NOT NULL,    
  age number(100));    

Oracle Alter Query:
Uses: To add, modify, delete or drop columns of a table.

Syntax: To add columns in a table.

ALTER TABLE table_name   
ADD column data_type  [ NULL | NOT NULL ] ;      

Example: Adding a column in a table.

ALTER TABLE students   
ADD city varchar2(100);