Home » Oracle » Oracle Sql » Oracle sql tutorial :Basic Sql statement

Oracle sql tutorial :Basic Sql statement

we have already discussed about sql in the previous post

how to write sql queries

Please go through the post if you not read before. It gives a brief introduction sql statement

Here in this tutorial we will be presenting the Basic sql statement.

Basic sql statment is of the form

select [Distinct] { *,col alias…..} from table;

The important takeways from this
1) select is use to identify the column while from is used to identify the table
2) select ,from are the keywords
3) * signifies all column to be choosen from the table
4) col signifies the particular column to be choosen
4) Distinct eliminate the duplicates
5) Alias give selected column different headings
6) semi colon ;signifies the end of the statement
7) The portion from select to before from is called the select clause
8) The full statement is called sql statement

Some examples

select * from dept; The query select all the column from the table dept
select dept_no from dept; The query select dept_no column from the table dept
select dept_no,dept_name from dept; The query select mutiple column dept_no ,dept_name from the table dept
select dept_name nam from dept; The query select dept_name column and give it alias name nam from the table dept
select distinct status from absent_data; The query select distinct value of column status from the table absent_data

Some Important points about sql
1) sql statement are not case sensitive
ie. select and SELECT has same meaning
2) sql statement can be written in multiple lines
ie.
select dept_name,
dept_no
from
dept;
3) Keywords are not split across the line
4) It is good to write select clause on one line and from table on other lines for better readiblity

See also  Oracle Case Statement Explained with Tips and Examples

Some other operations on the select statement

1) Airthmetic Operation

We can use +,-,/,* on the select statement.Offcourse these are valid on column which are numeric in nature

Examples

select ename,salary+100 from sal; The query select ename and salary column and add 100 to salary column for each rows from the table sal
select ename, salary-200 from sal; The query select ename and salary column and deduct 200 to salary column for each rows from the table sal
select ename, salary*2 from dept; The query select ename and salary column and mulitply by 2 to salary column for each rows from the table sal
select ename, salary/2 from dept; The query select ename and salary column and divided by 2 to salary column for each rows from the table sal

2) Concatenation

We use concatination operator (||) to join two or more column

Examples

select empnname||deptname from emp;
This will concatenate empname and deptname for each rows in the table emp

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top