Monday, 6 February 2017

DATA QUERY LANGUAGE IN ORACLE



DATA QUERY LANGUAGE (OR) DATA RETRIEVAL LANGUAGE (DQL / DRL)

1. SELECT - Using select command we are fetching data from a table.
Syntax - select * from filename
Syntax - select col1,col2.... from tablename where condition group by colname having condition order by colname[asc/desc];

  • select all rows and columns
  • select all columns and particular rows
  • select particular columns and all rows
  • select particular columns and particular rows
Creating a new table from existing table / copying a table from existing table.
Syntax - create table tablename as select * from tablename;

Creating a new table from existing table without copying data
Syntax - create table tablename as select * from tablename where falsecondition;
Example -
SQL> create table d2 as select * from emp where 1=2;

OPERATORS USED IN SELECT STATEMENT

  1. Arithmetic Operator (*, /, +, -)
  2. Comparison Operator (=, <, <=, >, >=, <>(or) !=)
  3. Logical Operator (AND, OR, NOT)
  4. Special Operator - (IN, NOT IN, BETWEEN, NOT BETWEEN, IS NULL, IS NOT NULL, LIKE, NOT LIKE)
DECLARING ALIAS

An Alias is an another name or alternative name, aliases in Oracle are of two types.
  1. Column Alias : Alias declared for column is called column alias. Example - select ename as 'employee name' from emp;
  2. Table Alias

No comments:

Post a Comment