Вы находитесь на странице: 1из 3

fld=field_name,tb=table_name

__________________________________

1) create a table
_________________

create table table_name(field_name datatype(size));

inset into table


________________________
insert into tablename(fld1,fld2,fld3...........)values(.................);

2) select a table
__________________
select * from table_name;
or

select * from table_name where query;

3) Alias creation
___________________
select field name as_____ from tb;
EX----select fst_name as name from emp;

4)Between condition--it is commonly used in range value;


_______________________
select fld1,fld2 from table where fld between value1 and value2;
____________________________________________________________________

5)like cond---it is commonly used in searching


_______________________________________________

select fld from tb where fld LIKE 'S%';

6)orderby clause
desc--in descending order.
___________________
select fld1,fld2 from tb ORDER BY fld;
or
select fld1,fld2 from tb ORDER BY fld DESC;

ex---select f_name,hire_date ,job_id from emp ORDER BY hire_date;

______________________________________________________________________

7)Delete function
____________________

delete from tb ;
or
delete from tb where condition;

8)update
___________________________________

update tb set fld1=value, fld2=value where condition;


_______________________________________________________
9) Group function
___________________
min,max,count,avg,sum

select gf(fn) from tb;


or
select gf(fn) from tb where cond;

ex--select AVG(sal),Max(sal),MIN(sal),SUM(sal) from emp where job_id LIKE'%REP%';

select count(emp_id) from emp;

___________________________________________________________________________________
_

10)group by---divide rows in a table into smaller groups by gropu by.


________________________________
select fld,group func(fld) from tb where cond;(group by expression)

ex--select fld,group func(fld) from tb where group by dep_id;

11) having clause


________________________

select fld1,froup_function from tb having group cond;

ex--- select fld1,MAX(fld) from emp GROUP BY dep_id HAVING MAX(sal)>value;

12)initcap--convert first char into capital letter in a string


_____________________________________________________________________

select initcap("expression") from dual;

13)concat--select concat("ABC","NHG")from dual;


____________

14) replace---replace ("String","matchingstring","replacestring");


___________

15)date function
__________________

add_months-- select add_month('19-Dec-2016',2) from dual;

16) sysdate--- current system date & time


select sysdate from dual;

17) last _day---select last_day(-feb-2015')from dual;

18) months_between()-- select months_between(sysdate,'1-feb-2016')from dual;

19)table joining
________________
cartesion product---it is defined joining without any cond;
ex---select * from fees,student;

20)equijoin---

select * from sname,scourse,ftotal from stu,fees wheres_id=fs_id;

21)innerjoin--
___________________

select sname,fname,ftotal from fees,student where fess.f_id=student.sid;

22)commit--it is used to save data permanently;


___________

commit;

23)rollback---this cmd is used to provide the previous data which is delete or


updated by user;
_______________________

rollback;

24)grant---give a previllage to user to acces to db


_________________________________________________
GRant create table,create view to manager;

1)Grant select on emp to sue,rich;

2)Grant update(dep_name,loc_id) on dep to manager;

revoke-- to removed the permission

revoke select on tb from manager;

25)sequence-- it is used for auto numbering


__________________________________________

create sequence sid start with 100 minvalue 100 maxvalue 300 incremented by2;

26)access the sequence--


_______________________

sequence name.nextval;

Вам также может понравиться