DBMS Edp

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 59

SQL*Plus: Release 10.2.0.1.

0 - Production on Tue Feb 7 22:21:01 2023

Prg EDP

Copyright (c) 1982, 2005, Oracle. All rights reserved.

SQL> connect system


Enter password:
Connected.

SQL> create table edp(no int,in varchar(15),cop int,quantity int,dop date,warrnty int,oprl
int));

create table edp(no int,in varchar(15),cop int,quantity int,dop date,warrnty int,oprl int))
*
ERROR at line 1:
ORA-00904: : invalid identifier

SQL> create table edp(no int,i_name varchar(15),cop int,quantity int,dop date,warrnty


int,oprl int));
create table edp(no int,i_name varchar(15),cop int,quantity int,dop date,warrnty int,oprl
int))
*
ERROR at line 1:
ORA-00922: missing or invalid option

SQL> create table edp(no int,i_name varchar(15),cop int,quantity int,dop date,warrnty


int,oprl int);

Table created.

SQL> insert into edp values('1','com','30000','9','21-may-07','2','7');


1 row created.

SQL> insert into edp values('2','pri','5000','3','21-may-06','4','2');

1 row created.

SQL> insert into edp values('3','sca','8000','1','29-aug-08','3','1');

1 row created.

SQL> insert into edp values('4','cam','7000','2','13-jun-08','1','2');

1 row created.

SQL> insert into edp values('5','ups','15000','5','21-may-08','1','4');

1 row created.

SQL> select * from edp;

NO I_NAME COP QUANTITY DOP WARRNTY OPRL


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

1 com 30000 9 21-MAY-07 2 7


2 pri 5000 3 21-MAY-06 4 2
3 sca 8000 1 29-AUG-08 3 1
4 cam 7000 2 13-JUN-08 1 2
5 ups 15000 5 21-MAY-08 1 4
SQL> select i_name from edp where dop>31-oct-07;
select i_name from edp where dop>31-oct-07
*

ERROR at line 1:
ORA-00904: "OCT": invalid identifier

SQL> select i_name from edp where dop>31/oct/07;

select i_name from edp where dop>31/oct/07


*
ERROR at line 1:
ORA-00904: "OCT": invalid identifier

SQL> select i_name from edp where dop>'31/oct/07';

I_NAME
---------------

sca
cam
ups

SQL> select i_name,warrnty(warranty+'0.6')"warranty" from edp;

select i_name,warrnty(warranty+'0.6')"warranty" from edp


*
ERROR at line 1:
ORA-00904: "WARRNTY": invalid identifier
SQL> select i_name,quantity(warranty+'0.6')"warranty" from edp;
select i_name,quantity(warranty+'0.6')"warranty" from edp
*

ERROR at line 1:
ORA-00904: "QUANTITY": invalid identifier

SQL> select i_name,quantity,(warranty+'0.6')"warranty" from edp;

select i_name,quantity,(warranty+'0.6')"warranty" from edp


*
ERROR at line 1:
ORA-00904: "WARRANTY": invalid identifier

SQL> select i_name,quantity,(warrnty+'0.6')"warranty" from edp;

I_NAME QUANTITY warranty


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

com 9 2.6
pri 3 4.6
sca 1 3.6
cam 2 1.6
ups 5 1.6

SQL> select i_name,warrnty(warrnty+'0.6')"warranty" from edp;


select i_name,warrnty(warrnty+'0.6')"warranty" from edp
*
ERROR at line 1:
ORA-00904: "WARRNTY": invalid identifier
SQL> select i_name,quantity(warrnty+'0.6')"warranty" from edp;

select i_name,quantity(warrnty+'0.6')"warranty" from edp


*
ERROR at line 1:
ORA-00904: "QUANTITY": invalid identifier

SQL> select i_name,quantity,(warrnty+'0.6')"warranty" from edp;

I_NAME QUANTITY warranty


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

com 9 2.6
pri 3 4.6
sca 1 3.6
cam 2 1.6
ups 5 1.6

SQL> select i_name,dop,trunc(months_between(sys_date,dop)) as months_difference from


edp;
select i_name,dop,trunc(months_between(sys_date,dop)) as months_difference from edp
*
ERROR at line 1:
ORA-00904: "SYS_DATE": invalid identifier

SQL> select i_name,dop,trunc(months_between(sysdate,dop)) as months_difference from


edp;
I_NAME DOP MONTHS_DIFFERENCE
--------------- --------- -----------------
com 21-MAY-07 188

pri 21-MAY-06 200


sca 29-AUG-08 173
cam 13-JUN-08 175
ups 21-MAY-08 176

SQL> select i_name,dop from edp where quantity>3 order by dop asc;

I_NAME DOP
--------------- ---------
com 21-MAY-07

ups 21-MAY-08

SQL> select count(num) as total_items, avg(cop) as average_items from edp where


dop<1/jan/08;
select count(num) as total_items, avg(cop) as average_items from edp where dop<1/jan/08
*
ERROR at line 1:

ORA-00904: "JAN": invalid identifier

SQL> select count(num) as total_items, avg(cop) as average_items from edp where


dop<'1/jan/08';
select count(num) as total_items, avg(cop) as average_items from edp where
dop<'1/jan/08'
*

ERROR at line 1:
ORA-00904: "NUM": invalid identifier
SQL> select count(num) as total_items, avg(cop) as average_items from edp where
dop<'1/jun/08';
select count(num) as total_items, avg(cop) as average_items from edp where
dop<'1/jun/08'

*
ERROR at line 1:
ORA-00904: "NUM": invalid identifier

SQL> select count(num) as total_items, avg(cop) as average_cost from edp where


dop<'1/jun/08';

select count(num) as total_items, avg(cop) as average_cost from edp where dop<'1/jun/08'


*
ERROR at line 1:
ORA-00904: "NUM": invalid identifier

SQL> select count (num) as total_items, avg(cop) as average_cost from edp where
dop<'1/jun/08';
select count (num) as total_items, avg(cop) as average_cost from edp where dop<'1/jun/08'
*
ERROR at line 1:
ORA-00904: "NUM": invalid identifier

SQL> select count ('num') as total_items, avg(cop) as average_cost from edp where
dop<'1/jun/08';

TOTAL_ITEMS AVERAGE_COST
----------- ------------
3 16666.6667

SQL> select min(warranty) as minimum_warranty,max(warranty) as maximum_warranty


from edp;

select min(warranty) as minimum_warranty,max(warranty) as maximum_warranty from


edp
*
ERROR at line 1:
ORA-00904: "WARRANTY": invalid identifier

SQL> select min(warranty) as minimum_warranty max(warranty) as maximum_warranty


from edp;
select min(warranty) as minimum_warranty max(warranty) as maximum_warranty from
edp
*
ERROR at line 1:
ORA-00923: FROM keyword not found where expected

SQL> select min(warranty) as minimum_warranty ,'max'(warranty) as maximum_warranty


from edp;
select min(warranty) as minimum_warranty ,'max'(warranty) as maximum_warranty from
edp
*
ERROR at line 1:
ORA-00923: FROM keyword not found where expected

SQL> select min(warranty) as minimum_warranty max('warranty') as maximum_warranty


from edp;
select min(warranty) as minimum_warranty max('warranty') as maximum_warranty from
edp
*
ERROR at line 1:
ORA-00923: FROM keyword not found where expected

SQL> select min(warranty) as minimum_warranty and max('warranty') as


maximum_warranty from edp;
select min(warranty) as minimum_warranty and max('warranty') as maximum_warranty
from edp
*
ERROR at line 1:

ORA-00923: FROM keyword not found where expected

SQL> select min(warranty) as minimum_warranty ,max('warranty') as maximum_warranty


from edp;
select min(warranty) as minimum_warranty ,max('warranty') as maximum_warranty from
edp
*

ERROR at line 1:
ORA-00904: "WARRANTY": invalid identifier

SQL> select min(warranty) as minimum_warranty max(warranty) as maximum_warranty


from edp;
select min(warranty) as minimum_warranty max(warranty) as maximum_warranty from
edp
*
ERROR at line 1:
ORA-00923: FROM keyword not found where expected
SQL> select min(warranty) as minimum_warranty,max(warranty) as maximum_warranty
from edp;
select min(warranty) as minimum_warranty,max(warranty) as maximum_warranty from
edp

*
ERROR at line 1:
ORA-00904: "WARRANTY": invalid identifier

SQL> select min(warrnty) as minimum_warranty,max(warrnty) as maximum_warranty from


edp;

MINIMUM_WARRANTY MAXIMUM_WARRANTY
---------------- ----------------
1 4

SQL> select to_char(dop,'month','day','year') as purchase date from edp;


select to_char(dop,'month','day','year') as purchase date from edp
*
ERROR at line 1:
ORA-00923: FROM keyword not found where expected

SQL> select to_char(dop,'month','day','year') as purchase_date from edp;


select to_char(dop,'month','day','year') as purchase_date from edp
*

ERROR at line 1:
ORA-00939: too many arguments for function
SQL> select i_name,to_char(dop,'day','month','year') as purchase_date from edp;

select i_name,to_char(dop,'day','month','year') as purchase_date from edp


*
ERROR at line 1:
ORA-00939: too many arguments for function

SQL> select i_name,to_char(dop,'day','month',year) as purchase_date from edp;


select i_name,to_char(dop,'day','month',year) as purchase_date from edp
*
ERROR at line 1:

ORA-00904: "YEAR": invalid identifier

SQL> select i_name,to_char(dop,'day month year') as purchase_date from edp;

I_NAME PURCHASE_DATE
--------------- --------------------------------------------------------------
com monday may two thousand seven
pri sunday may two thousand six
sca friday august two thousand eight

cam friday june two thousand eight


ups wednesday may two thousand eight

SQL> select i_name rount((add_months(warranty,dop),'month')) as round_month,


rount((add_months(warranty,dop),'year')as round_year from edp;
select i_name rount((add_months(warranty,dop),'month')) as round_month,
rount((add_months(warranty,dop),'year')as round_year from edp
*
ERROR at line 1:
ORA-00923: FROM keyword not found where expected

SQL> select i_name,rount((add_months(warranty,dop),'month')) as round_month,


rount((add_months(warranty,dop),'year')as round_year from edp;
select i_name,rount((add_months(warranty,dop),'month')) as round_month,
rount((add_months(warranty,dop),'year')as round_year from edp
*
ERROR at line 1:

ORA-00907: missing right parenthesis

SQL> select i_name,rount((add_months(warrnty,dop),'month')) as round_month,


rount((add_months(warrnty,dop),'year')as round_year from edp;
select i_name,rount((add_months(warrnty,dop),'month')) as round_month,
rount((add_months(warrnty,dop),'year')as round_year from edp
*
ERROR at line 1:

ORA-00907: missing right parenthesis

SQL> select i_name,rount((add_months(warrnty,dop),'month')) as round_month,


round((add_months(warrnty,dop),'year')as round_year from edp;
select i_name,rount((add_months(warrnty,dop),'month')) as round_month,
round((add_months(warrnty,dop),'year')as round_year from edp
*

ERROR at line 1:
ORA-00907: missing right parenthesis
SQL> select i_name,rount((add_months(dop,warrnty),'month')) as round_month,
round((add_months(dop,warranty),'year')as round_year from edp;
select i_name,rount((add_months(dop,warrnty),'month')) as round_month,
round((add_months(dop,warranty),'year')as round_year from edp
*

ERROR at line 1:
ORA-00907: missing right parenthesis

SQL> select i_name,round((add_months(dop,warrnty),'month')) as round_month,


round((add_months(dop,warranty),'year')as round_year from edp;
select i_name,round((add_months(dop,warrnty),'month')) as round_month,
round((add_months(dop,warranty),'year')as round_year from edp
*

ERROR at line 1:
ORA-00907: missing right parenthesis

SQL> select i_name,round((add_months(dop,warrnty)),'month') as round_month,


round((add_months(dop,warranty)),'year')as round_year from edp;

select i_name,round((add_months(dop,warrnty)),'month') as round_month,


round((add_months(dop,warranty)),'year')as round_year from edp

*
ERROR at line 1:
ORA-00904: "WARRANTY": invalid identifier

SQL> select i_name,round((add_months(dop,warrnty)),'month') as round_month,


round((add_months(dop,warrnty)),'year')as round_year from edp;

I_NAME ROUND_MON ROUND_YEA


--------------- --------- ---------
com 01-AUG-07 01-JAN-08
pri 01-OCT-06 01-JAN-07

sca 01-DEC-08 01-JAN-09


cam 01-JUL-08 01-JAN-09
ups 01-JUL-08 01-JAN-08

SQL> select next_day('07/jun/96','sunday')from edp;

NEXT_DAY(
---------
09-JUN-96
09-JUN-96

09-JUN-96
09-JUN-96
09-JUN-96

SQL> select next_day('07/jun/96','sunday')as next_sunday from edp;

NEXT_SUND
---------
09-JUN-96
09-JUN-96

09-JUN-96
09-JUN-96
09-JUN-96

SQL> select i_name from edp where(add_months(dop,warranty)-sysdate>0;


select i_name from edp where(add_months(dop,warranty)-sysdate>0
*
ERROR at line 1:
ORA-00907: missing right parenthesis

SQL> select next_day('07/jun/96','sunday')as next_sunday from edp;-


> select next_day('07/jun/96','sunday')as next_sunday from edp;-
>

select next_day('07/jun/96','sunday')as next_sunday from edp; select


next_day('07/jun/96','sunday')as next_sunday from edp

*
ERROR at line 1:
ORA-00911: invalid character

SQL> select i_name from edp where(add_months(dop,warranty)-sys_date>0;


select i_name from edp where(add_months(dop,warranty)-sys_date>0
*
ERROR at line 1:
ORA-00907: missing right parenthesis

SQL> select i_name from edp where(add_months(dop,warranty)-sys_date>'0';


select i_name from edp where(add_months(dop,warranty)-sys_date>'0'
*

ERROR at line 1:
ORA-00907: missing right parenthesis

SQL> select i_name from edp where(add_months(dop,warrnty)-sys_date>0;


select i_name from edp where(add_months(dop,warrnty)-sys_date>0
*
ERROR at line 1:

ORA-00907: missing right parenthesis

SQL> select i_name from edp where(add_months(dop,warrnty)-sysdate>0;


select i_name from edp where(add_months(dop,warrnty)-sysdate>0

*
ERROR at line 1:
ORA-00907: missing right parenthesis

SQL> select count ('num') as total_items, avg(dop) as average_cost from edp where
dop<'1/jun/08';

select count ('num') as total_items, avg(dop) as average_cost from edp where


dop<'1/jun/08'
*
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected NUMBER got DATE

SQL> select count ('num') as total_items, avg(cop) as average_cost from edp where
dop<'1/jun/08';

TOTAL_ITEMS AVERAGE_COST
----------- ------------
3 16666.6667

SQL> select i_name from edp where(add_months(dop,warranty))-sysdate>0;


select i_name from edp where(add_months(dop,warranty))-sysdate>0
*
ERROR at line 1:

ORA-00904: "WARRANTY": invalid identifier

SQL> select i_name from edp where(add_months(dop,warrnty))-sysdate>0;

no rows selected

SQL> update edp set dop='05/dec/22'where i_name='hub';

0 rows updated.

SQL> update edp set dop='05/dec/22'where i_name='ups';

1 row updated.

SQL> select i_name from edp where(add_months(dop,warrnty))-sysdate>0;

no rows selected

SQL> Z

Employee
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Feb 23 09:14:54 2023

Copyright (c) 1982, 2005, Oracle. All rights reserved.

SQL> connect system


Enter password:
Connected.
SQL> create table emp(emp_id int primary key,fn varchar(10),ln varchar(10),hire_date
date,address varchar(15),city varchar(15));

Table created.

SQL> insert int emp values('1001','george','smith','11/may/06','83 f s','paries');


insert int emp values('1001','george','smith','11/may/06','83 f s','paries')
*

ERROR at line 1:
ORA-00925: missing INTO keyword

SQL> insert into emp values('1001','george','smith','11/may/06','83 f s','paries');

1 row created.

SQL> insert into emp values('1002','mary','jones','25/feb/08','842 v a','losantiville');

1 row created.

SQL> insert into emp values('1012','sam','tones','12/sep/05','33 e s','paries');

1 row created.
SQL> select*from emp;

EMP_ID FN LN HIRE_DATE ADDRESS CITY


---------- ---------- ---------- --------- --------------- ---------------
1001 george smith 11-MAY-06 83 f s paries
1002 mary jones 25-FEB-08 842 v a losantiville
1012 sam tones 12-SEP-05 33 e s paries

SQL> select fn,ln,address,city where city='paries';


select fn,ln,address,city where city='paries'
*
ERROR at line 1:

ORA-00923: FROM keyword not found where expected

SQL> select fn,ln,address,city from emp where city='paries';

FN LN ADDRESS CITY
---------- ---------- --------------- ---------------
george smith 83 f s paries
sam tones 33 e s paries

SQL> select * from emp order by fn indesc;


select * from emp order by fn indesc
*
ERROR at line 1:
ORA-00933: SQL command not properly ended
SQL> select * from emp order by fn in desc;
select * from emp order by fn in desc

*
ERROR at line 1:
ORA-00933: SQL command not properly ended

SQL> select * from emp order by fn desc;

EMP_ID FN LN HIRE_DATE ADDRESS CITY


---------- ---------- ---------- --------- --------------- ---------------
1012 sam tones 12-SEP-05 33 e s paries

1002 mary jones 25-FEB-08 842 v a losantiville


1001 george smith 11-MAY-06 83 f s paries

SQL> create table slr(emp_id int references emp(emp_id),slr varchar(10),benifits


varchar(10),dsg varchar(15));

Table created.

SQL> insert into emp values('1001','10000','3000','manager');


insert into emp values('1001','10000','3000','manager')
*
ERROR at line 1:

ORA-00947: not enough values

SQL> insert into slr values('1001','10000','3000','manager');


1 row created.

SQL> insert into slr values('1002','8000','1200','salesman');

1 row created.

SQL> insert into slr values('1012','20000','5000','director');

1 row created.

SQL> select * from slr;

EMP_ID SLR BENIFITS DSG

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


1001 10000 3000 manager
1002 8000 1200 salesman
1012 20000 5000 director

SQL> select fn,slr from emp e,slr s where e.emp=slr.s and dsn='salesman';
select fn,slr from emp e,slr s where e.emp=slr.s and dsn='salesman'
*
ERROR at line 1:
ORA-00904: "DSN": invalid identifier

SQL> select fn,slr from emp e,slr s where e.emp=slr.s and dsg='salesman';
select fn,slr from emp e,slr s where e.emp=slr.s and dsg='salesman'
*
ERROR at line 1:
ORA-00904: "SLR"."S": invalid identifier

SQL> select fn,slr from emp e,slr s where e.emp=s.slr and dsg='salesman';
select fn,slr from emp e,slr s where e.emp=s.slr and dsg='salesman'
*
ERROR at line 1:
ORA-00904: "E"."EMP": invalid identifier

SQL> select fn,slr from emp e,slr s where e.emp_id=s.emp_id and dsg='salesman';

FN SLR

---------- ----------
mary 8000

SQL> select fn,ln,(slr+benifits)as total_salary from emp e,slr s where e.emp_id=s.emp_id


2

SQL> select fn,ln,(slr+benifits)as total_salary from emp e,slr s where e.emp_id=s.emp_id;

FN LN TOTAL_SALARY
---------- ---------- ------------
george smith 13000

mary jones 9200


sam tones 25000

SQL> select fn,ln(sys_date-hire_date)/365 as experience from edp where(sys_date-


hire_date)/365>1;
select fn,ln(sys_date-hire_date)/365 as experience from edp where(sys_date-
hire_date)/365>1
*
ERROR at line 1:
ORA-00904: "HIRE_DATE": invalid identifier

SQL> select fn,ln(sysdate-hire_date)/365 as experience from edp where(sysdate-


hire_date)/365>1;
select fn,ln(sysdate-hire_date)/365 as experience from edp where(sysdate-
hire_date)/365>1
*
ERROR at line 1:

ORA-00904: "HIRE_DATE": invalid identifier

SQL> select fn,ln(sysdate-hire_date)/365 as experience from emp where(sysdate-


hire_date)/365>1;

FN EXPERIENCE

---------- ----------
george .023894086
mary .023584619
sam .023999694

SQL> select count(distint_designation) from slr;


select count(distint_designation) from slr
*
ERROR at line 1:
ORA-00904: "DISTINT_DESIGNATION": invalid identifier
SQL> select count(distinct_designation) from slr;
select count(distinct_designation) from slr
*

ERROR at line 1:
ORA-00904: "DISTINCT_DESIGNATION": invalid identifier

SQL> select count(distinct designation) from slr;

select count(distinct designation) from slr


*
ERROR at line 1:
ORA-00904: "DESIGNATION": invalid identifier

SQL> select count(distinct desingation) from slr;


select count(distinct desingation) from slr
*
ERROR at line 1:

ORA-00904: "DESINGATION": invalid identifier

SQL> select count(distinct designation) from slr;


select count(distinct designation) from slr

*
ERROR at line 1:
ORA-00904: "DESIGNATION": invalid identifier

SQL> select count(distinct designation) from slr;


select count(distinct designation) from slr
*
ERROR at line 1:

ORA-00904: "DESIGNATION": invalid identifier

SQL> select count(distinct dsg) from slr;

COUNT(DISTINCTDSG)
------------------
3

SQL> select fn from emp lenth(fn)=6;

select fn from emp lenth(fn)=6


*
ERROR at line 1:
ORA-00933: SQL command not properly ended

SQL> select fn from emp length(fn)=6;


select fn from emp length(fn)=6
*
ERROR at line 1:

ORA-00933: SQL command not properly ended

SQL> select fn from emp length('fn')=6;


select fn from emp length('fn')=6
*
ERROR at line 1:
ORA-00933: SQL command not properly ended

SQL> select fn from emp where length('fn')=6;

no rows selected

SQL> select fn from emp where length('fn')=3;

no rows selected

SQL> select fn from emp where length(fn)=3;

FN
----------
sam

SQL> alter table emp add ph_no varchar(10);

Table altered.

SQL> select * from emp;

EMP_ID FN LN HIRE_DATE ADDRESS CITY


---------- ---------- ---------- --------- --------------- ---------------
PH_NO
----------
1001 george smith 11-MAY-06 83 f s paries
1002 mary jones 25-FEB-08 842 v a losantiville

1012 sam tones 12-SEP-05 33 e s paries

SQL> update emp set ph_no='1234'where emp_id='1001';

1 row updated.

SQL> update emp set ph_no='1235'where emp_id='1002';

1 row updated.

SQL> update emp set ph_no='1236'where emp_id='1012';

1 row updated.

SQL> select * from emp;

EMP_ID FN LN HIRE_DATE ADDRESS CITY


---------- ---------- ---------- --------- --------------- ---------------
PH_NO
----------
1001 george smith 11-MAY-06 83 f s paries
1234
1002 mary jones 25-FEB-08 842 v a losantiville
1235

1012 sam tones 12-SEP-05 33 e s paries


1236

SQL> select fn,ln from emp where hire_date<'15/jan/08' and hire_date>'16/jan/07';

no rows selected

SQL> select fn,ln,slr,benifits,(slr*0.5)as hra,(slr*0.3)as da,(slr*0.12)as pf,(slr*0.5)+(slr*0.3)-


(slr*0.12)+slr+benifits as gross from emp e,slr s where e.emp_id=s.emp_id ;

FN LN SLR BENIFITS HRA DA PF

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


GROSS
----------
george smith 10000 3000 5000 3000 1200
19800

mary jones 8000 1200 4000 2400 960


14640

sam tones 20000 5000 10000 6000 2400


38600

SQL>

library

SQL*Plus: Release 10.2.0.1.0 - Production on Thu Feb 23 10:00:05 2023

Copyright (c) 1982, 2005, Oracle. All rights reserved.

SQL> connect system


Enter password:
Connected.
SQL> create table books(book_id varchar(10)primary key,bn varchar(10),an varchar(20),pbl
varchar(10),price int,type char,quantity int);

Table created.

SQL> insert into books values('c0001','tkai','lata','epp','355','novel','5');


insert into books values('c0001','tkai','lata','epp','355','novel','5')

*
ERROR at line 1:
ORA-12899: value too large for column "SYSTEM"."BOOKS"."TYPE" (actual: 5,
maximum: 1)
SQL> create table books1(book_id varchar(10)primary key,bn varchar(10),an varchar(20),pbl
varchar(10),price int,type varchar(10),quantity int);

Table created.

SQL> insert into books values('c0001','tkai','lata','epp','355','novel','5');


insert into books values('c0001','tkai','lata','epp','355','novel','5')
*

ERROR at line 1:
ORA-12899: value too large for column "SYSTEM"."BOOKS"."TYPE" (actual: 5,
maximum: 1)

SQL> create table books(book_id varchar(10)primary key,bn varchar(10),an varchar(20),pbl


varchar(10),price varchar(10),type varchar(10),quantity varchar(10));
create table books(book_id varchar(10)primary key,bn varchar(10),an varchar(20),pbl
varchar(10),price varchar(10),type varchar(10),quantity varchar(10))
*
ERROR at line 1:
ORA-00955: name is already used by an existing object

SQL> create table books2(book_id varchar(10)primary key,bn varchar(10),an varchar(20),pbl


varchar(10),price varchar(10),type varchar(10),quantity varchar(10));

Table created.

SQL> insert into books3 values('c0001','tkai','lata','epp','355','novel','5');

insert into books3 values('c0001','tkai','lata','epp','355','novel','5')


*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> insert into books2 values('c0001','tkai','lata','epp','355','novel','5');

1 row created.

SQL> insert into books2 values('f0001','tt','wh','firstpubl','650','fiction','20');

1 row created.

SQL> insert into books2 values('t0001','mfc','bb','erp','350','text','10');

1 row created.

SQL> select*from books;

no rows selected

SQL> select*from books2;

BOOK_ID BN AN PBL PRICE TYPE


---------- ---------- -------------------- ---------- ---------- ----------
QUANTITY
----------
c0001 tkai lata epp 355 novel
5
f0001 tt wh firstpubl 650 fiction
20

t0001 mfc bb erp 350 text


10

SQL> create table issued(book_id varchar(10)references books(book_id),qi int);

Table created.

SQL> insert into issued values('t0001','4');

insert into issued values('t0001','4')


*
ERROR at line 1:
ORA-02291: integrity constraint (SYSTEM.SYS_C004029) violated - parent key not
found

SQL> create table issued(book_id varchar(10)references books(book_id),qi varchar(10));


create table issued(book_id varchar(10)references books(book_id),qi varchar(10))
*

ERROR at line 1:
ORA-00955: name is already used by an existing object

SQL> create table issued1(book_id varchar(10)references books(book_id),qi varchar(10));


Table created.

SQL> insert into issued1 values('t0001','4');

insert into issued1 values('t0001','4')


*
ERROR at line 1:
ORA-02291: integrity constraint (SYSTEM.SYS_C004030) violated - parent key not
found

SQL> create table issued1(book_id varchar(10)references books2(book_id),qi varchar(10));


create table issued1(book_id varchar(10)references books2(book_id),qi varchar(10))
*

ERROR at line 1:
ORA-00955: name is already used by an existing object

SQL> create table issued2(book_id varchar(10)references books2(book_id),qi varchar(10));

Table created.

SQL> insert into issued2 values('t0001','4');

1 row created.

SQL> insert into issued2 values('c0001','5');

1 row created.
SQL> insert into issued2 values('f0001','2');

1 row created.

SQL> select*from issued2;

BOOK_ID QI
---------- ----------

t0001 4
c0001 5
f0001 2

SQL> select bn,an,price from books where pbl='firstpubl';

no rows selected

SQL> select bn,an,price from books2 where pbl='firstpubl';

BN AN PRICE
---------- -------------------- ----------
tt wh 650

SQL> select book_id,bn,pbl from books2 where quantity>'8' and price<'500';

no rows selected

SQL> select book_id,bn,pbl from books2 where quantity>4 and price<500;

BOOK_ID BN PBL
---------- ---------- ----------
c0001 tkai epp
t0001 mfc erp

SQL> select book_id,bn,an, from books2 where pbl!='erp'and price>300 and price<700;
select book_id,bn,an, from books2 where pbl!='erp'and price>300 and price<700
*
ERROR at line 1:

ORA-00936: missing expression

SQL> select book_id,bn,an from books2 where pbl!='erp'and price>300 and price<700;

BOOK_ID BN AN
---------- ---------- --------------------
c0001 tkai lata
f0001 tt wh

SQL> select book_id,bn,pbl,price,quantity (quantity*0.04) as total from book2;


select book_id,bn,pbl,price,quantity (quantity*0.04) as total from book2
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> select book_id,bn,pbl,price,quantity (0.04*price) as vat,price+(0.04*price)as total from


book2;
select book_id,bn,pbl,price,quantity (0.04*price) as vat,price+(0.04*price)as total from
book2
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> select book_id,bn,pbl,price,quantity (0.04*price) as vat,price+(0.04*price)as total from


books2;
select book_id,bn,pbl,price,quantity (0.04*price) as vat,price+(0.04*price)as total from
books2
*
ERROR at line 1:
ORA-00904: "QUANTITY": invalid identifier

SQL> select book_id,bn,pbl,price,quantity,(0.04*price) as vat,price+(0.04*price)as total from


books2;

BOOK_ID BN PBL PRICE QUANTITY VAT TOTAL


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

c0001 tkai epp 355 5 14.2 369.2


f0001 tt firstpubl 650 20 26 676
t0001 mfc erp 350 10 14 364

SQL> select*from books2 where book

2 select*from books2 where book


3
SQL> select*from books2 where book_id in('c0001','f0001','t0001');

BOOK_ID BN AN PBL PRICE TYPE

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


QUANTITY
----------
c0001 tkai lata epp 355 novel
5

f0001 tt wh firstpubl 650 fiction


20

t0001 mfc bb erp 350 text

10

SQL> select*from books2 where book_id in('c0001','f0001');

BOOK_ID BN AN PBL PRICE TYPE


---------- ---------- -------------------- ---------- ---------- ----------
QUANTITY
----------
c0001 tkai lata epp 355 novel

f0001 tt wh firstpubl 650 fiction


20

SQL> select * from books2 where an like('l%');

BOOK_ID BN AN PBL PRICE TYPE


---------- ---------- -------------------- ---------- ---------- ----------
QUANTITY
----------
c0001 tkai lata epp 355 novel
5

SQL> select book_id,bn, where an like('l%');


select book_id,bn, where an like('l%')
*

ERROR at line 1:
ORA-00936: missing expression

SQL> select book_id,bn where an like('l%');

select book_id,bn where an like('l%')


*
ERROR at line 1:
ORA-00923: FROM keyword not found where expected

SQL> select book_id,bn from books2 where an like('l%');

BOOK_ID BN
---------- ----------

c0001 tkai

SQL> select * from books2 where an like('l%');

BOOK_ID BN AN PBL PRICE TYPE


---------- ---------- -------------------- ---------- ---------- ----------
QUANTITY
----------
c0001 tkai lata epp 355 novel

SQL> select * from books2 where an like('w%') and an like('%h');

BOOK_ID BN AN PBL PRICE TYPE


---------- ---------- -------------------- ---------- ---------- ----------
QUANTITY
----------
f0001 tt wh firstpubl 650 fiction

20

SQL> select books_id,bn,an,issued.qi from books2,issued where


books2.book_id=issued.book_id;
select books_id,bn,an,issued.qi from books2,issued where books2.book_id=issued.book_id
*

ERROR at line 1:
ORA-00904: "BOOKS_ID": invalid identifier

SQL> select book2.book_id,bn,an,issued.qi from books2,issued where


books2.book_id=issued.book_id;

select book2.book_id,bn,an,issued.qi from books2,issued where


books2.book_id=issued.book_id

*
ERROR at line 1:
ORA-00904: "BOOK2"."BOOK_ID": invalid identifier

SQL> select book_id,bn,an,issued.qi from books2,issued where


books2.book_id=issued.book_id;

select book_id,bn,an,issued.qi from books2,issued where books2.book_id=issued.book_id


*
ERROR at line 1:
ORA-00918: column ambiguously defined

SQL> select book_id,bn,an,qi from books2.b,issued.i where b.book_id=i.book_id;


select book_id,bn,an,qi from books2.b,issued.i where b.book_id=i.book_id
*
ERROR at line 1:

ORA-00942: table or view does not exist

SQL> select book_id,bn,an,qi from books2.b,issued2.i where b.book_id=i.book_id;


select book_id,bn,an,qi from books2.b,issued2.i where b.book_id=i.book_id

*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> select book_id,bn,an,qi from books2.b,issued2.i where b.book_id=i.book_id;


select book_id,bn,an,qi from books2.b,issued2.i where b.book_id=i.book_id
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> select book_id,bn,an,qi,from books2.b,issued2.i where b.book_id=i.book_id;

select book_id,bn,an,qi,from books2.b,issued2.i where b.book_id=i.book_id


*
ERROR at line 1:
ORA-00936: missing expression

SQL> select book_id,bn,an,qi from books2.b,issued2.i where b.book_id=i.book_id;


select book_id,bn,an,qi from books2.b,issued2.i where b.book_id=i.book_id
*
ERROR at line 1:

ORA-00942: table or view does not exist

SQL> select book_id,bn,an,qi from books2.b,issued2.is where b.book_id=is.book_id;


select book_id,bn,an,qi from books2.b,issued2.is where b.book_id=is.book_id

*
ERROR at line 1:
ORA-00903: invalid table name

SQL> select book_id,bn,an,qi from books2.b,is.issued2 where b.book_id=is.book_id;


select book_id,bn,an,qi from books2.b,is.issued2 where b.book_id=is.book_id
*
ERROR at line 1:
ORA-00903: invalid table name
SQL> select book2.book_id,bn,an,issued2.qi from books2,issued2 where
books2.book_id=issued.book_id;
select book2.book_id,bn,an,issued2.qi from books2,issued2 where
books2.book_id=issued.book_id
*

ERROR at line 1:
ORA-00904: "ISSUED"."BOOK_ID": invalid identifier

SQL> select book2.book_id,bn,an,issued2.qi from books2,issued2 where


books2.book_id=issued.book_id;
select book2.book_id,bn,an,issued2.qi from books2,issued2 where
books2.book_id=issued.book_id
*

ERROR at line 1:
ORA-00904: "ISSUED"."BOOK_ID": invalid identifier

SQL> select book2.book_id,bn,an,issued2.qi from books2,issued2 where


books2.book_id=issued2.book_id;

select book2.book_id,bn,an,issued2.qi from books2,issued2 where


books2.book_id=issued2.book_id

*
ERROR at line 1:
ORA-00904: "BOOK2"."BOOK_ID": invalid identifier

SQL> select books2.book_id,bn,an,issued2.qi from books2,issued2 where


books2.book_id=issued2.book_id;

BOOK_ID BN AN QI
---------- ---------- -------------------- ----------
t0001 mfc bb 4
c0001 tkai lata 5

f0001 tt wh 2

SQL> select book_id,bn,an,qi from b.books2,is.issued2 where b.book_id=is.book_id;


select book_id,bn,an,qi from b.books2,is.issued2 where b.book_id=is.book_id
*

ERROR at line 1:
ORA-00903: invalid table name

SQL> select book_id,bn,an,qi from b.books2,es.issued2 where b.book_id=es.book_id;

select book_id,bn,an,qi from b.books2,es.issued2 where b.book_id=es.book_id


*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> select book_id,bn,an,qi from books2 b,issued2 es where b.book_id=es.book_id;


select book_id,bn,an,qi from books2 b,issued2 es where b.book_id=es.book_id
*
ERROR at line 1:

ORA-00918: column ambiguously defined

SQL> select bn,an,qi from books2 b,issued2 es where b.book_id=es.book_id;

BN AN QI
---------- -------------------- ----------
mfc bb 4
tkai lata 5

tt wh 2

SQL> select book2.book_id,bn,an,issued2.qi from book2,issued2 where


book2.book_id=issued2.book_id;
select book2.book_id,bn,an,issued2.qi from book2,issued2 where
book2.book_id=issued2.book_id
*
ERROR at line 1:

ORA-00942: table or view does not exist

SQL> select books2.book_id,bn,an,issued2.qi from books2,issued2 where


books2.book_id=issued2.book_id;

BOOK_ID BN AN QI

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


t0001 mfc bb 4
c0001 tkai lata 5
f0001 tt wh 2

SQL> select bn,an,price, order by bn asc;


select bn,an,price, order by bn asc
*
ERROR at line 1:
ORA-00936: missing expression
SQL> select bn,an,price,from books2 where order by bn asc;
select bn,an,price,from books2 where order by bn asc
*

ERROR at line 1:
ORA-00936: missing expression

SQL> select bn,an,price from books2 where order by bn asc;

select bn,an,price from books2 where order by bn asc


*
ERROR at line 1:
ORA-00936: missing expression

SQL> select bn,an,price from books2 order by bn asc;

BN AN PRICE
---------- -------------------- ----------

mfc bb 350
tkai lata 355
tt wh 650

SQL>books

View
dropped.

SQL> create table td(train_no varchar(10)primary key,tn varchar(15),sp varchar(10),dst


varchar(15));

Table created.

SQL> insert into td values('rjd16','raj_ex','banglore','mumbai');

1 row created.

SQL> insert into td values('ude04','udy_ex','chennai','hyderabad');

1 row created.

SQL> insert into td values('kke55','krn_ex','banglore','chennai');

1 row created.

SQL> drop table avl;

Table dropped.

SQL> create table avl(train_no varchar(10) references td(train_no),class varchar(15),sp


varchar(10),dst varchar(10),nos varchar(10));

Table created.

SQL> insert into avl values('rjd16','sc','banglore','mumbai','15');


1 row created.

SQL> insert into avl values('ude04','fc','chennai','hyderabad','22');

1 row created.

SQL> insert into avl values('kke55','fc ac','banglore','chennai','15');

1 row created.

SQL> create view sleeper as select train_no,sp,dst from avl where class='sc';
create view sleeper as select train_no,sp,dst from avl where class='sc'
*

ERROR at line 1:
ORA-00955: name is already used by an existing object

SQL> drop table sleeper;

drop table sleeper


*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> drop view sleeper;

View dropped.

SQL> create view sleeper as select train_no,sp,dst from avl where class='sc';
View created.

SQL> insert into sleeper values('mn3','hassan','banglore');


insert into sleeper values('mn3','hassan','banglore')
*
ERROR at line 1:
ORA-02291: integrity constraint (SYSTEM.SYS_C004033) violated - parent key not

found

SQL> insert into sleeper values('mn3','m exp','hassan','banglore');


insert into sleeper values('mn3','m exp','hassan','banglore')

*
ERROR at line 1:
ORA-00913: too many values

SQL>
SQL> insert into td values('mn3','m exp','hassan','banglore');

1 row created.

SQL> select * from td;

TRAIN_NO TN SP DST
---------- --------------- ---------- ---------------
rjd16 raj_ex banglore mumbai
ude04 udy_ex chennai hyderabad
kke55 krn_ex banglore chennai
mn3 m exp hassan banglore

SQL> select * from sleeper;

TRAIN_NO SP DST
---------- ---------- ----------
rjd16 banglore mumbai

SQL> update avl set class='sleeper' where tn='mn3';


update avl set class='sleeper' where tn='mn3'
*
ERROR at line 1:

ORA-00904: "TN": invalid identifier

SQL> update avl set class='sleeper' where train_no='mn3';

0 rows updated.

SQL> insert into sleeper values('mn3','hassan,'banglore');


ERROR:
ORA-01756: quoted string not properly terminated

SQL> insert into sleeper values('mn3','hassan','banglore');

1 row created.
SQL> select * from sleeper;

TRAIN_NO SP DST

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


rjd16 banglore mumbai

SQL> update avl set class='sleeper' where train_no='mn3';

1 row updated.

SQL> select * from sleeper;

TRAIN_NO SP DST

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


rjd16 banglore mumbai

SQL> update avl set dst='mng' where train_no='rjd16';

1 row updated.

SQL> select * from sleeper;

TRAIN_NO SP DST

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


rjd16 banglore mng

SQL> select * from avl;

TRAIN_NO CLASS SP DST NOS


---------- --------------- ---------- ---------- ----------
rjd16 sc banglore mng 15
ude04 fc chennai hyderabad 22

kke55 fc ac banglore chennai 15


mn3 sleeper hassan banglore

SQL> update avl set class='sc' where train_no='mn3';

1 row updated.

SQL> select * from sleeper;

TRAIN_NO SP DST

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


rjd16 banglore mng
mn3 hassan banglore

SQL> insert into td values('kkl','n exp','hsn','bang');

1 row created.

SQL> select * from td;

TRAIN_NO TN SP DST
---------- --------------- ---------- ---------------
rjd16 raj_ex banglore mumbai
ude04 udy_ex chennai hyderabad
kke55 krn_ex banglore chennai
mn3 m exp hassan banglore
kkl n exp hsn bang

SQL> insert into td values('kkl','hsn','bang');

insert into td values('kkl','hsn','bang')


*
ERROR at line 1:
ORA-00947: not enough values

SQL> insert into sleeper values('kkl','hsn','bang');

1 row created.

SQL> update avl set class='sc' where train_no='kkl';

1 row updated.

SQL> select * from sleeper;

TRAIN_NO SP DST
---------- ---------- ----------
rjd16 banglore mng
mn3 hassan banglore

kkl hsn bang

SQL> insert into td values('mn4','k exp','hass','lore');

1 row created.
SQL> insert into sleeper values('mn4','hass','lore');

1 row created.

SQL> select * from sleeper;

TRAIN_NO SP DST
---------- ---------- ----------

rjd16 banglore mng


mn3 hassan banglore
kkl hsn bang

SQL> update avl set class='sc' where train_no='mn4';

1 row updated.

SQL> select * from sleeper;

TRAIN_NO SP DST
---------- ---------- ----------
rjd16 banglore mng
mn3 hassan banglore
kkl hsn bang

mn4 hass lore

SQL> create view details as select td.train_no,td.tn,avl.class from td inner join avl where
avl.train_no=td.train_no;
create view details as select td.train_no,td.tn,avl.class from td inner join avl where
avl.train_no=td.train_no
*
ERROR at line 1:
ORA-00905: missing keyword

SQL> create view details as select td.train_no,td.tn,avl.class from td inner join avl where
avl.train_no=td.train_no;
create view details as select td.train_no,td.tn,avl.class from td inner join avl where
avl.train_no=td.train_no
*
ERROR at line 1:
ORA-00905: missing keyword

SQL> select * from td;

TRAIN_NO TN SP DST

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


rjd16 raj_ex banglore mumbai
ude04 udy_ex chennai hyderabad
kke55 krn_ex banglore chennai
mn3 m exp hassan banglore

kkl n exp hsn bang


mn4 k exp hass lore

6 rows selected.

SQL> create view kew as select td.train_no,td.tn,avl.class from td inner join avl where
avl.train_no=td.train_no;

create view kew as select td.train_no,td.tn,avl.class from td inner join avl where
avl.train_no=td.train_no

*
ERROR at line 1:
ORA-00905: missing keyword

SQL> create view details as select td.train_no,td.tn,avl.class from td inner join avl where
avl.train_no=td.train_no;
create view details as select td.train_no,td.tn,avl.class from td inner join avl where
avl.train_no=td.train_no
*
ERROR at line 1:
ORA-00905: missing keyword

SQL> select * from avl;

TRAIN_NO CLASS SP DST NOS

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


rjd16 sc banglore mng 15
ude04 fc chennai hyderabad 22
kke55 fc ac banglore chennai 15
mn3 sc hassan banglore

kkl sc hsn bang


mn4 sc hass lore

6 rows selected.

SQL> create view details as select td.train_no,td.tn,avl.class from td,avl where


avl.train_no=td.train_no;

View created.
SQL> select * from details;

TRAIN_NO TN CLASS
---------- --------------- ---------------
rjd16 raj_ex sc
ude04 udy_ex fc
kke55 krn_ex fc ac

mn3 m exp sc
kkl n exp sc
mn4 k exp sc

6 rows selected.

SQL> create view total_seats as select train_no,sp,nos from avl;

View created.

SQL> select sp,count(nos)from total_seats group by sp;

SP COUNT(NOS)
---------- ----------
hass 0

hsn 0
chennai 1
banglore 2
hassan 0

SQL> insert into total_seats values('rjd17','bnglore','15');


insert into total_seats values('rjd17','bnglore','15')
*
ERROR at line 1:

ORA-02291: integrity constraint (SYSTEM.SYS_C004033) violated - parent key not


found

SQL> insert into td values('klm2','s exp',bnglore','mysore');

ERROR:
ORA-01756: quoted string not properly terminated

SQL> insert into td values('klm2','s exp','bnglore','mysore');

1 row created.

SQL> insert into total_seats values('rjd17','bnglore','15');


insert into total_seats values('rjd17','bnglore','15')

*
ERROR at line 1:
ORA-02291: integrity constraint (SYSTEM.SYS_C004033) violated - parent key not
found

SQL> insert into total_seats values('klm2','bnglore','mysore');

1 row created.

SQL> select * from total_seats;


TRAIN_NO SP NOS
---------- ---------- ----------

rjd16 banglore 15
ude04 chennai 22
kke55 banglore 15
mn3 hassan
kkl hsn

mn4 hass
klm2 bnglore mysore

7 rows selected.

SQL> update total_seats set sp='hubli' where train_no='klm2';

1 row updated.

SQL> select * from total_seats;

TRAIN_NO SP NOS
---------- ---------- ----------
rjd16 banglore 15
ude04 chennai 22

kke55 banglore 15
mn3 hassan
kkl hsn
mn4 hass
klm2 hubli mysore
7 rows selected.

SQL> delete from total_seats where train_no='klm2';

1 row deleted.

SQL> select * from total_seats;

TRAIN_NO SP NOS
---------- ---------- ----------
rjd16 banglore 15
ude04 chennai 22
kke55 banglore 15

mn3 hassan
kkl hsn
mn4 hass

6 rows selected.

SQL> rename sleeper to class


2
SQL>
SQL> rename sleeper to class;

Table renamed.

SQL>

You might also like