Archive for May, 2012

Where-In -Between

ceate table contact(
id number,
first_name varchar2(30),
last_name varchar2(30),
phone_number varchar2(15)
)

insert into contact values ( 1,’Sezayir’,’Dağtekin’,’32312121′)
insert into contact values ( 2,’Murat’,’Aktan’,’323434121′)
insert into contact values ( 3,’Duygu’,’Çetin’,’3987634121′)

OR Operator

select * from contact
where first_name=’Sezayir’ OR first_name=’Murat’;

Sadece Sezayir ve Murat döner

update contact set phone_number=’32312121′
where id=2;
1 rows updated.

update contact set first_name=’Sezayir’
where id=2;
1 rows updated.

select * from contact
where phone_number=’32312121′ and first_name=’Sezayir’;

Sezayir Dağtekin ,Sezayir Aktan iki kayıt döner

Yeni kolon ekleme

alter table contact add city varchar2(30)
1 rows updated.
1 rows updated.
1 rows updated.
table CONTACT altered.

3 kaydın city alanını güncelleme
update contact set city=’İstanbu’ where id=1
update contact set city=’İzmir’ where id=2
update contact set city=’Ankara’ where id=3

select * from contact
where city=’İzmir’ and first_name=’Murat’

IN
select * from contact
where id in(2,3)

select * from contact
where id NOT IN(2,3)

BETWEEN
insert into contact values ( 4,’Mehmet’,’Özcan’,’32312121′,’İzmir’)
insert into contact values ( 4,’Ceyda’,’Demir’,’32312121′,’İstanbul’)

select * from contact
where id between 2 and 4

2,3,4 id ‘li kayıtları döner

select * from contact
where id not between 2 and 4

sadece id’si 1 ve 5 olan kayıtları döner

Leave a comment

Sql Expression

Wehere Condition

ceate table contact(
id number,
first_name varchar2(30),
last_name varchar2(30),
phone_number varchar2(15)
)

insert into contact values ( 1,’Sezayir’,’Dağtekin’,’32312121′)
insert into contact values ( 2,’Murat’,’Aktan’,’323434121′)
insert into contact values ( 3,’Duygu’,’Çetin’,’3987634121′)

id numarası 2 ve 3 olan kişiler listelenir
select * from contact
where id>=2

where koşulundaki string’ler case sensetive. Aşağıdaki ifade bişey döndürmez.name büyük harfle başlamalı.
select * from contact
where first_name=’sezayir’

doğrusu

select * from contact
where first_name=’Sezayir’


Full Table Scan

Tum kayıtları getirir.
select * from contact where 1=1

Hiç bir kayıt dönmez
select * from contact where 1=2

tum kayırları döner
select * from contact where id=id

tabloyu kopyalama

create table contact2 as
select * from contact

1 rows inserted.
1 rows inserted.
1 rows inserted.
table CONTACT2 created.

Leave a comment

Sql Hızlandırılmış Tur

tablo yaratma

create table contact(
id number,
first_name varchar2(30),
last_name varchar2(30),
phone_number varchar2(15)
)

tablonun özelklliklerini görme

desc contact

Name Null Type
———— —- ————
ID NUMBER
FIRST_NAME VARCHAR2(30)
LAST_NAME VARCHAR2(30)
PHONE_NUMBER VARCHAR2(15)

)

Tabloya kayıt atma
insert into contact values ( 1,’Sezayir’,’Dağtekin’,’32312121′)

1 rows inserted.

select * from contact

insert into contact values ( 2,’Murat’,’Aktan’,’323434121′)
insert into contact values ( 3,’Duygu’,’Çetin’,’3987634121′)


Tablodaki kaydı güncelleme

update contact set phone_number=’56565644343′ where first_name=’Sezayir’

1 rows updated.


Tablodan kayıt silme

delete from contact where id=3

tablodaki tüm kayıtları silme
delete from contact
2 rows deleted.

hepsini siler. tehlikeli

Tabloyu silme
drop table contact
table CONTACT dropped.

desc contact
ERROR: object CONTACT does not exist
tabloyu uçurdu.

Leave a comment