Sunteți pe pagina 1din 20

SQL*Plus: Release 10.2.0.1.

0 - Production on Tue Aug 6 15:55:39 2019

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

ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> create table Pdepartment(dept_name varchar(10),building varchar(10),budget


long)
2
SQL> create table Pdepartment(dept_name varchar(10),building varchar(10),budget
long);

Table created.

SQL> insert into Pdepartment values('Biology','Watson',90000);

1 row created.

SQL> insert into Pdepartment values('Comp.Sci','Taylor',100000);

1 row created.

SQL> insert into Pdepartment values('Elec.Eng.','Taylor',85000);

1 row created.

SQL> insert into Pdepartment values('Finance','Painter',120000);

1 row created.

SQL> insert into Pdepartment values(History','Painter',50000);


ERROR:
ORA-01756: quoted string not properly terminated

SQL> insert into Pdepartment values('History','Painter',50000);

1 row created.

SQL> insert into Pdepartment values('Music','Packard',80000);

1 row created.

SQL> insert into Pdepartment values('Physics',Watson',70000);


ERROR:
ORA-01756: quoted string not properly terminated

SQL> insert into Pdepartment values('Physics','Watson',70000);

1 row created.
SQL> select dept_name from Pdepartment
2
SQL> select dept_name from Pdepartment;

DEPT_NAME
----------
Biology
Comp.Sci
Elec.Eng.
Finance
History
Music
Physics

7 rows selected.

SQL> alter table Pdepartment modify(primary key(dept_name));

Table altered.

SQL> commit;

Commit complete.

SQL> create table Pinstructor(Id number(7),name varchar(15),dept_name


varchar(10),salary long,primar
y key(ID),foreign key(dept_name)refrences Pdepartment(dept_name));
create table Pinstructor(Id number(7),name varchar(15),dept_name varchar(10),salary
long,primary key

ERROR at line 1:
ORA-00905: missing keyword

SQL> create table Pinstructor(Id number(7),name varchar(15),dept_name


varchar(10),salary long,prima
ry key(ID),foreign key(dept_name)references Pdepartment(dept_name));

Table created.

SQL> insert into table Pinstructor(10101,'Srinivasan','Comp.Sci',65000);


insert into table Pinstructor(10101,'Srinivasan','Comp.Sci',65000)
*
ERROR at line 1:
ORA-00903: invalid table name

SQL> insert into Pinstructor values(10101,'Srinivasan','Comp.Sci',65000);

1 row created.

SQL> insert into Pinstructor(12121,'Wu','Finance',90000);


insert into Pinstructor(12121,'Wu','Finance',90000)
*
ERROR at line 1:
ORA-00928: missing SELECT keyword
SQL> insert into Pinstructor values(12121,'Wu','Finance',90000);

1 row created.

SQL> commit;

Commit complete.

===================================================================================
===========================

SQL*Plus: Release 10.2.0.1.0 - Production on Tue Aug 13 15:53:59 2019

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

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> select * from Pinstructor;

ID NAME DEPT_NAME
---------- --------------- ----------
SALARY
--------------------------------------------------------------------------------
10101 Srinivasan Comp.Sci
65000

12121 Wu Finance
90000

SQL> insert into Pinstructor values(15151,'Mozart','Music',40000);

1 row created.

SQL> select * from Pinstructor;

ID NAME DEPT_NAME
---------- --------------- ----------
SALARY
--------------------------------------------------------------------------------
10101 Srinivasan Comp.Sci
65000

12121 Wu Finance
90000

15151 Mozart Music


40000

SQL> insert into Pinstructor values(22222,'Einstein','Physics',95000);

1 row created.
SQL> insert into Pinstructor values(32343,'El Said','History',60000);

1 row created.

SQL> insert into Pinstructor values(33456,'Gold','Physics',87000);

1 row created.

SQL> insert into Pinstructor values(45565,'Katz','Comp.Sci',75000);

1 row created.

SQL> insert into Pinstructor values(58583,'Califieri','History',62000);

1 row created.

SQL> insert into Pinstructor values(765343,'Singh','Finance',80000);

1 row created.

SQL> insert into Pinstructor values(76766,'Crick','Biology',72000)';


ERROR:
ORA-01756: quoted string not properly terminated

SQL> insert into Pinstructor values(76766,'Crick','Biology',72000);

1 row created.

SQL> insert into Pinstructor values(83821,'Brandt','Comp.Sci',92000);

1 row created.

SQL> insert into Pinstructor values(98345,'Kim','Elec.Eng',80000);


insert into Pinstructor values(98345,'Kim','Elec.Eng',80000)
*
ERROR at line 1:
ORA-02291: integrity constraint (TEIT34.SYS_C0030799) violated - parent key not
found

SQL> insert into Pinstructor values(98345,'Kim','Elec.Eng',80000);


insert into Pinstructor values(98345,'Kim','Elec.Eng',80000)
*
ERROR at line 1:
ORA-02291: integrity constraint (TEIT34.SYS_C0030799) violated - parent key not
found

SQL> select * from Pinstructor;

ID NAME DEPT_NAME
---------- --------------- ----------
SALARY
--------------------------------------------------------------------------------
10101 Srinivasan Comp.Sci
65000

12121 Wu Finance
90000

15151 Mozart Music


40000

ID NAME DEPT_NAME
---------- --------------- ----------
SALARY
--------------------------------------------------------------------------------
22222 Einstein Physics
95000

32343 El Said History


60000

33456 Gold Physics


87000

ID NAME DEPT_NAME
---------- --------------- ----------
SALARY
--------------------------------------------------------------------------------
45565 Katz Comp.Sci
75000

58583 Califieri History


62000

765343 Singh Finance


80000

ID NAME DEPT_NAME
---------- --------------- ----------
SALARY
--------------------------------------------------------------------------------
76766 Crick Biology
72000

83821 Brandt Comp.Sci


92000

11 rows selected.

SQL> commet;
SP2-0042: unknown command "commet" - rest of line ignored.
SQL> comite;
SP2-0042: unknown command "comite" - rest of line ignored.
SQL> commit;

Commit complete.

SQL> create table Pstudent(s_id char(5),s_name varchar(15),dept_name


varchar(10),tot_cred int);

Table created.
SQL> drop table Pstudent;

Table dropped.

SQL> create table Pstudent(s_id char(5),s_name varchar(10),dept_name


varchar(10),tot_cred int,primar
y key(s_id),foreign key(dept_name)references Pdepartment(dept_name));

Table created.

SQL> insert into Pstudent values(00128,'Zhang','Comp.Sci',102);

1 row created.

SQL> insert into Pstudent(12345,'Shankar','Comp.Sci',32);


insert into Pstudent(12345,'Shankar','Comp.Sci',32)
*
ERROR at line 1:
ORA-00928: missing SELECT keyword

SQL> insert into Pstudent values(12345,'Shankar','Comp.Sci',32);

1 row created.

SQL> insert into Pstudent values(19991,'Brandt','History',80)'


2
SQL> insert into Pstudent values(19991,'Brandt','History',80);

1 row created.

SQL> insert into Pstudent values(23121,'Chavez','Finance',110);

1 row created.

SQL> insert into Pstudent values(44553,'Peltier','Physics',56);

1 row created.

SQL> insert into Pstudent values(45678,'Leavy','Physics',46);

1 row created.

SQL> insert into Pstudent values(54321,'Williams','Comp.Sci',54);

1 row created.

SQL> insert into Pstudent values(55734,'Sanchez','Music',38);

1 row created.

SQL> insert into Pstudent values(70557,'Snow','Physics',0);

1 row created.

SQL> insert into Pstudent values(76543,'Brown','Comp.Sci',58);

1 row created.
SQL> insert into Pstudent values(76653,'Aoi','Elec.Eng',60);
insert into Pstudent values(76653,'Aoi','Elec.Eng',60)
*
ERROR at line 1:
ORA-02291: integrity constraint (TEIT34.SYS_C0031860) violated - parent key not
found

SQL> commit;

Commit complete.

SQL> select dept_name from Pdepartmenrt;


select dept_name from Pdepartmenrt
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> select dept_name from Pdepartment;

DEPT_NAME
----------
Biology
Comp.Sci
Elec.Eng.
Finance
History
Music
Physics

7 rows selected.

SQL> insert into Pinstructor values(98345,'Kim','Elec.Eng.',80000);

1 row created.

SQL> insert into Pstudent values(76653,'Aoi','Elec.Eng.',60);

1 row created.

SQL> insert into Pstudent values(98765,'Bourikas','Elec.Eng.',98);

1 row created.

SQL> insert into Pstudent values(98988,'Tanaka','Biology',120);

1 row created.

SQL> commit;

Commit complete.

SQL> select * from Pstudent;

S_ID S_NAME DEPT_NAME TOT_CRED


----- ---------- ---------- ----------
128 Zhang Comp.Sci 102
12345 Shankar Comp.Sci 32
19991 Brandt History 80
23121 Chavez Finance 110
44553 Peltier Physics 56
45678 Leavy Physics 46
54321 Williams Comp.Sci 54
55734 Sanchez Music 38
70557 Snow Physics 0
76543 Brown Comp.Sci 58
76653 Aoi Elec.Eng. 60

S_ID S_NAME DEPT_NAME TOT_CRED


----- ---------- ---------- ----------
98765 Bourikas Elec.Eng. 98
98988 Tanaka Biology 120

13 rows selected.

SQL> create table Padvisor(as_id char(5),i_id number(7),primary key(as_id),foreign


key(as_id)referen
ces Pstudent(s_id),foreign key(i_id)references Pinstructor(ID));

Table created.

SQL> insert into Padvisor values(00128,45565);

1 row created.

SQL> insert into Padvisor values(12345,10101);

1 row created.

SQL> insert into Padvisor values(23121,76543);


insert into Padvisor values(23121,76543)
*
ERROR at line 1:
ORA-02291: integrity constraint (TEIT34.SYS_C0031883) violated - parent key not
found

SQL> select ID from Pinstructor where dept_name='Finance';

ID
----------
12121
765343

SQL> delete ID from Pinstructor where ID=765343;


delete ID from Pinstructor where ID=765343
*
ERROR at line 1:
ORA-00933: SQL command not properly ended

SQL> delete from Pinstructor where ID=765343;

1 row deleted.

SQL> insert into Pinstructor values(76543,'Singh','Finance',80000);


1 row created.

SQL> commit;

Commit complete.

SQL> insert into Padvisor values(23121,76543);

1 row created.

SQL> insert into Padvisor values(44553,22222);

1 row created.

SQL> insert into Padvisor values(45678,22222);

1 row created.

SQL> insert into Padvisor values(76543,45565);

1 row created.

SQL> insert into Padvisor values(76653,98345);

1 row created.

SQL> insert into Padvisor values(98765,98345);

1 row created.

SQL> ibnsert into Padvisor values(98988,76766);


SP2-0734: unknown command beginning "ibnsert in..." - rest of line ignored.
SQL> insert into Padvisor values(98988,76766);

1 row created.

SQL> select * from Padvisor;

AS_ID I_ID
----- ----------
128 45565
12345 10101
23121 76543
44553 22222
45678 22222
76543 45565
76653 98345
98765 98345
98988 76766

9 rows selected.

SQL> commit;

Commit complete.

SQL> create table Pcourse(course_id char(10),title varchar(30),dept_name


varchar(10),credit char(2),
primary key(course_id));

Table created.

SQL> drop table Pcourse;

Table dropped.

SQL> create table Pcourse(course_id char(10),title varchar(30),dept_name


varchar(10),credit char(2)
,primary key(course_id),foreign key(dept_name)references Pdepartment(dept_name));

Table created.

SQL> insert into Pcourse values('BIO-101','Intro. to Biology','Biology',4);

1 row created.

SQL> insert into Pcourse values('BIO-301','Genetics','Biology',4);

1 row created.

SQL> insert into Pcourse values('BIO-399','Computation Biology','Biology',3);

1 row created.

SQL> insert into Pcourse values('CS-101','Intro. to Computer


Science','Comp.Sci',4);

1 row created.

SQL> insert into Pcourse values('CS-190','Game Design','Comp.Sci',4);

1 row created.

SQL> insert into Pcourse values('CS-315','Robotics','Comp.


2
SQL> insert into Pcourse values('CS-315','Robotics','Comp.Sci',3);

1 row created.

SQL> insert into Pcourse values('CS-319','Image Processing','Comp.Sci',3);

1 row created.

SQL> insert into Pcourse values('CS-347','Database System Concept','Comp.Sci',3);

1 row created.

SQL> insert into Pcourse values('EE-181','Intro. to Digital


Systems','Elec.Eng.',3);

1 row created.

SQL> insert into Pcourse values('FIN-201','Investment Banking','Finance',3);

1 row created.

SQL> insert into Pcourse values('HIS-351','World History','History',3);


1 row created.

SQL> insert into Pcourse values('MU-199','Music Video Production','Music',3);

1 row created.

SQL> insert into Pcourse values('Physical Principles','Physics',4);


insert into Pcourse values('Physical Principles','Physics',4)
*
ERROR at line 1:
ORA-00947: not enough values

SQL> insert into Pcourse values('PHY-101','Physical Principles','Physics',4);

1 row created.

SQL> commit;

Commit complete.

=============================================================================

SQL*Plus: Release 10.2.0.1.0 - Production on Wed Aug 14 12:41:55 2019

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

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> create table Pprereq(course_id char(8),prereq_id char(8),primary


key(course_id),primary key(pre
req_id),foreign key(course_id)references Pcourse(course_id),foreign
key(prereq_id)references Pcourse
(course_id));
create table Pprereq(course_id char(8),prereq_id char(8),primary
key(course_id),primary key(prereq_i
*
ERROR at line 1:
ORA-02260: table can have only one primary key

SQL> create table Pprereq(course_id char(8),prereq_id char(8),primary


key(course_id),foreign key(co
urse_id)references Pcourse(course_id),foreign key(prereq_id)references
Pcourse(course_id));

Table created.

SQL> insert into Pprereq values('BIO-301','BIO-101');


insert into Pprereq values('BIO-301','BIO-101')
*
ERROR at line 1:
ORA-02291: integrity constraint (TEIT34.SYS_C0031978) violated - parent key not
found
SQL> select course_id from Pcourse
2
SQL> select course_id from Pcourse;

COURSE_ID
----------
BIO-101
BIO-301
BIO-399
CS-101
CS-190
CS-315
CS-319
CS-347
EE-181
FIN-201
HIS-351

COURSE_ID
----------
MU-199
PHY-101

13 rows selected.

SQL> insert into Pprereq values('BIO-399','BIO-101');


insert into Pprereq values('BIO-399','BIO-101')
*
ERROR at line 1:
ORA-02291: integrity constraint (TEIT34.SYS_C0031978) violated - parent key not
found

SQL> drop table Pprereq;

Table dropped.

SQL> create table Pprereq(course_id char(8),prereq_id char(8),primary


key(prereq_id),foreign key(cou
rse_id)references Pcourse(course_id),foreign key(prereq_id)references
Pcourse(course_id));

Table created.

SQL> insert into Pprereq values('BIO-301','BIO-101');


insert into Pprereq values('BIO-301','BIO-101')
*
ERROR at line 1:
ORA-02291: integrity constraint (TEIT34.SYS_C0031981) violated - parent key not
found

SQL> drop table Pprereq;

Table dropped.

SQL> create table Pprereq(course_id char(8),prereq_id char(8),primary


key(course_id),primary key(pre

2
SQL> create table Pprereq(course_id char(8),prereq_id char(8),primary
key(course_id,prereq_id),forei
gn key(course_id)references Pcourse(course_id),foreign key(prereq_id)references
Pcourse(course_id));

Table created.

SQL> insert into Pprereq values('BIO-301','BIO-101');


insert into Pprereq values('BIO-301','BIO-101')
*
ERROR at line 1:
ORA-02291: integrity constraint (TEIT34.SYS_C0031984) violated - parent key not
found

SQL> create table Ptime_slot(time_slot_id char,day char,start_time char(5),end_time


char(5),primary
key(time_slot_id,day,start_time);
create table Ptime_slot(time_slot_id char,day char,start_time char(5),end_time
char(5),primary key(t

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

SQL> create table Ptime_slot(time_slot_id char,day char,start_time


char(5),end_time char(5),primary
key(time_slot_id,day,start_time));
create table Ptime_slot(time_slot_id char,day char,start_time char(5),end_time
char(5),primarykey(t

*
ERROR at line 1:
ORA-00902: invalid datatype

SQL> create table Ptime_slot(time_slot_id char,day char,start_time


char(5),end_time char(5),primary
key(time_slot_id,day,start_time));

Table created.

SQL> insert into Ptime_slot values('A','M','8:00','8:50');

1 row created.

SQL> insert into Ptime_slot values('A','W','8:00','8:50');

1 row created.

SQL> insert into Ptime_slot values('A','F','8:00','8:50');

1 row created.
SQL> insert into Ptime_slot values('B','M','9:00','9:50');

1 row created.

SQL> insert into Ptime_slot values('B','W','9:00','9:50');

1 row created.

SQL> insert into Ptime_slot values('B','F','9:00','9:50');

1 row created.

SQL> insert into Ptime_slot values('C','M','11:00','11:50');

1 row created.

SQL> insert into Ptime_slot values('C','W','11:00','11:50');

1 row created.

SQL> insert into Ptime_slot values('C','F','11:00','11:50');

1 row created.

SQL> insert into Ptime_slot values('D','M','13:00','13:50');

1 row created.

SQL> insert into Ptime_slot values('D','W','13:00','13:50');

1 row created.

SQL> insert into Ptime_slot values('D','F','13:00','13:50');

1 row created.

SQL> insert into Ptime_slot values('E','T','10:30','11:45');

1 row created.

SQL> insert into Ptime_slot values('E','R','10:30','11:45');

1 row created.

SQL> insert into Ptime_slot values('F','T','14:30','15:45');

1 row created.

SQL> insert into Ptime_slot values('F','R','14:30','15:45');

1 row created.

SQL> insert into Ptime_slot values('G','M','16:00','16:50');

1 row created.

SQL> insert into Ptime_slot values('G','W','16:00','16:50');

1 row created.
SQL> insert into Ptime_slot values('G','F','16:00','16:50');

1 row created.

SQL> insert into Ptime_slot values('G','W','10:00','12:30');

1 row created.

SQL> create table Pclassroom(building varchar(10),room_num int,capacity int,primary


key(building,roo
m_num));

Table created.

SQL> insert into Pclassroom values('Packard',101,500);

1 row created.

SQL> insert into Pclassroom values('Painter',514,10);

1 row created.

SQL> insert into Pclassroom values('Taylor',3128,70);

1 row created.

SQL> insert into Pclassroom values('Watson',100,30);

1 row created.

SQL> insert into Pclassroom values('Watson',120,50);

1 row created.

SQL> commit;

Commit complete.
===================================================================================
============
===================================================================================
============
SQL*Plus: Release 10.2.0.1.0 - Production on Tue Aug 20 16:25:21 2019

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

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> select name from Pinstructor;

NAME
---------------
Srinivasan
Wu
Mozart
Einstein
El Said
Gold
Katz
Califieri
Crick
Brandt
Kim

NAME
---------------
Singh

12 rows selected.

SQL> select distinct name from Pinstructor;

NAME
---------------
Einstein
Crick
El Said
Srinivasan
Gold
Brandt
Wu
Kim
Singh
Mozart
Katz

NAME
---------------
Califieri

12 rows selected.

SQL> select distinct dept_name from Pinstructor;

DEPT_NAME
----------
Physics
Comp.Sci
Finance
Elec.Eng.
Biology
Music
History

7 rows selected.

SQL> select all dept_name from Pinstructor;

DEPT_NAME
----------
Comp.Sci
Finance
Music
Physics
History
Physics
Comp.Sci
History
Biology
Comp.Sci
Elec.Eng.

DEPT_NAME
----------
Finance

12 rows selected.

SQL> select ID,dept_name from Pdepartment;


select ID,dept_name from Pdepartment
*
ERROR at line 1:
ORA-00904: "ID": invalid identifier

SQL> select ID,dept_name from Pinstructor;

ID DEPT_NAME
---------- ----------
10101 Comp.Sci
12121 Finance
15151 Music
22222 Physics
32343 History
33456 Physics
45565 Comp.Sci
58583 History
76766 Biology
83821 Comp.Sci
98345 Elec.Eng.

ID DEPT_NAME
---------- ----------
76543 Finance

12 rows selected.

SQL> select 100 from Pinstructor;

100
----------
100
100
100
100
100
100
100
100
100
100
100

100
----------
100

12 rows selected.

SQL> select ID,name,salary*1.1 as inc_sal from Pinstructor;


select ID,name,salary*1.1 as inc_sal from Pinstructor
*
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected NUMBER got LONG

SQL> desc Pinstructor;


Name Null? Type
----------------------------------------- -------- ----------------------------
ID NOT NULL NUMBER(7)
NAME VARCHAR2(15)
DEPT_NAME VARCHAR2(10)
SALARY LONG

SQL> select salary from Pinstructor;

SALARY
--------------------------------------------------------------------------------
65000
90000
40000
95000
60000
87000
75000
62000
72000
92000
80000

SALARY
--------------------------------------------------------------------------------
80000

12 rows selected.

SQL> select ID,name,salary*1.1 as incremented_sal from Pinstructor;


select ID,name,salary*1.1 as incremented_sal from Pinstructor
*
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected NUMBER got LONG

SQL> select name from Pinstructor where dept_name='Comp.Sci';

NAME
---------------
Srinivasan
Katz
Brandt

SQL> select name from Pinstructor where dept_name='Comp.Sci' and salary>70000;


select name from Pinstructor where dept_name='Comp.Sci' and salary>70000
*
ERROR at line 1:
ORA-00997: illegal use of LONG datatype

SQL> desc Pcourse;


Name Null? Type
----------------------------------------- -------- ----------------------------
COURSE_ID NOT NULL CHAR(10)
TITLE VARCHAR2(30)
DEPT_NAME VARCHAR2(10)
CREDIT CHAR(2)

SQL> desc Pclassroom;


Name Null? Type
----------------------------------------- -------- ----------------------------
BUILDING NOT NULL VARCHAR2(10)
ROOM_NUM NOT NULL NUMBER(38)
CAPACITY NUMBER(38)

SQL> create table Psection(course_id char(10),sec_id number(2),semester


varchar(10),building varchar
(10),year int,room_num number(38),time_slot_id char,primary
key(course_id,sec_id,semester,year),fore
ign key(building)references Pclassroom(building),foreign key(room_num)references
Pclassroom(room_num
),foreign key(time_slot_id)references Ptime(time_slot_id));
create table Psection(course_id char(10),sec_id number(2),semester
varchar(10),building varchar(10),

ERROR at line 1:
ORA-02270: no matching unique or primary key for this column-list

SQL> alter table Pinstructor modify(salary number(7));


alter table Pinstructor modify(salary number(7))
*
ERROR at line 1:
ORA-01439: column to be modified must be empty to change datatype

SQL> alter table Pinstructor add sal number(7);

Table altered.

SQL> update Pinstructor set sal=salary;


update Pinstructor set sal=salary
*
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected NUMBER got LONG

SQL> commit;

Commit complete.
===================================================================================
========
===================================================================================
======

S-ar putea să vă placă și