DBIS Record Updated 29.5.23
DBIS Record Updated 29.5.23
Name :
Year: II Semester: IV Batch:2021-2025
Section:
Name :
Year : II Semester : IV Batch:2021 – 2025 Section :
Certified that this is the bonafide record work done by the above student in the
DATABASE INFORMATION SYSTEMS LAB (Sub Code: U20CSCJ06) during the month June / July
2023.
Submitted for the practical Examination held on ............................................ at Bharath Institute of Higher
Education & Research, Chennai-73.
2
Department of Computer Science and Engineering, School of Computing
U20CSCJ06 – Database Information Systems Laboratory
INDEX
9a PROCEDURES
9b FUNCTIONS
10 CURSOR
11 TRIGGERS
12
EXCEPTION HANDLING
13 CASE STUDY USING REAL LIFE DATABASE
APPLICATIONS
14
DATABASE CONNECTIVITY WITH FRONT &
BACK END TOOLS
3
Department of Computer Science and Engineering, School of Computing
U20CSCJ06 – Database Information Systems Laboratory
INTRODUCTION TO SQL:
SQL (structured query language) is a database computer language designed for the
retrieval and management of data in relational database systems (RDBMS), database scheme
creation and modification, and database object access control management.
FEATURES OF SQL
SQL is both an easy –to-understand language and a comprehensive tool for managing data.
⮚ High-level. English-like structure
⮚ Client/server architecture
SQL is used to control all of the functions that a DBMS provides for its users, including:
Data definition, SQL lets a user define the structure and organization of the stored data and
relationship among the stored data items.
Data retrieval, SQL allows a user or an application program to retrieve stored data from the
database and use it.
Data manipulation, SQL allows a user or an application program to update the database by
adding new data, removing old data, and modifying previously stored data.
Access control, SQL can be used to restrict a user’s ability to retrieve, add, and modify data,
protecting stored data against unauthorized access.
Data sharing, SQL is used to coordinate data sharing by concurrent users, ensuring that they
do not interface with one another.
Data integrity, SQL defines integrity constraints in the database, protecting it from corruption
due to inconsistent updates or system failures.
1
Department of Computer Science and Engineering, School of Computing
U20CSCJ06 – Database Information Systems Laboratory
A Data Definition Language (DDL) statement are used to define the database
structure or schema.
Aim:
To study and execute the DDL commands in RDBMS.
DDL commands:
✴ CREATE
✴ ALTER
✴ DROP
✴ RENAME
✴ TRUNCATE
SYNTAX’S OF COMMANDSCREATE
TABLE:
To make a new database, table, index, or stored query. A create statement in SQL
creates an object inside of a relational database management system (RDBMS).
2
Department of Computer Science and Engineering, School of Computing
U20CSCJ06 – Database Information Systems Laboratory
DROP TABLE:
TRUNCATE TABLE:
Remove all records from a table, including all spaces allocated for the records are
removed.
EXERCISE:
Create Table
3
Department of Computer Science and Engineering, School of Computing
U20CSCJ06 – Database Information Systems Laboratory
Table created.
DESCRIBE TABLE
EMPID
SALARY VARCHAR2 (10)
ALTER TABLE
Table altered.
4
Department of Computer Science and Engineering, School of Computing
U20CSCJ06 – Database Information Systems Laboratory
I. ADD:
SQL> alter table employee add(designation varchar2(15));
Table altered.
5
Department of Computer Science and Engineering, School of Computing
U20CSCJ06 – Database Information Systems Laboratory
II. MODIFY
Table altered.
RENAME TABLE
4 empname varchar2(20),
5 age number(3),
6 sex char
7 );
Table created.
EMPID VARCHAR2(10)
EMPNAME VARCHAR2(20)
AGE NUMBER(3)
SEX CHAR(1)
ERROR:
Table altered.
6
Department of Computer Science and Engineering, School of Computing
U20CSCJ06 – Database Information Systems Laboratory
1 arun it 22 m
2 bala service 26 m
3 chitra sales 25 f
SQL> commit;
7
Department of Computer Science and Engineering, School of Computing
U20CSCJ06 – Database Information Systems Laboratory
Commit complete.
SQL> truncate table emp;
Table truncated.
SQL> select * from emp;
no rows selected
SQL> commit;
Commit complete.
DROP TABLE
SQL> drop table empl;
Table dropped.
SQL> desc empl;
ERROR:
ORA-04043: object empl does not exist
RESULT:
8
Department of Computer Science and Engineering, School of Computing
U20CSCJ06 – Database Information Systems Laboratory
Data manipulation language allows the users to query and manipulate data in existing
schema in object. It allows following data to insert, delete, update and recovery data in schema
object.
Aim:
DML COMMANDS:
❖ INSERT
❖ UPDATE
❖ DELETE
❖ SELECT
QUERY:
Query is a statement in the DML that request the retrieval of data from database.
❖ The portion of the DML used in a Query is called Query language. The SELECT
statement is used to query a database
SYNTAX OF COMMANDSINSERT:
Values can be inserted into table using insert commands. There are two types of insert
commands. They are multiple value insert commands (using ‘&’ symbol) single value insert
command(without using ‘&’symbol)
Syntax:
(OR)
This allows the user to update the particular column value using the where clause
condition.
Syntax:
DELETE:
This allows you to delete the particular column values using where clause condition.
Syntax:
SELECT:
The select statement is used to query a database .This statement is used to retrieve the
information from the database. The SELECT statement can be used in many ways. They are:
1. Selecting some columns :
To select specified number of columns from the table the
Following command is used.
Syntax:
To select all columns from the table * is used instead of column names.
Syntax:
The DISTINCT keyword is used to return only different values (i.e. ) this
command does not select the duplicate values from the table.
Syntax:
If you want to get the rows which contain certain values, the best way to do it
is to use the IN conditional expression.
Syntax:
10
Department of Computer Science and Engineering, School of Computing
U20CSCJ06 – Database Information Systems Laboratory
BETWEEN can be used to get those items that fall within a range.
Syntax:
The select statement can be used to rename either a column or the entire
table.
Syntax:
Renaming a column:
Renaming a table:
7. Sorting:
The select statement with the order by Clause is used to sort the contents
Table either in ascending or descending order.
Syntax:
Syntax:
SELECT column name FROM table_name WHERE Column name LIKE “% or-“;
Syntax:
11
Department of Computer Science and Engineering, School of Computing
U20CSCJ05 – Database Information Systems
Laboratory
SELECT
Column_na
me(s) INTO
variable_na
me(s) FROM
table_name
WHERE
condition.
2. To Select NULL
values:
12
Department of Computer Science and Engineering, School of Computing
U20CSCJ06 – Database Information Systems Laboratory
Syntax:
INSERT COMMAND
values('&empid','&empname','&gender',&age,'&dept','&dob','&doj','&desig');
Enter value for empid: it9002
Enter value for empname: balakrishnan
Enter value for gender: male
Enter value for age: 27
Enter value for dept: it
Enter value for dob: 27-mar-1983
Enter value for doj: 02-dec-2008
Enter value for desig: coordinatorold 1:
insert into employee
values('&empid','&empname','&gender',&age,'&dept','&dob','&doj','&desi
new 1: insert into employee values('it9002','balakrishnan','male',27,'it','27-mar-1983','02-dec-20
1 row created.
1 row created.
1 row created.
8 rows selected.
DOJ DESIGNATION
DOJ DESIGNATION
DOJ DESIGNATION
1 row created.
8 rows selected.
1 row created.
1 row created.
SQL> select * from branchtable;
BRANCH CITY
UPDATE COMMAND
1 row updated.
1 row updated.
SQL> select empname,designation from employee;
EMPNAME DESIGNATION
arunprasanth manager
balakrishnan coordinator
kannan manager
magudeshwaran asst manager
jagadheesh manager
muruganandam supervisor
suresh manager
EMPNAME
arun bala
bakyarajchitra
To retrieve all columns
SQL> select * from emp;
1 arun it 22 m
2 bala accounts 26 m
3 bakyaraj stores 30 m
4 chitra sales 24 f
DELETE COMMAND
1 row deleted.
SQL> select * from emp;
2 bala accounts 26
m
3 bakyaraj stores 30
m
4 chitra sales 24 f
3 rows deleted.
SQL> create table student (idno number, name varchar(10),branch varchar(4));
Table created.
SQL> desc student;
IDNO NUMBER
NAME VARCHAR2(10)
BRANCH VARCHAR2(4)
IDNO NUMBER
IDNO NUMBER
1 ASHOK CSE BE
2 BHAVANA CSE BE
3 CAVIN CSE BE
4 DANNY IT BE
5 HARRY IT BE
1 ASHOK CSE BE
2 BHAVANA CSE BE
3 CAVIN CSE BE
4 DANNY IT B.TECH
5 HARRY IT B.TECH
RESULT:
A View is a virtual relation that does not necessarily exist in the database but can be produced
upon request by a particular user, at the time of request.
Aim:
To write a SQL command to create a view for an existing table for security purpose
and manipulate that view table.
CREATING A VIEW:
Syntax:
The subselect is known as the defining query, if with check option is specified, SQL ensures that
if a row fails to satisfy the where clause of the getting query of the view, it is notadded to the underlying
base table of the view.
REMOVING A VIEW:
A view is removed from the database with the DROP VIEW statement.
Syntax:
If CASCADE is specified, DROP VIEW deletes all related dependent objects, all objects that
reference the view.
If RESTRICT is specified and there are any other objects that depend for their existence on the
continued existence of the view being dropped, the command is rejected. The default setting is
RESTRICT.
A horizontal view restricts a user’s access to selected rows of one or more tables. Avertical
view restricts a user’s access to selected columns of one or more tables.
UPDATABLE VIEW:
For a view to be updatable, the DBMS must be able to trace any row or column backto its row
or column in the source table.
EXERCISE
Department of Computer Science and Engineering, School of Computing P a g e | 26
U20CSCJ06 – Database Information Systems Laboratory
1 ASHOK CSE BE
2 BHAVANA CSE BE
3 CAVIN CSE BE
4 DANNY IT B.TECH
UPDATE VIEW
1 ASHOK CSE BE
2 BHAVANA CSE BE
3 CAVIN CSE BE
4 DANNY IT BE
SELECT
1 ASHOK CSE BE
2 BHAVANA CSE BE
3 CAVIN CSE BE
4 DANNY IT BE
DROP
SQL> drop table student;
Table dropped.
RESULT:
Constraints is a mechanism used to prevent invalid data entry into the table. SQL
Constraints are used to specify the rules for the data in a table
Aim:
To write a SQL command to create a table and apply constraints for security purpose
and manipulate it.
1 ASHOK CSE BE
2 BHAVANA CSE BE
3 CAVIN CSE BE
4 DANNY IT B.TECH
SQL> /
Enter value for idno:
Enter value for name: 'BENNY'
Enter value for branch: 'IT'
old 1: insert into staff values(&idno,&name,&branch)
new 1: insert into staff values(,'BENNY','IT')
insert into staff values(,'BENNY','IT') *
ERROR at line 1:
ORA-00936: missing expression
UNIQUE
SQL> create table employee
(
rollno number unique,
name varchar(10),
salary number
);
Table created.
ROLLNO NUMBER
NAME VARCHAR(10)
SALARY NUMBER
PRIMARY KEY
SQL> create table cars
(model number primary key,
name varchar(10),
cost number(6)
);
Table created.
SQL> desc cars;
NAME NULL? TYPE
RNO NUMBER(5)
NAME VARCHAR2(10)
SALARY NUMBER(10)
Department of Computer Science and Engineering, School of Computing P a g e | 31
U20CSCJ06 – Database Information Systems Laboratory
FOREIGN KEY
SQL> create table admin
(
stuid number constraint stuid_pk primary key,
name varchar(10),
permit number(6)
);
Table created.
SQL> /
Enter value for stuid: 4
Enter value for name: SANJAY
Enter value for permit: 45
old 1: insert into admin values(&stuid,'&name',&permit)
new 1: insert into admin values(4,'SANJAY',45)
1 row created.
SQL> /
Enter value for stuid: 5
Enter value for name: KAMALINI
Enter value for permit: 35
old 1: insert into admin values(&stuid,'&name',&permit)
new 1: insert into admin values(5,'KAMALINI',35)
1 row created.
1 ASWIN 80
2 ROHIT 67
4 SANJAY 45
5 KAMALINI 35
SQL> /
Enter value for stuid: 2
Enter value for branch: CSE
Enter value for sec: A
old 1: insert into course values(&stuid,'&branch','&sec')
Department of Computer Science and Engineering, School of Computing P a g e | 33
U20CSCJ06 – Database Information Systems Laboratory
SQL> /
Enter value for stuid: 4
Enter value for branch: IT
Enter value for sec: A
old 1: insert into course values(&stuid,'&branch','&sec')
new 1: insert into course values(4,'IT','A')
1 row created.
SQL> /
Enter value for stuid: 6
Enter value for branch: CSE
Enter value for sec: A
old 1: insert into course values(&stuid,'&branch','&sec')
new 1: insert into course values(6,'CSE','A')
insert into course values(6,'CSE','A')
*
ERROR at line 1:
ORA-02291: integrity constraint (SCOTT.SID_FK) violated - parent key not found
1 ASWIN 80
2 ROHIT 67
4 SANJAY 45
SQL> select * from course;
STUID BRANCH SE
1 CSE A
2 CSE A
4 IT A
RESULT:
DATE:
Data Control Language statements are used to create a user area and manipulate that user in the
database.
Aim:
To study and execute the DCL commands in RDBMS.
DCL commands:
CREATE
GRANT
REVOKE
CREATE USER
Syntax:
CREATE USER <user_name> IDENTIFIED BY <password>;
Example:
SQL> create user system identified by cse;
User created.
GRANT COMMAND
Syntax:
GRANT ALL PRIVILEGES TO <user_name>;
Example:
1) SQL> grant all privileges to system;
Grant succeeded.
2) SQL> grant all on employee to system;
Grant succeeded.
SQL> conn
Enter user-name:system
Enter password: ***
Connected.
REVOKE COMMAND
Syntax:
REVOKE ALL PRIVILEGES FROM <user_name>;
Example:
SQL> revoke all privileges from system;
Revoke succeeded.
RESULT:
Aim:
To write a SQL queries for retrieving data from a relation(s) using sub queries and joins.
Introduction:
Sub-queries are used to retrieve data from tables that depend on the values in the table itself.
Sub-queries can reside in the WHERE clause, the FROM clause, or the SELECT clause
EXERCISE:
SQL> create table employee1(empno number(10), empname varchar(10), dept char(10), salary
number(10));
Table created.
1 row created.
SQL> /
Enter value for empno: 101
Enter value for empname: ramu
Enter value for dept: testing
Enter value for salary: 45000
old 1: insert into employee1 values(&empno,'&empname','&dept',&salary)
new 1: insert into employee1 values(101,'ramu','testing',45000)
1 row created.
SQL> /
Enter value for empno: 103
Enter value for empname: rajesh
Enter value for dept: network
Enter value for salary: 35000
old 1: insert into employee1 values(&empno,'&empname','&dept',&salary)
new 1: insert into employee1 values(103,'rajesh','network',35000)
Department of Computer Science and Engineering, School of Computing P a g e | 37
U20CSCJ06 – Database Information Systems Laboratory
1 row created.
SQL> /
Enter value for empno: 104
Enter value for empname: ramya
Enter value for dept: testing
Enter value for salary: 10000
old 1: insert into employee1 values(&empno,'&empname','&dept',&salary)
new 1: insert into employee1 values(104,'ramya','testing',10000)
1 row created.
SQL> /
Enter value for empno: 105
Enter value for empname: ramesh
Enter value for dept: network
Enter value for salary: 60000
old 1: insert into employee1 values(&empno,'&empname','&dept',&salary)
new 1: insert into employee1 values(105,'ramesh','network',60000)
1 row created.
RESULT:
INTRODUCTION:
Join is a query in which data is returned from two or more tables.
The purpose of a join is to combine the data spread across tables
Syntax:
Select column_1, column_2, …..column_n
from table1, table2 [where <condition>];
SQL> create table emp(empno number(3),ename varchar2(20),deptno number(3));
Table created.
1 row created.
Table created.
1 row created.
RESULT:
INTRODUCTION:
Syntax:
create sequence <sequence_name>
start with <value>
minvalue <value>
increment by <value>
maxvalue <value>
cycle/nocycle;
EXERCISE:
SQL> create sequence my_seq1
start with 1
minvalue 1
increment by 1
maxvalue 5
nocycle;
Sequence created.
Table created.
Table created.
SQL> insert into xyz values(my_seq1.nextval);
1 row created.
1
SQL> insert into xyz values(my_seq1.nextval);
1 row created.
EMPNO
1
2
1 row created.
EMPNO
3
SQL> insert into xyz1 values(my_seq1.nextval);
1 row created.
EMPNO
3
4
1 row created.
EMPNO
3
4
5
CURRVAL
5
SYNONYMS:
An alias or alternative names can be given to any of the database objects like a table, view, stored procedure,
user-defined function, and sequence with the help of SQL Server Synonym.
Whenever we create a SQL Server Synonym in a database, the synonym is referenced to a particular database
object and that database object is called base object. The location of the base object to which the synonym
is referenced can be either in the same database or in some other database in the same server or even on some
other instance running on another server.
Syntax:
1. CREATE SYNONYM [ name_of_schema. ] name_of_synonym
2. FOR name_of_base_object;
Table created.
SQL> CREATE SYNONYM fruit for fruits;
Synonym created.
no rows selected
no rows selected
SQL> select * from fruit;
FRUIT_NAME
QUANTITY
mango
3
FRUIT_NAME
QUANTITY
mango
3
RESULT:
EX.NO:9a PROCEDURES
DATE:
Aim:
To implement PL/SQL program using procedures.
SQL> create table stud(rno number(2), mark1 number(3), mark2 number(3), total number(3), primary
key(rno));
Table created.
SQL> desc stud;
Name Null? Type
1 80 85 0
2 75 84 0
3 65 80 0
4 90 85 0
SQL> create or replace procedure student (rnum number) is
2 m1 number;
3 m2 number;
4 total number;
5 begin
6 select mark1,mark2 into m1,m2 from stud where rno=rnum;
7 if m1<m2 then
8 update stud set total=m1+m2 where rno=rnum;
9 end if;
10 end;
11 /
Procedure created.
1 80 85 165
2 75 84 0
3 65 80 0
4 90 85 0
SQL> exec student(4);
PL/SQL procedure successfully completed.
SQL> select * from stud;
RNO MARK1 MARK2 TOTAL
1 80 85 165
2 75 84 0
3 65 80 0
4 90 85 0
1 80 85 165
2 75 84 159
3 65 80 145
4 90 85 0
RESULT:
Aim:
To implement PL/SQL program using functions.
1 80 65 0
2 77 56 0
3 89 90 0
145
Department of Computer Science and Engineering, School of Computing P a g e | 46
U20CSCJ06 – Database Information Systems Laboratory
133
179
RESULT:
AIM:
To study and execute cursor program in PL/SQL for fetch and manipulate the data.
SQL> declare
2 cempid cur_salary.empid%type;
3 cname cur_salary.empname%type;
4 cdept cur_salary.dept%type;
5 csalary cur_salary.salary%type;
6 coldsalary cur_salary.salary%type;
7 cursor c is select empid,empname,dept,salary from cur_salary where dno=&dno;
8 begin
9 open c;
10 loop
11 fetch c into cempid,cname,cdept,csalary;
12 exit when c%notfound;
13 update cur_salary set salary=csalary+csalary*0.05 where empid=cempid and salary>25000;
14 select salary into csalary from cur_salary where empid=cempid;
15 dbms_output.put_line('cempid'||''||'cname'||''||''||'old_salary='||''||'New Salary');
16 dbms_output.put_line(cempid||''||cname||''||to_char(coldsalary)||''||to_char(csalary));
17 end loop;
18 close c;
19 end;
20 /
Enter value for dno: 33
old 7: cursor c is select empid,empname,dept,salary from cur_salary where dno=&dno;
new 7: cursor c is select empid,empname,dept,salary from cur_salary where dno=33;
cempidcnameold_salary=New Salary
sal8001kumaresan31500
PL/SQL procedure successfully completed.
RESULT:
Aim:
TRIGGER:
A database trigger is a stored procedure that is fired when an insert, update or delete statement is issued
against the associated table. Database triggers can be used for the following purposes.
To generate data automatically.
To enforce complex integrity constraints. (e.g. Checking with sysdate, checking with data in
another table).
To customize complex security authorizations.
To maintain replicate tables.
To audit data modifications.
PARTS OF A TRIGGER
A database trigger has three parts, namely, a trigger statement, a trigger body and a trigger
restriction.
TRIGGER STATEMENT:
A trigger statement specifies the DML statements like update, delete and insert and it fires the
trigger body. It also specifies the table to which the trigger is associated.
TRIGGER BODY:
Department of Computer Science and Engineering, School of Computing P a g e | 51
U20CSCJ06 – Database Information Systems Laboratory
Trigger body is a PL/SQL block that is executed when a triggering statement is issued.
TRIGGER RESTRICTION:
Restrictions on a trigger can be achieved using the WHEN clause as shown in the syntax for creating
triggers. They can be included in the definition of a row trigger, where in, the condition in the WHEN clause
is evaluated for each row that is affected by the trigger.
TYPES OF TRIGGER:
Triggers are categorized into the following types based on when they are fired:
Before
After
For each row
For each statement (default)
EXERCISE:
1. Write a PL/SQL program to create a trigger before the user inserts the data into the table.
2. Write a PL/SQL program to create a trigger before the user deletes the data from the table.
3. Write a PL/SQL program to create a trigger before the user changes the value of the salary of the employee.
ANSWERS:
SQL>create or replace trigger ins1 before insert on emp
begin
Department of Computer Science and Engineering, School of Computing P a g e | 52
U20CSCJ06 – Database Information Systems Laboratory
OUTPUT:
SQL>insert into emp values(&eid,'&name','&dob','&addr','&sex','&desig',&deptno,'&maritsta',&salary);
SQL>insert into emp *
values(&eid,'&name','&dob','&addr','&sex','&desig',&deptno,'&maritsta',&salary);
ERROR at line 1:
ORA-20001: you cant insert a row
ORA-06512: at "CSE382.ins1", line 2
ORA-04088: error during execution of trigger 'CSE382.ins1'
OUTPUT:
SQL>delete from emp where eid=4444;
delete from emp where eid=4444;
*
ORA-20001: you can’t delete a row
ORA-06512: at "CSE382.DEL1", line 2
ORA-04088: error during execution of trigger 'CSE382.DEL1'
SQL> create trigger upd1 before update on emp for each row
2 begin
3 if :new.sal < 1000 then
4 raise_application_error(-20001,'salary can’t be low than this');
5 end if;
6 end;
7/
Trigger created.
*
ERROR at line 1:
ORA-20001: salary can’t be low than this
ORA-06512: at "CSE382.UPD1", line 3
ORA-04088: error during execution of trigger 'CSE382.UPD1'
RESULT:
An Exception is an error situation, which arises during program execution. When an error occurs exception
is raised, normal execution is stopped and control transfers to exception handling part. Exception handlers
are routines written to handle the exception. The exceptions can be internally defined (system-defined or
pre-defined) or User-defined exception.
1. PREDEFINED EXCEPTIONS:
DECLARE
E EMP%ROWTYPE;
BEGIN
SELECT * INTO E FROM EMP WHERE DEPTNO=&DEPTNO;
DBMS_OUTPUT.PUT_LINE(E.EMPNO||' '||E.ENAME||' '||E.JOB||' '||E.SAL||' '||E.DEPTNO);
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE(' NO EMPLOYEES ARE WORKING WITH EMPLOYEE
NUMBER');
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE(' MORETHAN ONE EMPLOYEE EXISTS ');
END;
1 row created.
1 row created.
EMPNO ENAME
111 sai
Manager 50000 11
122 anu
clerk 20000 12
122 abi
clerk 20000 12
EMPNO ENAME
122 abi
clerk 20000 12
122 abi
clerk 20000 12
SQL> /
Enter value for deptno: 13
old 4: SELECT * INTO E FROM EMP WHERE DEPTNO=&DEPTNO;
new 4: SELECT * INTO E FROM EMP WHERE DEPTNO=13;
NO EMPLOYEES ARE WORING WITH EMPLOYEE NUMBER
SQL> /
Department of Computer Science and Engineering, School of Computing P a g e | 56
U20CSCJ06 – Database Information Systems Laboratory
SQL> DECLARE
VALUE_MISSING EXCEPTION;
A NUMBER(2):=&A;
B NUMBER(2):=&B;
C NUMBER(4);
BEGIN
IF A IS NULL OR B IS NULL THEN
RAISE VALUE_MISSING; -- CALLING EXCEPTION
END IF;
C:=A+B;
DBMS_OUTPUT.PUT_LINE('ADD OF TWO NUMBERS : '||C);
EXCEPTION
WHEN VALUE_MISSING THEN
DBMS_OUTPUT.PUT_LINE(' COLUMN VALUES ARE MANDATORY ');
END;
/
ERROR at line 3:
ORA-06550: line 3, column 19:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
( - + case mod new not null <an identifier>
<a double-quoted delimited-identifier> <a bind variable>
continue avg count current exists max min prior sql stddev
sum variance execute forall merge time timestamp interval
date <a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
<an alternatively-quoted string literal with character set specification>
<an alternatively
ORA-06550: line 4, column 20:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
( - + case mod new not null <an identifier>
<a double-quoted delimited-identifier> <a bind variable>
continue avg count current exists max min prior sql
SQL> /
Enter value for a: 10
old 3: A NUMBER(2):=&A;
new 3: A NUMBER(2):=10;
Enter value for b: 20
old 4: B NUMBER(2):=&B;
new 4: B NUMBER(2):=20;ADD
OF TWO NUMBERS : 30
SQL> /
Enter value for a: NULL
old 3: A NUMBER(2):=&A;
new 3: A NUMBER(2):=NULL;
Enter value for b: NULL
old 4: B NUMBER(2):=&B;
new 4: B NUMBER(2):=NULL;
COLUMN VALUES ARE MANDATORY
RESULT:
EX.NO:13
DATE:
CASE STUDY USING REAL LIFE DATABASE APPLICATIONS
Aim:
To create a simple calculator using Jframe (Netbeans IDE)
Implementation:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String n1= jTextField1.getText();
String n2= jTextField2.getText();
int num1=Integer.parseInt(n1);
int num2=Integer.parseInt(n2);
int res=num1+num2;
jTextField3.setText(res+"");
EX.NO:14
DATE:
Database connectivity with Front & Back End Tools
Aim:
To connect database with Oracle by JDBC
Implementation:
Source Code:
Select Query:
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
{
System.out.println(e);
}
Insert
try
Department of Computer Science and Engineering, School of Computing P a g e | 64
U20CSCJ06 – Database Information Systems Laboratory
{
Class.forName("oracle.jdbc.driver.OracleDriver");
//step2 create the connection object
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","cse2");
//step3 create the statement object
Statement stmt=con.createStatement();
//step4 execute query
int x=stmt.executeUpdate("insert into emp values(333,'ram')");
System.out.println(x+" row inserted");
con.close();
}catch(Exception e)
{
System.out.println(e);
}
Update
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
//step2 create the connection object
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","cse2");
//step3 create the statement object
Statement stmt=con.createStatement();
//step4 execute query
int x=stmt.executeUpdate("update emp set sname='siva' where sno=333");
System.out.println(x+" row updated");
con.close();
}catch(Exception e)
{
System.out.println(e);
}
Delete
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
//step2 create the connection object
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","cse2");
//step3 create the statement object
Statement stmt=con.createStatement();
//step4 execute query
int x=stmt.executeUpdate("delete from emp where sno=333");
System.out.println(x+" row deleted");
con.close();
}catch(Exception e)
{
System.out.println(e);
}
RESULT: