Anda di halaman 1dari 7

SQL>

2
3
4
5
6

CREATE TABLE movies


( titleid int,title varchar(30),
time varchar(10),
release_date date,
genre varchar(20))
;

Table created.
SQL> alter table movies add constraint mo_gorilla primary key(titleid);
Table altered.
SQL> create table artist
2 ( name varchar(20),
3 titleid int);
Table created.
SQL> alter table movies add constraint fk_title foreign key(titleid) references
movies(titleid);
Table altered.
SQL>
2
3
4

create table director


( did int,
name varchar(20),
titleid int);

Table created.
SQL> alter table director add constraint fk_title1 foreign key(titleid) referenc
es movies(titleid);
Table altered.
SQL> insert into table values('&a','&b','&d','&e',&ab);
Enter value for a: a
Enter value for b:
Enter value for d:
Enter value for e:
Enter value for ab:
old 1: insert into table values('&a','&b','&d','&e',&ab)
new 1: insert into table values('a','','','',)
insert into table values('a','','','',)
*
ERROR at line 1:
ORA-00903: invalid table name
SQL> insert into movies values('&a','&b','&d','&e',&ab);
Enter value for a: gorilla
Enter value for b: 3:00
Enter value for d: 06-march-2016
Enter value for e: action
Enter value for ab: 1
old 1: insert into movies values('&a','&b','&d','&e',&ab)
new 1: insert into movies values('gorilla','3:00','06-march-2016','action',1)
1 row created.

SQL> /
Enter value for
Enter value for
Enter value for
Enter value for
Enter value for
old 1: insert
new 1: insert

a: sultan
b: 2:50
d: 06-jan-2015
e: romance
ab: 2
into movies values('&a','&b','&d','&e',&ab)
into movies values('sultan','2:50','06-jan-2015','romance',2)

1 row created.
SQL> /
Enter value for
Enter value for
Enter value for
Enter value for
Enter value for
old 1: insert
new 1: insert

a: dhammal
b: 2:00
d: 06-feb-2013
e: action
ab: 3
into movies values('&a','&b','&d','&e',&ab)
into movies values('dhammal','2:00','06-feb-2013','action',3)

1 row created.
SQL> /
Enter value for a: Harry potter
Enter value for b: 1:45
Enter value for d: 07-mar-2006
Enter value for e: 4
Enter value for ab:
old 1: insert into movies values('&a','&b','&d','&e',&ab)
new 1: insert into movies values('Harry potter','1:45','07-mar-2006','4',)
insert into movies values('Harry potter','1:45','07-mar-2006','4',)
*
ERROR at line 1:
ORA-00936: missing expression
SQL> /
Enter value for
Enter value for
Enter value for
Enter value for
Enter value for
old 1: insert
new 1: insert
4)

a: jab we meet
b: 2:10
d: 07-mar-2010
e: action
ab: 4
into movies values('&a','&b','&d','&e',&ab)
into movies values('jab we meet','2:10','07-mar-2010','action',

1 row created.
SQL> /
Enter value for
Enter value for
Enter value for
Enter value for
Enter value for
old 1: insert
new 1: insert
1 row created.

a: rocky
b: 3:00
d: 06-feb-2015
e: romance
ab: 5
into movies values('&a','&b','&d','&e',&ab)
into movies values('rocky','3:00','06-feb-2015','romance',5)

SQL> /
Enter value for
Enter value for
Enter value for
Enter value for
Enter value for
old 1: insert
new 1: insert
ller',6)

a: salt and pepper


b: 2:40
d: 02-dec-2012
e: thriller
ab: 6
into movies values('&a','&b','&d','&e',&ab)
into movies values('salt and pepper','2:40','02-dec-2012','thri

1 row created.
SQL> /
Enter value for
Enter value for
Enter value for
Enter value for
Enter value for
old 1: insert
new 1: insert
,7)

a: baby day out


b: 2:50
d: 04-mar-2016
e: action
ab: 7
into movies values('&a','&b','&d','&e',&ab)
into movies values('baby day out','2:50','04-mar-2016','action'

1 row created.
SQL> desc artist;
Name
Null?
----------------------------------------- -------NAME
TITLEID
SQL> insert into artist values('&name',&titleid);
Enter value for name: ram
Enter value for titleid: 1
old 1: insert into artist values('&name',&titleid)
new 1: insert into artist values('ram',1)

Type
---------------------------VARCHAR2(20)
NUMBER(38)

1 row created.
SQL> /
Enter value for
Enter value for
old 1: insert
new 1: insert

name: shyam
titleid: 1
into artist values('&name',&titleid)
into artist values('shyam',1)

1 row created.
SQL> /
Enter value for
Enter value for
old 1: insert
new 1: insert

name: ram
titleid: 2
into artist values('&name',&titleid)
into artist values('ram',2)

1 row created.
SQL> /
Enter value for
Enter value for
old 1: insert
new 1: insert

name: vaishali
titleid: 3
into artist values('&name',&titleid)
into artist values('vaishali',3)

1 row created.
SQL> /
Enter value for
Enter value for
old 1: insert
new 1: insert

name: hari
titleid: 4
into artist values('&name',&titleid)
into artist values('hari',4)

1 row created.
SQL> /
Enter value for
Enter value for
old 1: insert
new 1: insert

name: neethu
titleid: 5
into artist values('&name',&titleid)
into artist values('neethu',5)

1 row created.
SQL> /
Enter value for
Enter value for
old 1: insert
new 1: insert

name: govind
titleid: 5
into artist values('&name',&titleid)
into artist values('govind',5)

1 row created.
SQL> /
Enter value for
Enter value for
old 1: insert
new 1: insert

name: karthik
titleid: 6
into artist values('&name',&titleid)
into artist values('karthik',6)

1 row created.
SQL> /
Enter value for
Enter value for
old 1: insert
new 1: insert

name: raj
titleid: 7
into artist values('&name',&titleid)
into artist values('raj',7)

1 row created.

SQL> desc director;


Name
Null?
----------------------------------------- -------DID
NAME
TITLEID

SQL> insert into director values(&a,'&b',&c);


Enter value for a: 100
Enter value for b: kamal
Enter value for c: 1
old 1: insert into director values(&a,'&b',&c)

Type
---------------------------NUMBER(38)
VARCHAR2(20)
NUMBER(38)

new

1: insert into director values(100,'kamal',1)

1 row created.
SQL> /
Enter value for
Enter value for
Enter value for
old 1: insert
new 1: insert

a: 101
b: raj
c: 2
into director values(&a,'&b',&c)
into director values(101,'raj',2)

1 row created.
Table altered.
SQL> insert into director values(&a,'&b',&c);
Enter value for a: 100
Enter value for b: kamal
Enter value for c: 4
old 1: insert into director values(&a,'&b',&c)
new 1: insert into director values(100,'kamal',4)
1 row created.
SQL> /
Enter value for a: emi
Enter value for b:
Enter value for c:
old 1: insert into director values(&a,'&b',&c)
new 1: insert into director values(emi,'',)
insert into director values(emi,'',)
*
ERROR at line 1:
ORA-00936: missing expression
SQL> /
Enter value for
Enter value for
Enter value for
old 1: insert
new 1: insert

a: 103
b: jaanu
c: 5
into director values(&a,'&b',&c)
into director values(103,'jaanu',5)

1 row created.
SQL> /
Enter value for
Enter value for
Enter value for
old 1: insert
new 1: insert

a: 104
b: ramya
c: 6
into director values(&a,'&b',&c)
into director values(104,'ramya',6)

1 row created.
SQL> /
Enter value for
Enter value for
Enter value for
old 1: insert
new 1: insert

a: 105
b: vimal
c: 7
into director values(&a,'&b',&c)
into director values(105,'vimal',7)

1 row created.
4)
SQL> select distinct(d.did),m.genre from director d ,movies m ;
DID
---------100
103
101
102
101
102
105
100
102
100
103

GENRE
-------------------action
thriller
action
romance
romance
action
action
thriller
thriller
romance
action

DID
---------104
101
105
103
104
105
104

GENRE
-------------------action
thriller
thriller
romance
romance
romance
thriller

18 rows selected.
5)
SQL> SELECT NAME,COUNT(TITLEID) AS Movies_worked FROM ARTIST GROUP BY NAME;
NAME
MOVIES_WORKED
-------------------- ------------vaishali
1
neethu
1
ram
2
raj
1
hari
1
govind
1
shyam
1
karthik
1
8 rows selected.
6)
SQL> select a.name,m.title from artist a,movies m,DIRECTOR D where a.titleid=m.t
itleid AND (D.TITLEID=M.TITLEID) order by m.release_date ;
NAME
-------------------hari
karthik
vaishali
ram
neethu

TITLE
-----------------------------jab we meet
salt and pepper
dhammal
sultan
rocky

govind
raj
shyam
ram

rocky
baby day out
gorilla
gorilla

9 rows selected.HO
7)
SQL> SELECT M.GENRE, M.TITLE,D.NAME FROM MOVIES M,DIRECTOR D WHERE M.TITLEID=D.
TITLEID ORDER BY M.GENRE;
GENRE
-------------------action
action
action
action
romance
romance
thriller
7 rows selected.

TITLE
NAME
------------------------------ -------------------gorilla
kamal
jab we meet
kamal
baby day out
vimal
dhammal
tanuj
rocky
jaanu
sultan
raj
salt and pepper
ramya

Anda mungkin juga menyukai