Sie sind auf Seite 1von 45

EXERCISE-3 DATE:


Aim:TO Implement Select, Insert, Delete, and Update Queries to Retrieve and Change Data

SQL> create table depositor(cust_name varchar(10),acc_no numeric(12));

Table created.

SQL> insert into depositor values('&cust_name',&acc_no);

Enter value for cust_name: john

Enter value for acc_no: 716789650954

old 1: insert into depositor values('&cust_name',&acc_no)

new 1: insert into depositor values('john',716789650954)

1 row created.

SQL> /

Enter value for cust_name: smith

Enter value for acc_no: 876534679876

old 1: insert into depositor values('&cust_name',&acc_no)

new 1: insert into depositor values('smith',876534679876)

1 row created.

SQL> /
Enter value for cust_name: robert

Enter value for acc_no: 678564579876

old 1: insert into depositor values('&cust_name',&acc_no)

new 1: insert into depositor values('robert',678564579876)

1 row created.

SQL> /

Enter value for cust_name: alex

Enter value for acc_no: 876534560987

old 1: insert into depositor values('&cust_name',&acc_no)

new 1: insert into depositor values('alex',876534560987)

1 row created.

SQL> /

Enter value for cust_name: johnson

Enter value for acc_no: 987645673409

old 1: insert into depositor values('&cust_name',&acc_no)

new 1: insert into depositor values('johnson',987645673409)


1 row created.

SQL> /

Enter value for cust_name: jockey

Enter value for acc_no: 872598657890

old 1: insert into depositor values('&cust_name',&acc_no)

new 1: insert into depositor values('jockey',872598657890)

1 row created.

SQL> /

Enter value for cust_name: ross

Enter value for acc_no: 765694539876

old 1: insert into depositor values('&cust_name',&acc_no)

new 1: insert into depositor values('ross',765694539876)

1 row created.

SQL> /

Enter value for cust_name: ihaka

Enter value for acc_no: 987526789546


old 1: insert into depositor values('&cust_name',&acc_no)

new 1: insert into depositor values('ihaka',987526789546)

1 row created.

SQL> /

Enter value for cust_name: foobar

Enter value for acc_no: 678734560987

old 1: insert into depositor values('&cust_name',&acc_no)

new 1: insert into depositor values('foobar',678734560987)

1 row created.

SQL> /

Enter value for cust_name: tommocen

Enter value for acc_no: 567896435098

old 1: insert into depositor values('&cust_name',&acc_no)

new 1: insert into depositor values('tommocen',567896435098)

1 row created.
SQL> select * from depositor;

CUST_NAME ACC_NO

---------- ----------

john 7.1679E+11

smith 8.7653E+11

robert 6.7856E+11

alex 8.7653E+11

johnson 9.8765E+11

jockey 8.7260E+11

ross 7.6569E+11

ihaka 9.8753E+11

foobar 6.7873E+11

tommocen 5.6790E+11

10 rows selected.

SQL> create table borrower(cust_name varchar(10),loan_no numeric(16));

Table created.
SQL> insert into borrower values('&cust_name',&loan_no);

Enter value for cust_name: noah

Enter value for loan_no: 768586430743

old 1: insert into borrower values('&cust_name',&loan_no)

new 1: insert into borrower values('noah',768586430743)

1 row created.

SQL> /

Enter value for cust_name: liam

Enter value for loan_no: 456487649521

old 1: insert into borrower values('&cust_name',&loan_no)

new 1: insert into borrower values('liam',456487649521)

1 row created.

SQL> /

Enter value for cust_name: mason

Enter value for loan_no: 479376520187

old 1: insert into borrower values('&cust_name',&loan_no)

new 1: insert into borrower values('mason',479376520187)


1 row created.

SQL> /

Enter value for cust_name: jacob

Enter value for loan_no: 765983247623

old 1: insert into borrower values('&cust_name',&loan_no)

new 1: insert into borrower values('jacob',765983247623)

1 row created.

SQL> /

Enter value for cust_name: william

Enter value for loan_no: 432905436789

old 1: insert into borrower values('&cust_name',&loan_no)

new 1: insert into borrower values('william',432905436789)

1 row created.

SQL> /

Enter value for cust_name: ethan


Enter value for loan_no: 340927895432

old 1: insert into borrower values('&cust_name',&loan_no)

new 1: insert into borrower values('ethan',340927895432)

1 row created.

SQL> /

Enter value for cust_name: james

Enter value for loan_no: 984576324567

old 1: insert into borrower values('&cust_name',&loan_no)

new 1: insert into borrower values('james',984576324567)

1 row created.

SQL> /

Enter value for cust_name: elijah

Enter value for loan_no: 985423896543

old 1: insert into borrower values('&cust_name',&loan_no)

new 1: insert into borrower values('elijah',985423896543)

1 row created.
SQL> /

Enter value for cust_name: michael

Enter value for loan_no: 560536459854

old 1: insert into borrower values('&cust_name',&loan_no)

new 1: insert into borrower values('michael',560536459854)

1 row created.

SQL> /

Enter value for cust_name: benjamin

Enter value for loan_no: 764359865432

old 1: insert into borrower values('&cust_name',&loan_no)

new 1: insert into borrower values('benjamin',764359865432)

1 row created.

SQL> select * from borrower;

CUST_NAME LOAN_NO

---------- ----------
noah 7.6859E+11

liam 4.5649E+11

mason 4.7938E+11

jacob 7.6598E+11

william 4.3291E+11

ethan 3.4093E+11

james 9.8458E+11

elijah 9.8542E+11

michael 5.6054E+11

benjamin 7.6436E+11

10 rows selected.

SQL>

SQL> /

Enter value for loan_no: 984576324567

Enter value for branch_name: italy

Enter value for amount: 15000

old 1: insert into loan values(&loan_no,'&branch_name',&amount)

new 1: insert into loan values(984576324567,'italy',15000)


1 row created.

SQL> /

Enter value for loan_no: 985423896543

Enter value for branch_name: nagpur

Enter value for amount: 90000

old 1: insert into loan values(&loan_no,'&branch_name',&amount)

new 1: insert into loan values(985423896543,'nagpur',90000)

1 row created.

SQL> /

Enter value for loan_no: 560536459854

Enter value for branch_name: nellore

Enter value for amount: 85000

old 1: insert into loan values(&loan_no,'&branch_name',&amount)

new 1: insert into loan values(560536459854,'nellore',85000)

1 row created.

SQL> /
Enter value for loan_no: 764359865432

Enter value for branch_name: hyderabad

Enter value for amount: 200000

old 1: insert into loan values(&loan_no,'&branch_name',&amount)

new 1: insert into loan values(764359865432,'hyderabad',200000)

1 row created

SQL> select * from loan;

LOAN_NO BRANCH_NAM AMOUNT

---------- ---------- ----------

7.6859E+11 pune 50000

4.5649E+11 vizag 25000

4.7938E+11 raichur 70000

7.6598E+11 visaka 75000

4.3291E+11 vijayawada 80000

3.4093E+11 jarkhand 100000

9.8458E+11 italy 15000

9.8542E+11 nagpur 90000

5.6054E+11 nellore 85000

7.6436E+11 hyderabad 200000


10 rows selected.

SQL> create table customer(cust_name varchar(10),city varchar(10),street integer

);

Table created.

SQL> insert into customer values('&cust_name','&city',&street);

Enter value for cust_name: john

Enter value for city: pune

Enter value for street: 1

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('john','pune',1)

1 row created.

SQL> /

Enter value for cust_name: smith

Enter value for city: vizag

Enter value for street: 2


old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('smith','vizag',2)

1 row created.

SQL> /

Enter value for cust_name: robert

Enter value for city: raichur

Enter value for street: 3

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('robert','raichur',3)

1 row created.

SQL> /

Enter value for cust_name: alex

Enter value for city: visaka

Enter value for street: 4

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('alex','visaka',4)


1 row created.

SQL> /

Enter value for cust_name: johnson

Enter value for city: vijayawada

Enter value for street: 5

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('johnson','vijayawada',5)

1 row created.

SQL> /

Enter value for cust_name: jockey

Enter value for city: jarkhand

Enter value for street: 6

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('jockey','jarkhand',6)

1 row created.

SQL> /
Enter value for cust_name: ross

Enter value for city: italy

Enter value for street: 7

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('ross','italy',7)

1 row created.

SQL> /

Enter value for cust_name: ihaka

Enter value for city: nagpur

Enter value for street: 8

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('ihaka','nagpur',8)

1 row created.

SQL> /

Enter value for cust_name: foobar

Enter value for city: nellore

Enter value for street: 9


old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('foobar','nellore',9)

1 row created.

SQL> /

Enter value for cust_name: tommocen

Enter value for city: hyderabad

Enter value for street: 10

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('tommocen','hyderabad',10)

1 row created.

SQL> /

Enter value for cust_name: noah

Enter value for city: pune

Enter value for street: 1

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('noah','pune',1)


1 row created.

SQL> /

Enter value for cust_name: liam

Enter value for city: vizag

Enter value for street: 2

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('liam','vizag',2)

1 row created.

SQL> /

Enter value for cust_name: mason

Enter value for city: raichur

Enter value for street: 3

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('mason','raichur',3)

1 row created.

SQL> /
Enter value for cust_name: jacob

Enter value for city: visaka

Enter value for street: 4

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('jacob ','visaka',4)

1 row created.

SQL> /

Enter value for cust_name: william

Enter value for city: vijayawada

Enter value for street: 5

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('william','vijayawada',5)

1 row created.

SQL> /

Enter value for cust_name: ethan

Enter value for city: jarkhand

Enter value for street: 6


old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('ethan ','jarkhand',6)

1 row created.

SQL> /

Enter value for cust_name: james

Enter value for city: italy

Enter value for street: 7

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('james','italy',7)

1 row created.

SQL> /

Enter value for cust_name: elijah

Enter value for city: nagpur

Enter value for street: 8

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('elijah','nagpur',8)


1 row created.

SQL> /

Enter value for cust_name: michael

Enter value for city: nellore

Enter value for street: 9

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('michael','nellore',9)

1 row created.

SQL> /

Enter value for cust_name: benjamin

Enter value for city: hyderabad

Enter value for street: 10

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('benjamin','hyderabad',10)

1 row created.

SQL> select * from customer;


CUST_NAME CITY STREET

---------- ---------- ----------

john pune 1

smith vizag 2

robert raichur 3

alex visaka 4

johnson vijayawada 5

jockey jarkhand 6

ross italy 7

ihaka nagpur 8

foobar nellore 9

tommocen hyderabad 10

noah pune 1

CUST_NAME CITY STREET

---------- ---------- ----------

liam vizag 2

mason raichur 3

jacob visaka 4

william vijayawada 5
ethan jarkhand 6

james italy 7

elijah nagpur 8

michael nellore 9

benjamin hyderabad 10

20 rows selected.

SQL> create table account(acc_no numeric(12),branch_name varchar(10),balance num

eric(10));

Table created.

SQL> insert into account values(&acc_no,'&branch_name',&balance);

Enter value for acc_no:

Enter value for cust_name: ihaka

Enter value for city: nagpur

Enter value for street: 8

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('ihaka','nagpur',8)


1 row created.

SQL> /

Enter value for cust_name: foobar

Enter value for city: nellore

Enter value for street: 9

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('foobar','nellore',9)

1 row created.

SQL> /

Enter value for cust_name: tommocen

Enter value for city: hyderabad

Enter value for street: 10

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('tommocen','hyderabad',10)

1 row created.

SQL> /
Enter value for cust_name: noah

Enter value for city: pune

Enter value for street: 1

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('noah','pune',1)

1 row created.

SQL> /

Enter value for cust_name: liam

Enter value for city: vizag

Enter value for street: 2

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('liam','vizag',2)

1 row created.

SQL> /

Enter value for cust_name: mason

Enter value for city: raichur

Enter value for street: 3


old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('mason','raichur',3)

1 row created.

SQL> /

Enter value for cust_name: jacob

Enter value for city: visaka

Enter value for street: 4

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('jacob ','visaka',4)

1 row created.

SQL> /

Enter value for cust_name: william

Enter value for city: vijayawada

Enter value for street: 5

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('william','vijayawada',5)


1 row created.

SQL> /

Enter value for cust_name: ethan

Enter value for city: jarkhand

Enter value for street: 6

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('ethan ','jarkhand',6)

1 row created.

SQL> /

Enter value for cust_name: james

Enter value for city: italy

Enter value for street: 7

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('james','italy',7)

1 row created.

SQL> /
Enter value for cust_name: elijah

Enter value for city: nagpur

Enter value for street: 8

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('elijah','nagpur',8)

1 row created.

SQL> /

Enter value for cust_name: michael

Enter value for city: nellore

Enter value for street: 9

old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('michael','nellore',9)

1 row created.

SQL> /

Enter value for cust_name: benjamin

Enter value for city: hyderabad

Enter value for street: 10


old 1: insert into customer values('&cust_name','&city',&street)

new 1: insert into customer values('benjamin','hyderabad',10)

1 row created.

SQL> select * from customer;

CUST_NAME CITY STREET

---------- ---------- ----------

john pune 1

smith vizag 2

robert raichur 3

alex visaka 4

johnson vijayawada 5

jockey jarkhand 6

ross italy 7

ihaka nagpur 8

foobar nellore 9

tommocen hyderabad 10

noah pune 1
CUST_NAME CITY STREET

---------- ---------- ----------

liam vizag 2

mason raichur 3

jacob visaka 4

william vijayawada 5

ethan jarkhand 6

james italy 7

elijah nagpur 8

michael nellore 9

benjamin hyderabad 10

20 rows selected.

SQL> create table account(acc_no numeric(12),branch_name varchar(10),balance num

eric(10));

Table created.

SQL> insert into account values(&acc_no,'&branch_name',&balance);

Enter value for acc_no:


Enter value for branch_name:

Enter value for balance:

old 1: insert into account values(&acc_no,'&branch_name',&balance)

new 1: insert into account values(,'',)

insert into account values(,'',)

ERROR at line 1:

ORA-00936: missing expression

SQL> select * from loan;

LOAN_NO BRANCH_NAM AMOUNT

---------- ---------- ----------

7.6859E+11 pune 50000

4.5649E+11 vizag 25000

4.7938E+11 raichur 70000

7.6598E+11 visaka 75000

4.3291E+11 vijayawada 80000

3.4093E+11 jarkhand 100000

9.8458E+11 italy 15000


9.8542E+11 nagpur 90000

5.6054E+11 nellore 85000

7.6436E+11 hyderabad 200000

10 rows selected.

SQL> insert into account values(&acc_no,'&branch_name',&balance);

Enter value for acc_no: 716789650954

Enter value for branch_name: pune

Enter value for balance: 10000

old 1: insert into account values(&acc_no,'&branch_name',&balance)

new 1: insert into account values(716789650954,'pune',10000)

1 row created.

SQL> /

Enter value for acc_no: 876534679876

Enter value for branch_name: vizag

Enter value for balance: 15000

old 1: insert into account values(&acc_no,'&branch_name',&balance)

new 1: insert into account values(876534679876,'vizag',15000)


1 row created.

SQL> /

Enter value for acc_no: 678564579876

Enter value for branch_name: raichur

Enter value for balance: 20000

old 1: insert into account values(&acc_no,'&branch_name',&balance)

new 1: insert into account values(678564579876,'raichur',20000)

1 row created.

SQL> /

Enter value for acc_no: 876534560987

Enter value for branch_name: visaka

Enter value for balance: 25000

old 1: insert into account values(&acc_no,'&branch_name',&balance)

new 1: insert into account values(876534560987,'visaka',25000)

1 row created.
SQL> /

Enter value for acc_no: 987645673409

Enter value for branch_name: vijayawada

Enter value for balance: 30000

old 1: insert into account values(&acc_no,'&branch_name',&balance)

new 1: insert into account values(987645673409,'vijayawada',30000)

1 row created.

SQL> /

Enter value for acc_no: 872598657890

Enter value for branch_name: jarkhand

Enter value for balance: 35000

old 1: insert into account values(&acc_no,'&branch_name',&balance)

new 1: insert into account values(872598657890,'jarkhand',35000)

1 row created.

SQL> /

Enter value for acc_no: 765694539876

Enter value for branch_name: italy


Enter value for balance: 43000

old 1: insert into account values(&acc_no,'&branch_name',&balance)

new 1: insert into account values(765694539876,'italy',43000)

1 row created.

SQL> /

Enter value for acc_no: 987526789546

Enter value for branch_name: nagpur

Enter value for balance: 28000

old 1: insert into account values(&acc_no,'&branch_name',&balance)

new 1: insert into account values(987526789546,'nagpur',28000)

1 row created.

SQL> /

Enter value for acc_no: 678734560987

Enter value for branch_name: nellore

Enter value for balance: 32000

old 1: insert into account values(&acc_no,'&branch_name',&balance)

new 1: insert into account values(678734560987,'nellore',32000)


1 row created.

SQL> /

Enter value for acc_no: tommocen

Enter value for branch_name: hyderabad

Enter value for balance: 48000

old 1: insert into account values(&acc_no,'&branch_name',&balance)

new 1: insert into account values(tommocen,'hyderabad',48000)

insert into account values(tommocen,'hyderabad',48000)

ERROR at line 1:

ORA-00984: column not allowed here

SQL> /

Enter value for acc_no: 567896435098

Enter value for branch_name: hyderabad

Enter value for balance: 48000

old 1: insert into account values(&acc_no,'&branch_name',&balance)

new 1: insert into account values(567896435098,'hyderabad',48000)


1 row created.

SQL> select * from account;

ACC_NO BRANCH_NAM BALANCE

---------- ---------- ----------

7.1679E+11 pune 10000

8.7653E+11 vizag 15000

6.7856E+11 raichur 20000

8.7653E+11 visaka 25000

9.8765E+11 vijayawada 30000

8.7260E+11 jarkhand 35000

7.6569E+11 italy 43000

9.8753E+11 nagpur 28000

6.7873E+11 nellore 32000

5.6790E+11 hyderabad 48000

10 rows selected.

SQL> create table branch(branch_name varchar(10),branch_city varchar(10),asserts


numeric(10));

Table created.

SQL> insert into branch values('&branch_name','&branch_city',&asserts);

Enter value for branch_name: pune

Enter value for branch_city: pune

Enter value for asserts: 500000

old 1: insert into branch values('&branch_name','&branch_city',&asserts)

new 1: insert into branch values('pune','pune',500000)

1 row created.

SQL> /

Enter value for branch_name: vizag

Enter value for branch_city: vizag

Enter value for asserts: 400000

old 1: insert into branch values('&branch_name','&branch_city',&asserts)

new 1: insert into branch values('vizag','vizag',400000)

1 row created.
SQL> /

Enter value for branch_name: raichur

Enter value for branch_city: raichur

Enter value for asserts: 600000

old 1: insert into branch values('&branch_name','&branch_city',&asserts)

new 1: insert into branch values('raichur','raichur',600000)

1 row created.

SQL> /

Enter value for branch_name: visaka

Enter value for branch_city: visaka

Enter value for asserts: 300000

old 1: insert into branch values('&branch_name','&branch_city',&asserts)

new 1: insert into branch values('visaka','visaka',300000)

1 row created.

SQL> /

Enter value for branch_name: vijayawada


Enter value for branch_city: vijayawada

Enter value for asserts: 750000

old 1: insert into branch values('&branch_name','&branch_city',&asserts)

new 1: insert into branch values('vijayawada','vijayawada',750000)

1 row created.

SQL> /

Enter value for branch_name: jarkhand

Enter value for branch_city: jarkhand

Enter value for asserts: 650000

old 1: insert into branch values('&branch_name','&branch_city',&asserts)

new 1: insert into branch values('jarkhand','jarkhand',650000)

1 row created.

SQL> /

Enter value for branch_name: italy

Enter value for branch_city: italy

Enter value for asserts: 800000

old 1: insert into branch values('&branch_name','&branch_city',&asserts)


new 1: insert into branch values('italy','italy',800000)

1 row created.

SQL> /

Enter value for branch_name: nagpur

Enter value for branch_city: nagpur

Enter value for asserts: 850000

old 1: insert into branch values('&branch_name','&branch_city',&asserts)

new 1: insert into branch values('nagpur','nagpur',850000)

1 row created.

SQL> /

Enter value for branch_name: nellore

Enter value for branch_city: nellore

Enter value for asserts: 950000

old 1: insert into branch values('&branch_name','&branch_city',&asserts)

new 1: insert into branch values('nellore','nellore',950000)

1 row created.
SQL> /

Enter value for branch_name: hyderabad

Enter value for branch_city: hyderabad

Enter value for asserts: 1000000

old 1: insert into branch values('&branch_name','&branch_city',&asserts)

new 1: insert into branch values('hyderabad','hyderabad',1000000)

1 row created.

SQL> select * from branch;

BRANCH_NAM BRANCH_CIT ASSERTS

---------- ---------- ----------

pune pune 500000

vizag vizag 400000

raichur raichur 600000

visaka visaka 300000

vijayawada vijayawada 750000

jarkhand jarkhand 650000

italy italy 800000


nagpur nagpur 850000

nellore nellore 950000

hyderabad hyderabad 1000000

10 rows selected.

SQL> alter table account add constraint pk_account primary key(acc_no);

Table altered.

SQL> alter table loan add constraint pk_loan primary key(loan_no);

Table altered.

SQL> alter table borrower add constraint fk_borrower foreign key(loan_no) refere

nces loan(loan_no);

Table altered.

SQL> alter table branch add constraint pk_branch primary key(branch_name);


Table altered.

SQL> alter table account add constraint fk_account foreign key(branch_name) refe

rences branch(branch_name);

Table altered.

SQL> alter table customer add constraint pk_customer primary key(cust_name);

Table altered.

SQL> alter table depositor add constraint fk_depositor foreign key(cust_name) re

ferences customer(cust_name);

Table altered.
RESULT:Thus the program has been executed successfully…...

Das könnte Ihnen auch gefallen