Wednesday, July 4, 2007
Oracle basics and opearators
Oracle basics and opearators
selecting all column
select * from emp;
------------------------------------------------------------
sql*plus command
sql>SET AUTOCOMMIT on
sql>SET AUTOCOMMIT 10
sql>set linesize 120
----------------------------------------------------
sql>COLUMN ENAME HEADING 'EMPLOYEE |NAME'
sql>COLUMN SAL FORMAT $9,999,990.99
----------------------------------------------------
****ACCOMODATING SQL COMMAND TO A FILE********
SQL>select empno,ename,sal from emp where job='&1'
SQL>save c:/job1.sql
SQL>START c:/job1.sql
----------------------------------------------------
*****define a variable ************
sql>define rem='sal*12+nvl(comm,0)';
sql>select ename,job,&rem from emp order by &rem;
sql>undefine rem
----------------------------------------------------
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!operators!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
ARITHMETIC
select 12+3,13*4,14-5,16/4 from dual;
----------------------------------------------------
CONCATENATION
select empno||'_'||ename employee, 'works in department' from emp;
----------------------------------------------------------------
****null value******
select ename,sal*12+comm annual_sal from emp;
select ename,sal*12+nvl(comm,0) annual_sal
from emp;
------------------------------------------------------------
*****where clause and operators*******
select * from emp
where ename='SMITH'
-----
where deptno<20>sal
-----
where sal>=comm
-----
where sal between 1000 and 2000
-----
where mgr in(7902,7566,7788)
-----
where ename like 'S%'
-----
where comm is null
-----
where sal between 1000 and 2000 and job='CLERK'
-----
where sal between 1000 and 2000 or job='CLERK'
---------------------------------------------------------------
*****distinct clause*****
select distinct deptno,job
from emp;
-------------------------------------------------------------
****order by*******
select deptno,job,ename
from emp
order by deptno,sal desc;
------------------------------------------------------------
*******USER INPUT********
select * from emp where deptno=&Department_no
-----------------------------------------------------------
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment