III Sem DBMS Lab Programs - Part A
III Sem DBMS Lab Programs - Part A
AIM:
Query:
LENGTH
LOWERC
mahith
UPPERC
------
MAHITH
NAME
---------------
MahithSasiklala
INITCAP
-------
Smahith
---------
09-FEB-23
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
CNAME SUM(SALARY)
---------- -----------
Rohit 150000
sasikala 50000
sachin 500000
Dinesh 75000
ADDRESS COUNT(*)
------------------------------ ----------
Delhi 1
Mumbai 1
Kolkata 1
Pune 1
Dinesh Pune 1
sachin Mumbai 1
sasikala Delhi 1
Rohit Kolkata 1
CNAME SUM(SALARY)
---------- -----------
Rohit 150000
sasikala 50000
sachin 500000
Dinesh 75000
AIM:
Query:
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
Select command
6 rows selected.
RNO NAME
---------- ----------
101 sachin
102 aarthi
103 antony
104 yuvaraj
105 vandhana
106 Kaviya
6 rows selected.
SQL> select * from student where age=18;
Update command
6 rows selected.
Delete command
SQL> delete from student where rno=106;
1 row deleted.
Query:
Table altered.
RENAME command
Table renamed.
RNO NUMBER(10)
NAME VARCHAR2(10)
AGE NUMBER(2)
GENDER VARCHAR2(7)
CONTACTNO NUMBER(10)
CITY VARCHAR2(10)
Truncate Command
Table truncated.
no rows selected
4. Execute DCL commands
AIM:
• Create table student1 with attribute stu_name,roll_no,course_enrolled in sys user
• Insert the tuples values
• Perform DCL commands(Grant, Revoke) command
Query:
SQL> create table student1(stud_name varchar2(20),roll_no varchar2(10),course_enrolled varchar2(20));
Table created.
grant command:
a) To grant SELECT permission to a single user To grant the SELECT permission to the sys(user name) of the
college
SQL> grant select on student1 to sys;
Grant succeeded.
b) To grant SELECT permission to public We write the following command to grant the SELECT permission to all
database users.
SQL> grant select on student1 to PUBLIC;
Grant succeeded.
c) The WITH GRANT OPTION clause: (This clause is used to permit the user who already has some permissions
on a particular table so that they can give those access to other users)
SQL> grant select on student1 to sys with grant OPTION;
Grant succeeded.
revoke command
SQL> revoke all on student1 from sys;
Revoke succeeded.
5. Execute TCL(commit,rollback,savepoint ) Commands
AIM:
• Perform TCL (commit,savepoint,rollback) command operation
Query:
SQL> select * from student1;
STUD_NAME ROLL_NO COURSE_ENROLLED
-------------------- ---------- --------------------
mahith SCS394303 BCA
kaviya SCS394708 BSC
commit command
SQL> commit;
Commit complete.
SQL> rollback;
Rollback complete.
savepoint command
rollback command
SQL> rollback to one;
Rollback complete.
SQL> select *from student1;
STUD_NAME ROLL_NO COURSE_ENROLLED
-------------------- ---------- --------------------
mahith SCS394303 BCA
kaviya SCS394708 BSC
Query:
SQL> create table student(rno number(10),name varchar2(10),age number(2), gender varchar2(7), contactno
number(10), fees number(8));
Table created.
1 row created.
1 row created.
SQL> insert into student values(103, 'antony' , 34 , 'male', 9050230881, 42000);
1 row created.
1 row created.
1 row created.
SQL> select *from student where rno IN(select rno from student where fees>20000);
SQL> select *from student where gender='male' AND fees>ANY (select fees from student where
gender='male');
Table created.
5 rows created.
Query:
Table created.
1 row created.
1 row created.
1 row created.
Table created.
1 row created.
1 row created.
1 row created.
REGNO NAME
---------- --------------------
101 DILIP
102 KUMAR
9 rows selected.
SQL> create table student_marks (rno number(10),name varchar2(20), age number(5),marks number(10));
Table created.
SQL> insert into student_marks values(101,'sasikala',40,97);
1 row created.
SQL> insert into student_marks values(102,'aarthi',24,86);
1 row created.
SQL> insert into student_marks values(103,'antim',21,74);
1 row created.
SQL> insert into student_marks values(104,'yubaraj',21,90);
1 row created.
SQL> select *from student_marks;
DECLARE
s_rno student.rno%type := 10;
s_name student.name%type;
s_age student.age%type;
s_gender student.gender%type;
BEGIN
SELECT rno, name, age, gender INTO s_rno,s_name,s_age,s_gender FROM student WHERE rno = s_rno;
dbms_output.put_line(s_rno || ' ' || s_name || ' ' || s_age||' '||s_gender);
EXCEPTION
WHEN no_data_found THEN
dbms_output.put_line('No such student!');
WHEN others THEN
dbms_output.put_line('Error!');
END;
/
No such student!
DECLARE
s_rno student.rno%type := 10;
s_name student.name%type;
s_age student.age%type;
s_gender student.gender%type;
CURSOR cur_student is
SELECT rno, name, age, gender from student;
BEGIN
OPEN cur_student;
LOOP
FETCH cur_student INTO s_rno,s_name,s_age,s_gender;
EXIT WHEN cur_student%notfound;
dbms_output.put_line(s_rno ||''||s_name||''||s_age||''||s_gender);
END LOOP;
CLOSE cur_student;
END;
/
102aarthi26female
105vandhana24female
declare
a number;
b number;
c number;
function findmax(x in number, y in number)
return number
is
z number;
begin
if x>y then
z:=x;
else
z:=y;
end if;
return z;
end;
begin
a:=23;
b:=45;
c:=findmax(a,b);
dbms_output.put_line('Maximum of (23,45):' || c);
end;
/
Maximum of (23,45):45
Package created.
SQL> create or replace package body cust_sal as
2
3 procedure find_sal(c_custid customer.custid%type) is
4 c_sal customer.salary%type;
5 begin
6 select salary into c_sal
7 from customer
8 where custid=c_custid;
9 dbms_output.put_line('salary:'||c_sal);
10 end find_sal;
11 end cust_sal;
12 /