0% found this document useful (0 votes)
21 views11 pages

INTERNAL

The document shows SQL commands being used to insert, select, update and alter data in a Student database table. There are errors shown with some initial insert and select statements that are then corrected. The structure of the Student table is also modified several times by altering column names and data types.

Uploaded by

Rishitha Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views11 pages

INTERNAL

The document shows SQL commands being used to insert, select, update and alter data in a Student database table. There are errors shown with some initial insert and select statements that are then corrected. The structure of the Student table is also modified several times by altering column names and data types.

Uploaded by

Rishitha Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 11

SQL> INSERT INTO Student (StdID, StdName, Branch, Sec, Mid1, Mid2, Assign1,

Assign2)
2 VALUES
3 (1, 'A1', 'CSE', 'D', 20, 19, 'Y', 'N'),
4 (2, 'B1', 'ECE', 'A', 12, 18, 'N', 'Y'),
5 (3, 'C1', 'CSE', 'D', 20, 20, 'Y', 'Y'),
6 (4, 'D1', 'ECE', 'C', 19, 16, 'Y', 'Y'),
7 (5, 'E1', 'IT', 'B', 18, 18, 'N', 'Y');
(1, 'A1', 'CSE', 'D', 20, 19, 'Y', 'N'),
*
ERROR at line 3:
ORA-00933: SQL command not properly ended

SQL> INSERT INTO Student (StdID, StdName, Branch, Sec, Mid1, Mid2, Assign1,
Assign2)
2 VALUES
3 (1, 'A1', 'CSE', 'D', 20, 19, 'Y', 'N'),
4 (2, 'B1', 'ECE', 'A', 12, 18, 'N', 'Y'),
5 (3, 'C1', 'CSE', 'D', 20, 20, 'Y', 'Y'),
6 (4, 'D1', 'ECE', 'C', 19, 16, 'Y', 'Y'),
7 (5, 'E1', 'IT', 'B', 18, 18, 'N', 'Y');
(1, 'A1', 'CSE', 'D', 20, 19, 'Y', 'N'),
*
ERROR at line 3:
ORA-00933: SQL command not properly ended

SQL> INSERT INTO Student (StdID, StdName, Branch, Sec, Mid1, Mid2, Assign1,
Assign2)
2 VALUES (1, 'A1', 'CSE', 'D', 20, 19, 'Y', 'N');

1 row created.

SQL> INSERT INTO Student (StdID, StdName, Branch, Sec, Mid1, Mid2, Assign1,
Assign2)
2 VALUES (2, 'B1', 'ECE', 'A', 12, 18, 'N', 'Y');

1 row created.

SQL> INSERT INTO Student (StdID, StdName, Branch, Sec, Mid1, Mid2, Assign1,
Assign2)
2 VALUES (3, 'C1', 'CSE', 'D', 20, 20, 'Y', 'Y');

1 row created.

SQL> INSERT INTO Student (StdID, StdName, Branch, Sec, Mid1, Mid2, Assign1,
Assign2)
2 VALUES (4, 'D1', 'ECE', 'C', 19, 16, 'Y', 'Y');

1 row created.

SQL>
SQL> INSERT INTO Student (StdID, StdName, Branch, Sec, Mid1, Mid2, Assign1,
Assign2)
2 VALUES (5, 'E1', 'IT', 'B', 18, 18, 'N', 'Y');

1 row created.
SQL> select * from student;

STDID STDNAME
---------- --------------------------------------------------
BRANCH S MID1 MID2 A A
-------------------------------------------------- - ---------- ---------- - -
1 A1
CSE D 20 19 Y N

2 B1
ECE A 12 18 N Y

3 C1
CSE D 20 20 Y Y

STDID STDNAME
---------- --------------------------------------------------
BRANCH S MID1 MID2 A A
-------------------------------------------------- - ---------- ---------- - -
4 D1
ECE C 19 16 Y Y

5 E1
IT B 18 18 N Y

SQL> select * from student


2 having min(mid1);
having min(mid1)
*
ERROR at line 2:
ORA-00920: invalid relational operator

SQL> select max(mid1) as 'top_marks'


2 From student
3 group by stdname
4 having max(mid1);
select max(mid1) as 'top_marks'
*
ERROR at line 1:
ORA-00923: FROM keyword not found where expected

SQL> select * from student


2 where (select max(mid1) from student);
where (select max(mid1) from student)
*
ERROR at line 2:
ORA-00936: missing expression

SQL> select * from student


2 where mid1 = (select max(mid1) from student);

STDID STDNAME
---------- --------------------------------------------------
BRANCH S MID1 MID2 A A
-------------------------------------------------- - ---------- ---------- - -
1 A1
CSE D 20 19 Y N

3 C1
CSE D 20 20 Y Y

SQL> select * from student


2 where assign1 = 'N' AND assign = 'Y';
where assign1 = 'N' AND assign = 'Y'
*
ERROR at line 2:
ORA-00904: "ASSIGN": invalid identifier

SQL> select * from student


2 where assign1 = 'N' AND assign2 = 'Y';

STDID STDNAME
---------- --------------------------------------------------
BRANCH S MID1 MID2 A A
-------------------------------------------------- - ---------- ---------- - -
2 B1
ECE A 12 18 N Y

5 E1
IT B 18 18 N Y

SQL> select * from student


2 order by mid2;

STDID STDNAME
---------- --------------------------------------------------
BRANCH S MID1 MID2 A A
-------------------------------------------------- - ---------- ---------- - -
4 D1
ECE C 19 16 Y Y

2 B1
ECE A 12 18 N Y

5 E1
IT B 18 18 N Y

STDID STDNAME
---------- --------------------------------------------------
BRANCH S MID1 MID2 A A
-------------------------------------------------- - ---------- ---------- - -
1 A1
CSE D 20 19 Y N

3 C1
CSE D 20 20 Y Y

SQL> select SELECT StdID, StdName, (Mid1 + Mid2) AS TotalMarks


2 FROM Student;
select SELECT StdID, StdName, (Mid1 + Mid2) AS TotalMarks
*
ERROR at line 1:
ORA-00936: missing expression

SQL> SELECT StdID, StdName, (Mid1 + Mid2) AS TotalMarks


2 FROM Student;

STDID STDNAME TOTALMARKS


---------- -------------------------------------------------- ----------
1 A1 39
2 B1 30
3 C1 40
4 D1 35
5 E1 36

SQL> alter table student


2 add Internal_marks number(2);

Table altered.

SQL> update student


2 set Internal_marks = 9
3 where stdid = 1;

1 row updated.

SQL> select * from student;

STDID STDNAME
---------- --------------------------------------------------
BRANCH S MID1 MID2 A A
-------------------------------------------------- - ---------- ---------- - -
INTERNAL_MARKS
--------------
1 A1
CSE D 20 19 Y N
9

2 B1
ECE A 12 18 N Y

STDID STDNAME
---------- --------------------------------------------------
BRANCH S MID1 MID2 A A
-------------------------------------------------- - ---------- ---------- - -
INTERNAL_MARKS
--------------

3 C1
CSE D 20 20 Y Y

4 D1
ECE C 19 16 Y Y
STDID STDNAME
---------- --------------------------------------------------
BRANCH S MID1 MID2 A A
-------------------------------------------------- - ---------- ---------- - -
INTERNAL_MARKS
--------------

5 E1
IT B 18 18 N Y

SQL> alter table student


2 alter column stdname varchar(5);
alter column stdname varchar(5)
*
ERROR at line 2:
ORA-01735: invalid ALTER TABLE option

SQL> alter table student


2 modify column stdname varchar(5);
modify column stdname varchar(5)
*
ERROR at line 2:
ORA-00905: missing keyword

SQL> alter table student


2 modify stdname
3 varchar(4);

Table altered.

SQL> select * from student;

STDID STDN BRANCH S MID1


---------- ---- -------------------------------------------------- - ----------
MID2 A A INTERNAL_MARKS
---------- - - --------------
1 A1 CSE D 20
19 Y N 9

2 B1 ECE A 12
18 N Y

3 C1 CSE D 20
20 Y Y

STDID STDN BRANCH S MID1


---------- ---- -------------------------------------------------- - ----------
MID2 A A INTERNAL_MARKS
---------- - - --------------
4 D1 ECE C 19
16 Y Y

5 E1 IT B 18
18 N Y

SQL> alter table student


2 modify stdname
3 varchar(7);

Table altered.

SQL> alter table student


2 modify branch
3 varchar(6)
4 ;

Table altered.

SQL> select * from student;

STDID STDNAME BRANCH S MID1 MID2 A A INTERNAL_MARKS


---------- ------- ------ - ---------- ---------- - - --------------
1 A1 CSE D 20 19 Y N 9
2 B1 ECE A 12 18 N Y
3 C1 CSE D 20 20 Y Y
4 D1 ECE C 19 16 Y Y
5 E1 IT B 18 18 N Y

SQL> create or replace procedure "UPDATEUSER"


2 (stdid IN NUMBER, internal_marks)
3 is
4 begin
5 update student
6 set INTERNAL_MARKS = internal_marks
7 where stdid = stdid;
8 end;
9 /

Warning: Procedure created with compilation errors.

SQL> create or replace procedure "UPDATEUSER"


2 (stdid IN INT, internal_marks IN NUMBER)
3 is
4 begin
5 update student
6 set INTERNAL_MARKS = internal_marks
7 where stdid = stdid;
8 end;
9 /

Procedure created.

SQL> begin
2 updateuser(1,9);
3 dbms_output.put_line('record updated succesfull');
4 end;
5 /

PL/SQL procedure successfully completed.

SQL> begin
2 /
begin
*
ERROR at line 1:
ORA-06550: line 1, column 5:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the
following:
( begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
continue close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe purge

SQL> begin
2 updateuser(2,10);
3 end;
4 /

PL/SQL procedure successfully completed.

SQL> select * from student;

STDID STDNAME BRANCH S MID1 MID2 A A INTERNAL_MARKS


---------- ------- ------ - ---------- ---------- - - --------------
1 A1 CSE D 20 19 Y N 9
2 B1 ECE A 12 18 N Y
3 C1 CSE D 20 20 Y Y
4 D1 ECE C 19 16 Y Y
5 E1 IT B 18 18 N Y

SQL> select count(branch)


2 group by branch;
group by branch
*
ERROR at line 2:
ORA-00923: FROM keyword not found where expected

SQL> slect count(branch) from student


SP2-0734: unknown command beginning "slect coun..." - rest of line ignored.
SQL> select count(branch) from student
2 group by branch;

COUNT(BRANCH)
-------------
1
2
2

SQL> select branch,count(branch) as value


2 group by branch;
group by branch
*
ERROR at line 2:
ORA-00923: FROM keyword not found where expected

SQL> select branch,count(branch) as value


2 from student
3 group by branch;

BRANCH VALUE
------ ----------
IT 1
CSE 2
ECE 2

SQL> select * from student


2 where mid1 <= (select min(mid2) from student);

STDID STDNAME BRANCH S MID1 MID2 A A INTERNAL_MARKS


---------- ------- ------ - ---------- ---------- - - --------------
2 B1 ECE A 12 18 N Y

SQL> create or replace procedure "REVERSE"


2 (num IN INTEGER)
3 IS
4 temp integer := 0;
5 BEGIN
6 for num < 0 loop
7 temp := (temp * 10) + num % 10;
8 num := num/10 ;
9 end loop;
10 dbms_output.put_line('Value of reverse Number:' || temp);
11 end;
12 /

Warning: Procedure created with compilation errors.

SQL> create or replace procedure "REVERSENUMBER"


2 (num IN INTEGER)
3 IS
4 temp integer := 0;
5 BEGIN
6 for num < 0 loop
7 temp := (temp * 10) + num % 10;
8 num := num/10 ;
9 end loop;
10 dbms_output.put_line('Value of reverse Number:' || temp);
11 end;
12 /

Warning: Procedure created with compilation errors.

SQL> create or replace procedure "REVERSENUMBER"


2 (num IN INTEGER)
3 IS
4 temp integer := 0;
5 BEGIN
6 while num <> 0 LOOP
7 temp := (temp * 10) + num % 10;
8 num := num/10 ;
9 end loop;
10 DBMS_OUTPUT.PUT_LINE('Original Number: ' || num);
11 dbms_output.put_line('Value of reverse Number:' || temp);
12 end;
13 /
Warning: Procedure created with compilation errors.

SQL> CREATE OR REPLACE PROCEDURE REVERSENUMBER(num IN INTEGER) IS


2 temp INTEGER := 0;
3 original_num INTEGER := num;
4 BEGIN
5 WHILE num <> 0 LOOP
6 temp := (temp * 10) + num % 10;
7 num := num / 10;
8 END LOOP;
9
10 DBMS_OUTPUT.PUT_LINE('Original Number: ' || original_num);
11 DBMS_OUTPUT.PUT_LINE('Reversed Number: ' || temp);
12 END;
13 /

Warning: Procedure created with compilation errors.

SQL> create or replace procedure "REVERSENUMBER"


2 (num IN INTEGER)
3 IS
4 temp integer := 0;
5 BEGIN
6 while (num <= 0)
7 begin
8 temp := (temp * 10) + num % 10;
9 num := num/10 ;
10 end;
11 DBMS_OUTPUT.PUT_LINE('Original Number: ' || num);
12 dbms_output.put_line('Value of reverse Number:' || temp);
13 end;
14 /

Warning: Procedure created with compilation errors.

SQL>
SQL>
SQL> create or replace procedure "REVERSENUMBER"
2 (@num IN INTEGER)
3 IS
4 @temp integer := 0;
SP2-0310: unable to open file "temp.sql"
4 BEGIN
5 while (@num <= 0)
6 begin
7 @temp := (@temp * 10) + @num % 10;
SP2-0310: unable to open file "temp.sql"
7 @num := @num/10 ;
SP2-0310: unable to open file "num.sql"
7 end;
8 DBMS_OUTPUT.PUT_LINE('Original Number: ' || @num);
9 dbms_output.put_line('Value of reverse Number:' || @temp);
10 end;
11 /

Warning: Procedure created with compilation errors.

SQL> create or replace procedure "REVERSENUMBER"


2 (@num IN INTEGER)
3 IS
4 @temp integer := 0;
SP2-0310: unable to open file "temp.sql"
4 BEGIN
5 while (@num <= 0)
6 begin
7 @temp := (@temp * 10) + @num % 10;
SP2-0310: unable to open file "temp.sql"
7 @num := @num/10 ;
SP2-0310: unable to open file "num.sql"
7 end;
8 DBMS_OUTPUT.PUT_LINE('Original Number: ' || @num);
9 dbms_output.put_line('Value of reverse Number:' || @temp);
10 end;
11 /

Warning: Procedure created with compilation errors.

SQL> DECLARE
2 num number;
3 reverse_num number:=0;
4
5 begin
6 num:=98765;
7 while num>0
8 loop
9 reverse_num:=(reverse_num*10) + mod(num,10);
10 num:=trunc(num/10);
11 end loop;
12
13 dbms_output.put_line(' Reversed number is : '|| reverse_num);
14 /
dbms_output.put_line(' Reversed number is : '|| reverse_num);
*
ERROR at line 13:
ORA-06550: line 13, column 61:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the
following:
( begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-identifier>
<a bind variable> << continue close current delete fetch lock
insert open rollback savepoint set sql execute commit forall
merge pipe purge

SQL> set serveroutput on;


SQL> DECLARE
2 num number;
3 reverse_num number:=0;
4
5 begin
6 num:=98765;
7 while num>0
8 loop
9 reverse_num:=(reverse_num*10) + mod(num,10);
10 num:=trunc(num/10);
11 end loop;
12
13 dbms_output.put_line(' Reversed number is : '|| reverse_num);
14 end;
15 /
Reversed number is : 56789

PL/SQL procedure successfully completed.

SQL> spool off;

You might also like