You are on page 1of 67

K.L.N.

COLLEGE OF ENGINEERING
(An Autonomous Institution – Affiliated to Anna University, Chennai)
Accredited with B++ Grade by NAAC
(An ISO 9001:2015 Certified Institution)
MASTER OF COMPUTER APPLICATIONS

Department: MASTER OF COMPUTER APPLICATIONS


Laboratory:

Name ................................................................................................... Roll No ...................................

Semester: I Subject: DBMS LABORATORY

Subject Code: 20MC1L2

Register Number

Certified that is the bonafide work done by the above student during the period
October 2022 – February 2023 in the Laboratory.

STAFF INCHARGE DIRECTOR/MCA

DATE: ....................................

Submitted for the External Practical Examination held on .................................. at


K.L.N. COLLEGE of ENGINEERING, POTTAPALAYAM-630612

INTERNAL EXAMINER EXTERNAL EXAMINER


List of Programs
Date of Date of Page
S.No Name of the Program Sign
Program Submission No

SQL
1. DATA DEFINITION LANGUAGE
2. DATA DEFINITION LANGUAGE WITH CONSTRAINTS
3. DATA MANIPULATION LANGUAGE
4. QUERIES ON SINGLE ROW FUNCTIONS
5. QUERIES ON GROUP FUNCTIONS
6. JOINS
7. SUBQUERIES
8. VIEW
9. SEQUENCES

PL/SQL
PL/SQL PROGRAMS-USING IF..ELSE(MANIPULATING
a
STUDENT DATABASE)
10.
PL/SQL PROGRAMS-USING IF..ELSE(ELECTRICITY
b
BILL TARIFF)
a FACTORIAL USING FOR LOOP
11. b PERFECT NUMBER USING WHILE LOOP
c MULTIPLICATION TABLE USING WHILE LOOP
PROCEDURES(Check The Given Year Is Leap Year Or
a
Not)
12. b PROCEDURES(To Display Numbers in Triangle)
PROCEDURES(To Display Information About Employees
c
Based on Employee Number)
a FUNCTIONS(Display First ‘N’ Fibonacci Numbers)
b FUNCTIONS(Display Reverse a Given String)
13. FUNCTIONS(Count The Total Number of Student Having
c
Grade ‘Pass’)
d FUNCTIONS(Assign Grade to All Students)
a CURSORS(Cursor to Display the First Five Records)
CURSORS(Update Net Salary Database for Employee’s Net
14. b Pay ismore than 10,000)
CURSORS(To Display Employee Details who Getting the
c
Highest Salary)
a TRIGGERS(Check the Pincodeis Exactly Six Digit or Not)

15. b TRIGGERS(Check the Salary is Zero or Negative)


c TRIGGERS(Check the Student_Idmust be Start with ‘M’)
d TRIGGERS(To Convert the Name into Capital Letters)
Date of Date of Page
S.No Name of the Program Sign
Program Submission No
PACKAGES (Calculate the Net salary, Display the Pay
a
Slip, Reciprocal Sum)
16.
PACKAGES (String is Palindrome or Not and Number is
b
Prime or Not)
VISUAL BASIC
17. MENU EDITIOR-NOTEPAD SIMULATION
18. ADODC CONNECTIVITY(WITHOUT USING CONTROL)
19. DATA REPORT
EX.NO:1
DATE:
DATA DEFINITION LANGUAGE

AIM:
To implement with databases by using DDL commandssuch as CREATE, ALTER, DROP
and TRUNCATE.
Data Definition Language are classified into four types,
 Create
 Alter
 Drop
 Truncate
CREATE
Create command is used to create a table. We can specify names and data types of various
columns.
Syntax:
SQL>CREATE TABLE<TABLENAME> (FIELDNAME1 DATATYPE1...FIELD N DATATYPE N);

Output:

DESCRIBE TABLE:
Syntax:
SQL>DESC table_name;
Output:

ALTER
Alter command is used for alteration of table structures. Various uses of alter command are,
 To add a column to existing table
 To rename any existing column
 To change data type of any column or to modify its size
 Alter is also used to drop a column
Syntax:
 To add a new field:
Syntax:
SQL>ALTER TABLE<TABLE NAME>ADDNew_field_nameDATATYPE;
Output:
 Modify a table:
Syntax:
SQL>ALTER TABLE<TABLE NAME>MODIFY (FIELDNAME 1 DATATYPE);

Output:

 Drop a column:
Syntax:
SQL>ALTER TABLE<TABLENAME>DROP(COLUMN_NAME);

Output:

 RENAME A COLUMN NAME:


Rename is used to change the name of a column in a table.
Syntax:
SQL>ALTER TABLE<table name>RENAME COLUMN (old_column_name) TO (new_column_name);

Output:

DROP:
Drop query completely removes a table from database. This command will also destroy the
table structure.
Syntax:
SQL>DROP TABLE<TABLE NAME>;

Output:

 FLASHBACK:
Flashback is used to restore a deleted table.
Syntax:
SQL>FLASH BACK TABLE<table name> TO BEFORE DROP;

 ROLLBACK:
This command restores the database to last committed state. It is also used with savepoint
command to jump to a savepoint in a transaction.
Syntax:

SQL>ROLL BACK <table name>;


TRUNCATE:
Truncate command removes all records from a table. But this command will not destroy the
table’s structure. When we apply truncate command on a table its primary key initialized.
Syntax:
SQL>TRUNCATE TABLE<TABLENAME>;
Output:

Result:
Create, alter, drop and truncate are implemented by using DDL Command.
EX.NO:2 DATA DEFINITION LANGUAGE WITH CONSTRAINTS
DATE:

AIM:
To implement some operations using DDL commands using constraints in SQL.
DESCRIPTION:
Constraints are the rules enforced on the data columns of a table.These are used to limit the
type of data that can go into a table.Thisensures the accuracy and reliability of the data in the
database.
There are generally 5 types of constraints are used in SQL and they are,
1. NOT NULL
2. UNIQUE
3. PRIMARY
4. CHECK
5. FOREIGN\REFERENCE
NOT NULL CONSTRAINT:
The not null specification prohibits the insertion of a null value for this attribute.A database
modification that would cause a null to be inserted in an attribute declared to be not null generates
an error diagnostic.
Example:
SQL>CREATE TABLE stud (stud_id number(6) NOT NULL, stud_namevarchar(20));

UNIQUE CONSTRAINT:
The unique constraint do not allow any duplicate values to the assigned field.If duplicate
values are assigned an error message will be generated.
Example:
SQL>CREATE TABLE emp (emp_id number(6) UNIQUE, emp_namevarchar(20));

PRIMARY KEY CONSTRAINT:


The primary key constraint is used to unique identification of each row in a relation or field.
Example:

SQL>CREATE TABLE stud (stud_id number(6) PRIMARY KEY,stud_namevarchar(20));


NOTE:A table can have only one primary key.

CHECK CONSTRAINT:
The check constraint is used to check the values for the given attributes or for the field name.
Otherwise, It is used to limit the range of the values in a particular field i.e., where the check
constraint is actually given.
Example:
SQL>CREATE TABLE emp (emp_id number(6) PRIMARY KEY, stud_namevarchar(20). salary number(8,4)
CHECK (salary>6000 AND salary<15000));
FOREIGN KEY /REFERENCE KEY CONSTRAINT:
The foreign key (or) reference key constraint is used to refer the value of child table attribute
to the parent table attribute, if both matches the corresponding row will be inserted in the child
table.
Example:
Let us take the above student table as parent table then the child table is,
SQL>CREATE TABLE library (book_idnumber (6) PRIMARY KEY, stud_id number(6)
REFERENCES student(stud_id));

NOTE: The referenced field of the parent table must be same in both field name and data type of
the child table.
TWO LEVELS OF CONSTRAINTS:
Constraints could be either on a column level or a table level.The column level constraints
are applied only to one column, whereas the table level constraints are applied to the whole table.
Constraints can be defined by 2 levels.They are:
1. Column Level Constraint
2. Table Level Constraint
COLUMN LEVEL CONSTRAINT:
A constraint which is defined or created at the column itself(next to the column definition) is
called Column Level Constraint.
Syntax:
SQL>CREATE TABLE<table name> (<field1><datatype1> CONSTRAINT, <field2><data type2>,…..);

Output:

TABLE LEVEL CONSTRAINT;-


A constraint which is defined at the end of table creation is called Table level constraint (at
the end of all column).
Syntax:

SQL>CREATE TABLE<table name>(<field1><data type1>,<field2><data type2>, ….,


<fieldn> <data type>,CONSTRAINT <constraint name><type of constraint> (field name));

Output:
POSSIBLE OPERATIONS:
 ADD CONSTRAINT ON TABLE CREATION
 ADD FIELDS WITH CONSTRAINT ON TABLE ALTERATION
 ADD CONSTRAINT FOR AN EXISTING FIELD
The below operations could be done for every constraint by simply knowing the name of the
constraint. The name can be given by user himself or otherwise the system will create a name for
itself for a particular constraint.
 DISABLING A CONSTRAINT
 ENABLING A CONSTRAINT
 DROP A CONSTRAINT

OPERATIONS ON NOT NULL CONSTRAINT:


ADD NOT NULL ON CREATE TABLE:
Syntax:
SQL>CREATE TABLE <tablename> (<fieldname1><datatype1> CONSTRAINT
<user-defined constraint name> NOT NULL,<fieldname2><datatype2>…);
Output:

ADD NOT NULL ON ALTER TABLE:


Syntax:
SQL>ALTER TABLE<table name>ADD<field name><data type> NOT NULL;
Output:

ADD NOT NULL FOR A EXISTING FIELD:


Syntax:
SQL>ALTER TABLE <table name>MODIFY<field name><data type>NOT NULL;

Output:
OPERATIONS ON UNIQUE CONSTRAINT:
ADD UNIQUE ON CREATE TABLE:
Syntax:
SQL>CREATE TABLE<table name> (<field name1><data type1> CONSTRAINT
<user-defined constraint name> UNIQUE, <field name2><data type2>…);
Output:

ADD UNIQUE ON ALTER TABLE:


Syntax:
SQL>ALTER TABLE<table name>ADD<field name><data type> UNIQUE;

Output:

ADD UNIQUE FOR A EXISTING FIELD:


Syntax:
SQL>ALTER TABLE <table name>MODIFY<field name><data type>UNIQUE;

Output:

OPERATIONS ON PRIMARY KEY CONSTRAINT:


ADD PRIMARY KEY ON CREATE TABLE:
Syntax:

SQL>CREATE TABLE<table name>(<field name1><data type1>CONSTRAINT<user-defined constraint


name>PRIMARY KEY,<field name2><data type2>…);

Output:

ADD PRIMARY KEY ON ALTER TABLE:


It can be done only when there is no primary key constraint available in the table.
Syntax:
SQL>ALTER TABLE<table name>ADD<field name><data type> PRIMARY KEY;
Output:
ADD PRIMARY KEY FOR A EXISTING FIELD:
Syntax:
SQL>ALTER TABLE<table_name>MODIFY<field_name><datatype>PRIMARY KEY;
Output:

OPERATIONS ON CHECK CONSTRAINT:


ADD CHECK CONSTRAINT ON CREATE TABLE:
Syntax:
SQL>CREATE TABLE <table name>(<field name1><data type1>, <field name2><data type2> CONSTRAINT
<user-defined constraint name>CHECK(<field name> number> AND <field name <number> )…);
Output:

ADD CHECK CONSTRAINT ON ALTER TABLE:


Syntax:
SQL>ALTERTABLE<tablename>ADD<fieldname><datatype>CHECK (<fieldname>
number> AND <fieldname <number>);

Output:

ADD CHECK CONSTRAINT FOR A EXISTING FIELD:


Syntax:

SQL>ALTER TABLE <table name> MODIFY <field name><data type> CHECK (<field name>
number> AND <field name <number>);
Output:
OPERATIONS ON FOREIGN KEY CONSTRAINT:
ADD FOREIGN KEY CONSTRAINT ON CREATE TABLE:
Syntax:
SQL>CREATE TABLE <table name1>(<field name1><data type1>,<field name2> <data
type2> CONSTRAINT <user-defined constraint name> (<field name><data type>
REFERENCES<table name>(field name));
Output:

ADD FOREIGN KEY CONSTRAINT ON ALTER TABLE:


Syntax:
SQL>ALTER TABLE<table name1> ADD <field name><datatype> REFERENCES <table
name> (field name);
Output:

ADD FOREIGN KEY CONSTRAINT FOR A EXISTING FIELD:


Syntax:
SQL>ALTER TABLE <table name>MODIFY<field name><data type> REFERENCES
<table name>(field name);
Output:

DISABLE A CONSTRAINT:
Syntax:
SQL>ALTER TABLE<tablename>DISABLE CONSTRAINT <constraint name>;

Output:

Here, stud_3 is the table name and rollcon1 is the constraint name that was given by user himself.
ENABLE A CONSTRAINT:
Syntax:
SQL>ALTER TABLE<table name>ENABLE CONSTRAINT<constraint name>;

Output:

DROP A CONSTRAINT:
Syntax:

SQL>ALTER TABLE<tablename>DROP CONSTRAINT<constraint


name>;
Output:

ADD A CONSTRAINT AFTER DROP:


Syntax:
SQL>ALTER TABLE<table name>ADD CONSTRAINT<constraint name>TYPE OF
CONSTRAINT(field name);

Output:

RESULT:
Primary,Unique ,Not Null,Foreign and Check constraints has being implemented using DDL
Commands.
EX.NO:3
DATE:
DATA MANIPULATION LANGUAGE

AIM:
To implement with database by using DML commands. These Data Manipulation Language
are classified into four types
 Insert
 Select
 Update
 Delete
An insert command is used for inserting one or more rows into a database table with
specified table column values.
INSERT:
INSERT WITH VALUES:
The first form doesn’t specify the column name where the data will be inserted only their
values.
Syntax:
SQL>INSERT INTO<table_name>VALUES(‘&column1’,’&column2’….’&column’);
Output:

INSERT WITH COLUMN NAME:


Each column name can only be listed once, if the list does not include all the columns in a
table.
Syntax:

SQL>INSERT INTO<TABLENAME>(COLUMN_NAME)VALUES(VALUE);
OUTPUT:

INSERT WITH SELECT COMMAND:


Select command is used to select the records from a table using its field name
Syntax:
SQL>INSERT INTO<TABLE_NAME> (COLUMN_NAME) SELECT COLUMN_NAME
FROM TABLE_NAME WHERECONDITION;
Output:

INSERT WITH SET OF COLUMN:


When the select and insert data by using column set on tables that have lot columns
Example:

SQL> INSERT INTO student(id,name,age,address) VALUES(10,’arun’,21,’resthouse’);

Output:

SELECT:
This is one of the fundamental query command of SQL. It is used to retrieve data from the
database.
Syntax:

SQL>SELECT column_name FROM table_name;


Output:

FROM CLAUSE:
The SQL FROM clause is used to list the tables and any joins required for the SQL
statement.
Syntax:
SQL>SELECTfield_name1,field_name2,…,field_name_nFROM<table_name>;

Output:
WHERE CLAUSE:
The WHERE clause is used to filter records from a single table or by joining with multiple
tablesbased on a specified condition in a SELECT, INSERT, UPDATE, or DELETE statement, etc
Syntax:

SQL>SELECT field_name1,field_name2,…,field_name_nFROM<table_name> WHERE condition;

Output:

UPDATE:
This command is used for updating or modifying the values of Columns in a table (relation).
Syntax:
SQL>UPDATEtable_nameSETColumn=Value WHEREoldcolumn=Value;
Output:

4) DELETE:
This command is used for removing one or more rows from a table (relation).
Syntax:

SQL>DELETE FROM table_name [WHERE condition];


Output:

RESULT:
Insert, Select, Update, Delete operation are implemented using DML Commands.
EX.NO:4
DATE:
QUERIES ON SINGLE ROW FUNCTIONS
AIM:
To implement Single Row Functions using databases

DESCRIPTION:
Functions make the result of the query easier and are used to manipulate the data values.
Functions can accept any number of constant values or variables. These variables or constant are
called as arguments. SQL functions can perform operations such as modify individual data items,
convert column data types, format dates and numbers

 Single row/ Scalar functions.


 Group/Aggregate functions.
Functions which operate on single row and return one value per row, are called as Scalar or
Single Row functions.
Functions which operate on multiple row and give one result, are called as Group or
Aggregate functions.
CLASSIFICATION OF SINGLE ROW FUNCTIONS:
 Character
 Number
 Date
 Aggregate
CHARACTER FUNCTIONS:
LOWER(STRING) It converts the string in lower case.
Syntax:
SQL>select lower(col_name) from table_name;

Output:

UPPER(STRING)
It converts the string into upper case.

Syntax:
SQL>select upper(col_name) from tablename;
Output:
LENGTH(X) It returns the length of the string x.
Syntax:
SQL>select length(string) from dual;
Output:

CONCAT(X1,X2)This function concatenates the string with x1 with x2. This function is equivalent
to the || operator.
Syntax:
SQL>select concat(string1,string2) from dual;
Output:

ASCII(‘X’): It returns the ASCII decimal equivalent of a character passed as an argument.


Syntax:
SQL>SELECT ASCII(‘a’) FROM DUAL;

Output:

NUMERIC FUNCTIONS:
ABS(X) It obtains the absolute value for the number. If number is negative returns positive value.
Syntax:
SQL>select abs(x) from dual;
Output:

ROUND(X,[Y])It round off the decimal precision of y. If y is negative, rounds to the precision of y
places to the left of the decimal point.
Syntax:
SQL>select round(value,position) from dual;
Output:

SQRT(X)
It returns the square root of given number x. number x is negative or zero it returns null.
Syntax:
SQL>select sqrt(value) from dual;
Output:

MOD(X,Y)It returns the remainder when x is divided by the number y. when y is zero, the value
returned is x.
Syntax:
SQL>select mod(dividend,divisor) from dual;
Output:

POWER(X,Y)This function raise the value of x to the power of y.


Syntax:
SQL>SELECT POWER(X,Y) FROM DUAL;
Output:

DATE FUNCTIONS:
SYSDATE:
It is the date function that returns the current date and time. It can be used just like any other
column name. Generally we use the dual table to select the sysdate.
Syntax:
SQL>select sysdate from dual;
Output:

ADDMONTHS: It add number of months with the given date and gives result.
Syntax:
SQL>select add_months(date, months to add)from dual;
Output:

LASTDAY: It gives last date of the month given in the date.


Syntax:
SQL>select last_date(‘date’) from dual;
Output:

MONTHSBETWEEN It gives months between the given dates.


Syntax:
SQL>select months_between(date1,date2) from dual;
Output:
NEXTDAY It gives next occurrence of the given day from the given date.
Syntax:

SQL>select next_day(‘date’,’day’) from dual;


Output:

RESULT:
Character function, Numeric function, Date function are successfully implemented
EX.NO: 5
DATE:
QUERIES ON GROUP FUNCTIONS
AIM:
To implement learn about the various Group Functions in SQL.
AGGREGATE FUNCTION:
This function are produce summarized results. They are applied on set of rows to give you
single value as a result. A group function allows you to perform a data operation on several values in
a column of data as though the column was one collective group of data. These function are called
group functions also, because they are often used in a special clause of select statements called a
group by clause.
COUNT(X)
This function returns the number of row or non-null values for column x. when we use * in
place of x, it returns the total number of rows in the table.
Syntax:
SQL>select count([distinct|all]column name) from tablename;
Output:

SUM(X)
This function returns the sum of values for the column x. This function is applied on
columns having numeric datatype and it returns the numeric value.
Syntax:
SQL>SELECT SUM( COL_NAME) FROM TABLENAME;
Output:

AVG(X)
The function returns the average of values for the column x. This function is applied on
columns having numeric datatype and it returns the numeric value. It ignores the null values in the
column x.
Syntax:
SQL>SELECT AVG([DISTINCT|ALL]COLUMN NAME) FROM TABLENAME;
Output:

MIN(X)
This function returns the minimum of values for the column x for all the rows. This function
can be applied on any datatype.
Syntax:
SQL> SELECT MIN([DISTINCT|ALL]COLUMN NAME) FROM TABLENAME;
Output:
MAX(X)
This function returns the maximum of values for the column x for all the rows. This function can be
applied on any data type.
Syntax:
SQL>SELECT MAX([DISTINCT|ALL]COLUMN NAME) FROM TABLENAME;
Output:

NOTE: The avg() and sum() functions will always be applied on numeric data type while min() and
max() functions can be applied on any data type.
GROUP BY CLAUSE:
The GROUP BY clause is used with SELECT to arrange identical data into groups. It is used
to group the result-set by one or more columns. This GROUP BY clause follows the WHERE clause
in a SELECT statement and precedes the ORDER BY clause.
Syntax:
SQL>SELECT field_name1, field_name2,…, field_name_n FROM <table_name>WHERE condition
GROUP BY field_name1, field_name2,…,field_name_nORDER BY field_name1, field_name2..,field_namen;
Output:

ORDER BY CLAUSE:
The ORDER BY keyword is used to sort the result-set in ascending or descending order. The
ORDER BY keyword sorts the records in ascending order by default. To sort the records in
descending order, use the DESC keyword.
Syntax:
SQL>SELECTfield_name1, field_name2,…, field_name_n FROM <table_name>
ORDER BY field_name1 ASC/DESC;

Output:

HAVING CLAUSE:
The HAVING Clause enables you to specify conditions that filter which group results appear
in the results.
The HAVING clause was added to SQL because the WHERE keyword could not be used
with aggregate functions.
Syntax:
SQL>SELECT field_name1, field_name2…,field_name_n FROM <table_name>
WHERE condition GROUP BYfield_name1, field_name2 ,…, field_namen
HAVING condition ORDER BY field_name1, field_name2,…, field_name_n;
Output:
LIKE CLAUSE:
The SQL LIKE clause is used to search for a specified pattern in a field with WHERE clause
of a SELECT, INSERT, UPDATE, or DELETE statement. This can be done by using wildcard
operators. There are two wildcards used with the LIKE operator.
 % - The percent sign represents zero, one, or multiple characters
 _ - The underscore represents a single character
These symbols can be used in combinations.The Patterns are listed below in the table:
LIKE OPERATOR DESCRIPTION
WHERE CustomerName LIKE 'a%' Finds any values that starts with "a"
WHERE CustomerName LIKE '%a' Finds any values that ends with "a"
WHERE CustomerName LIKE '%or%' Finds any values that have "or" in any position
WHERE CustomerName LIKE '_r%' Finds any values that have "r" in the second
position
WHERE CustomerName LIKE Finds any values that starts with "a" and are at
'a_%_%' least 3 characters in length
WHERE ContactName LIKE 'a%o' Finds any values that starts with "a" and ends
with "o"
Syntax:
SQL>SELECT field_name1, field_name2…, field_name_n FROM <table_name> WHERE
field_name LIKE pattern;

Output:

DISTINCT CLAUSE:
The SQL DISTINCT clause is used with the SELECT statement to return only unique or
distinct values.
Syntax:

SQL>SELECT DISTINCTfield_name1,
field_name2…,field_name_nFROM<table_name>WHERE condition;
Output:

RESULT:
GroupBy, OrderBy, Having, Like, Distinct clauses are successfully processed in SQL
Queries.
EX.NO: 6 JOINS
DATE :
AIM:
To combine the fields from two tables using values common to each other using sql joins.
An SQL join combines columns from two or more tables in a relational database. It creates a
set that can be saved as a table used as it is.
TYPES OF SQL JOINS:
There are different types of joins available in SQL.
 Simple join
 Self-join
 Outer join
 Inner join
SIMPLE JOIN:
Equi-join:A join, which is based on equalities, is called equi-join.
Syntax:
SQL>SELECT<fieldname> FROM<tablename1>,<tablename2>WHERE table1. filed1 =table2;

Output:

NonEqui-join:It specifies the relationship between table aliases. The non equi-join uses
comparison operator instead of the equal sign like >,<,<=,>= along with conditions.
Syntax:

SQL>SELECT<fieldname>FROM<tablename1>,<tablename2>WHERE table1.filed1 <>table2;


Output:

SELF JOIN:
A self join is a query in which a table is joined to itself. Self joins are used to compare values
in a column with other values in the same column in the same table.
Syntax: SQL>SELECT a.column_name, b.column_name FROM table1 a, table b
WHERE a.common_field = b.commonfield;
Output:

OUTER JOIN:
It extends the result of a simple join. An outer join returns all the rows returned by simple join
as well as those rows from one table that do not match any row from the table. The symbol (+)
represents outer join.
It can be divided into three types as follows.
1)Left outer join
2)Right outer join
3)Full outer join
LEFT OUTER JOIN:
Syntax:
SQL>SELECT table1.field1,filed2FROM table1 LEFT OUTER JOIN table2 on
table1.commonfield=table2.commonfield;

Output:

RIGHT OUTER JOIN:


Syntax:
SQL>SELECT table1.field1,filed2FROM table1 RIGHT OUTER JOIN table2 on
table1.commonfield=table2.commonfield;
Output:

FULL OUTER JOIN:


Syntax:

SQL>SELECT table1.field1, filed2 FROM table1 FULL OUTER JOIN table2 on


table1.commonfield=table2.commonfield;
Output:

INNER JOIN:
Inner join returns the matching rows from the tables that are being joined. The query
compares each row of table1 with each row of table2 to find all pairs of rows which satisfy the join
predicate. When the join predicate is satisfied, column values for each matched pair of rows of A
and B are combined into a result row.
Syntax:

SQL>SELECT table1.column1, table2.column2….FROM table1 INNER JOIN table 2


ON table1.commonfield=table2.commonfield;
Output:

RESULT:
The various joins operatons are successfully processed.
EX.NO: 7 SUBQUERIES
DATE :
AIM:
Sub queries using select, insert, update, delete command.
SQL sub queries are the queries which are embedded inside another query. The embedded
queries are called as INNER query & container query is called as OUTER query.
Syntax:

SQL>SELECT * FROM Table_Name1 WHERE Column_name(s) = (SELECT Column_Name(s)


FROM Table_Name2);

SUBQUERIES:
 SELECT
 INSERT
 UPDATE
 DELETE
SUBQUERIES WITH THE SELECT STATEMENT:
Syntax:

SELECT column_name1, [column_name] FROM table, [table2] WHERE column_name


OPERATOR (SELECT column_name, [column_name] FROM table1, [table2 ] [WHERE])
<Condition>;

Output:

SUBQUERIES WITH THE INSERT STATEMENT:


Syntax:
SQL>INSERT INTO table_name[ (column1 [, column2 ])] SELECT [ *[column1 [,
column2]FROM table1 [, table2 ] ( WHERE VALUE OPERATOR )
Output:
SUBQUERIES WITH UPDATE STATEMENT:
Syntax:

SQL>UPDATE table SETcolumn_name = new_value[ WHERE OPERATOR [ VALUE ]


(SELECTcolumn_name FROM table_name ) [WHERE )]

Output:

SUBQUERIES WITH DELETE STATEMENT:


Syntax:

SQL>DELETE FROM Table_name [ WHERE OPERATOR [ VALUE ] (SELECT column_name


FROM Table_name ) [ WHERE) ]

Output:

Table: Customer
ID NAME AGE ADDRESS SALARY
1 Ram 30 Chennai 2000
2 Karan 25 Delhi 1500
3 Manav 20 Kolkata 2000
4 Sanju 25 Mumbai 6500
5 Hiren 27 Ramanand 8500
6 Komal 22 Mangalore 4500
7 Raja 26 Indore 10000
Write a SQL query to display Maximum Salary from customer Table.
SQL> Select Max(salary) from customer;
Output: Max(salary)
10000
Write a SQL query to display customer name who is taking maximum salary.
SQL> Select name from customer where salary = (select max(salary) from customer);
Output: NAME
Muffy
Subqueries with the UPDATE Statement
Write a query to Update salary by 0.25 times in customer1 table for all the customers whose
Age is greater than or equal to 27.
SQL> update customer1set salary = salary * 0.25 where age in (select age from
customer1 where age>=27);
Output:
SQL> Select * from customer1;
ID NAME AGE ADDRESS SALARY
1 Ram 30 Chennai 500
5 Hiren 27 Ramanand 2125

Subqueries with the DELETE Statement


Write a query to Delete records from customer1 table for all customers whose Age is greater
than or equal to 27.
SQL> delete from customer1 Where age in (select age from customer1 where age >= 27);
Output:
SQL> Select * from customer1;
ID NAME AGE ADDRESS SALARY
2 Karan 25 Delhi 1500
3 Manav 20 Kolkata 2000
4 Sanju 25 Mumbai 6500
6 Komal 22 Mangalore 4500
7 Raja 26 Indore 10000

RESULT:
Insert, Select, Update, Delete was successfully implemented in Sub Queries.
EX.NO: 8 VIEW
DATE :
AIM:
To Implement create view, drop view by using DDL and DML command.
VIEWS:
In SQL, a view is a virtual table based on the result-set of an SQL statement.A view contains
rows and columns, just like a real table. The fields in a view are fields from one or more real tables
in the database.
SYNTAX:-
SQL>CREATE VIEW view_name AS SELECT column1, column2..... FROM table_name WHERE [condition];

Examples:-
Create a table employee with attributes empno, ename, job, mgr, hiredate, sal, deptno with
appropriate data type.
Create a table department with attributes deptno, dname, loc.
Table creation:-

1. Create a view V1, which contain employee names and their manager names working in
sales department.

2. Create a view called V2 which contains column such as empno, name, job from
employee table.
3. Create a view V3 from employee table with check option on column sal>5000.

4. Create a view called V4 for the table student, which does not exists currently.

5. Create a view V5 which performs read only operation

6. Remove the view v1.


SQL> drop view v1;
View dropped.

RESULT:-
Create view, drop view with various options of views successfully implemented.
EX.NO: 9 SEQUENCES
DATE :
AIM :
To execute Sequence commands and to create Type table.
SYNTAX FOR SEQUENCE :
Create Sequence <sequence_name> increment by <increment_value>Start with
<start_value> Maxvalue <max_value>
Ex.
SQL>Create sequence s3 increment by 1 start with 10 max value 20;

IMPLEMENTATION OF SEQUENCE:
SQL>Insert into emp values (s3.nextval,‘&ename’,&sal,‘&job’,&eno);

DROP SEQUENCE :
Syntax:
SQL>Drop sequence <sequence_name>
Ex :
SQL>Drop sequence s3;
Sequence Dropped

Output:

RESULT :
The output was successfully verified.
EX.NO: 10(a) PL/SQL PROGRAMS-USING IF..ELSE
DATE : (MANIPULATING STUDENT DATABASE)
AIM :
To write a PL / SQL for manipulating student database
PROGRAM CODING :
declare
no1 number;
n1 number;
name1 varchar(20);
add1 varchar(20);
city1 varchar(20);
begin
n1: = &n1;
select sno, sname, addr, city into no1, name1, add1, city1 from stud where sno=n`;
dbms _output.put_line(‘s no:’ || no1);
dbms _output.put_line(‘s name:’ || name1);
dbms _output.put_line(‘address:’ || add1);
dbms _output.put_line(‘city:’ || city1);
end;
Output:
SQL > Set Serveroutput on ;
Enter value for n:11
Old 8: n:=&n;
New 8:n:=11;
Sno: 11
Sname: Jamun
Adress: 27,Netaji Street,
City: Madurai.

RESULT:
Thus the PL/SQL program was successfully executed.
EX.NO: 10(b) PL/SQL PROGRAMS-USING IF..ELSE
DATE : (ELECTRICITY BILL TARIFF)
AIM :
To write program to generate electricity bill tariff using PL / SQL.
PROGRAM CODING :
declare
perunit number ;
curunit number ;
nounit number ;
amount number ;
begin
perunit:=&perunit;
curunit:=&curunit;
nounit:=&curunit–perunit;
if (nounit<=100) then
amount:=nounit*1;
else if(nounit>100) and (nounit<=200) then
amount:=((nounit–100)*2)+100;
else if((nounit>200) and (nounit<=300)) then
amount:=((nounit–200)*3)+300));
else if((nounit>300) and (nounit<400)) then
amount:=((nounit–300)*4)+600;
else
amount:=((nounit–500)*6)+1500;
end if ;
dbms_output.put_line (‘Amount is=’||amount);
end;
/

Output:
Enter value of preunit:700
Enter value of Curunit:800
Amount is :100

RESULT:
Thus the PL/SQL program was successfully executed
EX.NO: 11(a) FACTORIAL USING FOR LOOP
DATE :
AIM :
To execute the program for factorial using for loop.
PROGRAM CODING :
declare
f number:=1;
i number;
n number:=&n;
begin
for i in 1 . . n
loop
f:=f*i ;
end loop ;
dbms_ouput.put_line (f||‘The factorial of’||n);
end ;

OUTPUT :
SQL > Set Serveroutput on;
Enter Value for n:6
Old 2 : num number:=&n ;
New 2 : num number:=6 ;
720 is factorial of 6
PL / SQL procedure successfully completed.

RESULT :
Thus the PL / SQL program to find factorial number was successfully executed
EX.NO: 11(b) PERFECT NUMBER USING WHILE LOOP
DATE :

AIM :
To write a PL / SQL program to find the given number is perfect number or not
PROGRAM CODING :
declare
i num:=1;
s num:=0;
n num;
begin
n:=&n
whilei< n
loop
if (mod(n,i)=0) then
s:=i+s;
end if ;
i:=i+1 ;
end loop ;
if n=s then
dbms_Output.put_line (n||‘is a perfect number’) ;
else
dbms_Output.put_line (n||‘is not a perfect number”) ;
end if ;
end;

Output:
SQL > Set server output on ;
Enter value for n: 28
Old 7: n:= &n ;
New 7: n:=28;
28 is a perfect number
PL /SQL Procedure successfully completely.

RESULT:
Thus PL / SQL program to find the perfect number was successfully executed
EX.NO: 11(c) MULTIPLICATION TABLE USING WHILE LOOP
DATE :

AIM :
To write a PL / SQL program for implementing multiplication table.
PROGRAM CODING :
declare
n number;
term number;
i number;
begin
n: = & n ;
term:=&term;
for i in 1 . . term loop
dbms_output.put_line (n|| ‘*‘ || i || ‘=’ || n*i) ;
end loop ;
end ;
Output:
SQL > Set server Output on;
Enter the value for no : 2
Old 6:n:=&n ;
New 6:n:=2;
Enter the value for term :5
Old 7: term:=&term ;
New7: term:=5;
2*1=2
2*2=4
2*3=6
2*4=8
2 * 5 = 10

RESULT :
Thus the PL/SQL was successfully executed.
EX.NO: 12(a) PROCEDURES
DATE :
(CHECK THE GIVEN YEAR IS LEAP YEAR OR NOT)
AIM:
To write a pl/sql program to create a procedure to check the given year is leap year or not

PROGRAM CODING:

create or replace procedure leapyear(y in number) is


begin
if y mod 4 =0 and y mod 100 <>0 or y mod 400=0 then
dbms_output.put_line('The '|| y|| ' is leap year');
else
dbms_output.put_line ('The '|| y|| ' is not leap year');
end if;
end;

Procedure Created

PL/SQL Block:

declare
y number;
begin
y:=&y;
leapyear(y);
end;
Output:

RESULT:
Thus the PL/SQL program successfully executed using PROCEDURES.
EX.NO: 12(b) PROCEDURES
DATE : (TO DISPLAY NUMBERS IN TRIANGLE)
AIM:
To write a pl/sql program to create a procedure to display numbers in triangle

PROGRAM CODING:
create or replace procedure disp(n in number) is
a number:=0;
begin
for i in 1..n
loop
for j in 1..i
loop
a:=a+1;
dbms_output.put_line(' '||a);
end loop;
dbms_output.put_line(' ');
a:=i;
end loop;
end;
output:

PL/SQL Block:
declare
n number;
begin
n:=&n;
disp(n);
end;
Output:

RESULT:
Thus the PL/SQL program successfully executed using PROCEDURES.
EX.NO: 12(c) PROCEDURES
DATE : (TO DISPLAY INFORMATION ABOUT EMPLOYEES BASED ON EMPLOYEE NUMBER)

AIM:
To write a pl/sql program to create a procedure to display to display information about
employees based on employee number
Employee Number Employee Name City Salary

1 Hiral Mehsana 20000


2 Pinky Mehsana 21000
3 Dhruvi Mehsana 22000
PROGRAM CODING:
create or replace procedure recdisp (n in number) is
cursor c_emp is select eno, ename, city, salary from emp where eno=n;
no emp.eno%type;
name emp.ename%type;
c emp.city%type;
s emp.salary%type;
begin
open c_emp;
fetch c_emp into no, name, c, s;
dbms_output.put_line (no||' '||name||' '||c||' '||s);
close c_emp;
end;
PL/SQL BLOCK:
declare
n number;
begin
n:=&n;
dbms_output.put_line('Employee no Employee name city salary');
recdisp (n);
end;
Output:

RESULT:
Thus the PL/SQL program successfully executed using PROCEDURES.
EX.NO: 13(a) FUNCTIONS
DATE : (DISPLAY FIRST ‘N’ FIBONACCI NUMBERS)

AIM:
To write a pl/sql program using function to display first ‘N’ Fibonacci nos.
PROGRAM CODING:
create or replace function fibo(a in number) return number is
n number:=a;
m number:=0;
s number;
c number;
begin
dbms_output.put_line('m= '||m);
dbms_output.put_line('n= '||n);
for c in 1..12
loop
s:=m+n;
dbms_output.put_line (''||s);
m:=n;
n:=s;
end loop;
return 0;
end;
/

PL/SQL BLOCK:
declare
n number:=1;
s number;
begin
s:=fibo(n);
end;
/
Output:

RESULT:
Thus the PL/SQL program successfully executed using FUNCTION.
EX.NO: 13(b) FUNCTIONS
DATE :
(DISPLAY REVERSE A GIVEN STRING)
AIM:
To write a pl/sql program using function to display reverse a given string.
PROGRAM CODING:

create or replace function f_reverse(str in varchar) return varchar is


s varchar(5);
l number;
begin
l:=length(str);
for i in reverse 1..l
loop
s:=s||substr(str,i,1);
end loop;
return s;
end;
/

PL/SQL BLOCK:
declare
str varchar(50);
s varchar(50);
begin

str:='&str';
s:=f_reverse(str);
dbms_output.put_line('The reverse string is '||s);
end;
/
Output:

RESULT:
Thus the PL/SQL program successfully executed using FUNCTION.
EX.NO: 13(c) FUNCTIONS
DATE : (COUNT THE TOTAL NUMBER OF STUDENT HAVING GRADE ‘PASS’)

AIM:
To write a pl/sql program using function to count the total number of student having grade
‘PASS’.
PROGRAM CODING:

create or replace function totalpass(s in char) return number is


no number;
cursor c_total is select count(sno) from stud1 where grade=s;
begin
open c_total;
loop
fetch c_total into no;
exit when c_total%notfound;
end loop;
close c_total;
return no;
end;

PL/SQL BLOCK:

declare
s char(5):='Pass';
n number;
begin
n:=totalpass(s);
dbms_output.put_line('The total no of student who are pass is '||n);
end;

Output:

RESULT:
Thus the PL/SQL program successfully executed using FUNCTION.
EX.NO: 13(d) FUNCTIONS
DATE : (ASSIGN GRADE TO ALL STUDENTS)

AIM:
To write a pl/sql program using function to assign grade to all students.
PROGRAM CODING:
create or replace function grade(p in number) return char is g char(15);
begin
if p >= 70 then
g:='Distinction';
return g;
elsif p >= 60 then
g:='First';
return g;
elsif p>= 50 then
g:='Pass';
return g;
else
g:='Fail';
return g;
end if;
end;

PL/SQL BLOCK:
declare
cursor c_grade is select sno,sub1,sub2,sub3 from stud1;
no stud1.sno%type;
s1 stud1.sub1%type;
s2 stud1.sub2%type;
s3 stud1.sub3%type;
t number;
g stud1.grade%type;
p number(10,2);
begin
open c_grade;
loop
fetch c_grade into no,s1,s2,s3;
exit when c_grade%notfound;
t:=s1+s2+s3;
p:=t/3;
g:=grade(p);
update stud1 set grade=g where sno=no;
end loop;
close c_grade;
end;

RESULT:
Thus the PL/SQL program has been successfully processed using FUNCTIONS.
EX.NO: 14(a) CURSORS
DATE : (CURSOR TO DISPLAY THE FIRST FIVE RECORDS)
AIM:

To write PL/SQL program using CURSOR to display the first five records.

PROGRAM CODING:

declare
cursor c_stu is select sno, sname, addr, city from stu;
n number;
no number;
name char(15);
a varchar(30);
c char(15);
begin
open c_stu;
if c_stu%isopen then
loop
fetch c_stu into no, name, a, c;
exit when c_stu%rowcount> 5;
dbms_output.put_line(' '||no||' ' ||name||' '||a||' '||c);
end loop;
end if;
close c_stu;
end;

OUTPUT:

RESULT:

Thus the PL/SQL program has been successfully processed using CURSORS.
EX.NO: 14(b) CURSORS
DATE : (UPDATE NET SALARY DATABASE FOR EMPLOYEE’S NET PAY IS MORE THAN 10,000)
AIM:
To write PL/SQL program using CURSOR to update net salary database for for employee’s
net pay is more than 10,000.
emp2 (eno, ename, department, address, city)
salary1 (eno, basic, da, hra, it)
net_Salary (eno, total_allowance, total_deduction, netpay)

PROGRAM CODING:

declare
cursor c_salemp is select e.eno,s.basic,s.da,s.hra,s.it from emp2 e, salary1 s where
e.department='finance' and e.eno=s.eno;
no number;
d number(10,2);
b number(10,2);
h number(10,2);
i number(10,2);
ta number(10,2);
td number(10,2);
np number(10,2);
begin
open c_salemp;
loop
fetch c_salemp into no,b,d,h,i;
exit when c_salemp%notfound;
ta:=b+h+d;
td:=d;
np:=ta-td;
if np> 10000 then
insert into netsalary values(no,ta,td,np);
end if;
end loop;
close c_salemp;
end;

Output:

RESULT:
Thus the PL/SQL program has been successfully processed using CURSORS.
EX.NO: 14(c) CURSORS
DATE : (TO DISPLAY EMPLOYEE DETAILS WHO GETTING THE HIGHEST SALARY)
AIM:
To write PL/SQL program using CURSOR to display employee details who getting the
highest salary.
emp (eno, ename, dept, address, city)
salary (eno, sal)

PROGRAM CODING:
declare
cursor c_empsal is select s.eno,s.ename,e.dept,s.sal from salary s,emp e where
s.sal in(select max(sal) from salary) and e.eno=s.eno;
n salary.eno%type ;
name emp.ename%type;
s1 salary.sal%type;
d1 emp.dept%type;
begin
open c_empsal;
loop
fetch c_empsal into n,name,d1,s1;
exit when c_empsal%notfound;
dbms_output.put_line('The employee no is '||n);
dbms_output.put_line('The employee name is '||name);
dbms_output.put_line('The employee department is '||d1);
dbms_output.put_line('The employee salary is '||s1);
end loop;
close c_empsal;
end;

Output :

RESULT:
Thus the PL/SQL program has been successfully implemented on CURSORS.
EX.NO:15(a)
DATE: TRIGGERS
(CHECK THE PINCODE IS EXACTLY SIX DIGIT OR NOT)
AIM: SEQUENCES
To write TRIGGER to check the pincodeentered is exactly six digit or not.
PROGRAM CODING:
create or replace trigger tpin
before insert on pin
for each row
declare
no varchar(10);
begin
no:=length(:new.p);
if no<>6 then
Raise_application_error(-20001,'Pincode must be six digit');
end if;
end;

RESULT:
Thus the PL/SQL program has been successfully implemented on TRIGGERS.
EX.NO:15(b)
DATE: TRIGGERS
(CHECK THE SALARY IS ZERO OR NEGATIVE)
AIM:
To write TRIGGER to check the SALARYentered is zero or negative.
PROGRAM CODING:
create or replace trigger neg before insert on emp for each row
declare
no number;
begin
no:=:new.sal;
if no<=0 then
raise_application_error(-30000,'negative');
end if;
end;
/
OUTPUT

RESULT:
Thus the PL/SQL program has been successfully implemented on TRIGGERS.
EX.NO:15(c)
DATE: TRIGGERS
(CHECK THE STUDENT_ID MUST BE START WITH ‘M’)
AIM:
To write TRIGGER to check the student_id must be start with ‘M’.

PROGRAM CODING:
create or replace trigger cap
before insert on str
for each row
declare
name char(10);
begin
name:=:new.name;
if name not like '%M%' then
raise_application_error(-20003,'Name is not start with M');
end if;
end;

output:

RESULT:

Thus the PL/SQL program has been successfully implemented on TRIGGERS.


EX.NO:15(d)
DATE: TRIGGERS
(TO CONVERT THE NAME INTO CAPITAL LETTERS)
AIM:
To write TRIGGER to convert the name into capital letters.

PROGRAM CODING:
create or replace trigger upper
before insert on student
for each row
declare
no number;
namevarchar(10);
begin
no:=:new.sno;
name:=upper(:new.sname);
dbms_output.put_line('the '||name||'No '||no);
:new.sno:=no;
:new.sname:=name;
end;

Output:

RESULT:
Thus the PL/SQL program has been successfully implemented on TRIGGERS.
EX.NO:16(a)
DATE: PACKAGES
(STRING IS PALINDROME OR NOT AND NUMBER IS PRIME OR NOT)

AIM:
To write a PL/SQL program using PACKAGES to string is palindrome or not and
number is prime or not.
PROGRAM CODING:

create or replace package strings as


function palindrom(s varchar) return varchar;
function prime(a number) return number;
end strings;

create or replace package body strings as


function palindrom(s varchar) return varchar is
n number;
c varchar(50);
begin
n:=length(s);
for i in reverse 1..n
loop
c:=c || substr(s,i,1);
end loop;
dbms_output.put_line('The Entered string is '||s);
dbms_output.put_line('The Reverse string is '||c);
return(c);
end;
function prime(a in number) return number is
j number:=0;
b number:=0;
n number:=a;
begin
b:=n-1;
for i in 2..b
loop
if (mod(a, i)=0) then
j:=1;
exit;
end if;
end loop;
--dbms_output.put_line('The j is'||j);
return j;
end;
end strings;
PL/SQL: (NUMBER IS PRIME OR NOT)
declare
a number;
j number;
begin
a:=&a;
j:=prime(a);
if (j=1) then
dbms_output.put_line ('Not prime no');
else
dbms_output.put_line ('prime no');
end if;
end;
Output:

PL/SQL: (STRING IS PALINDROME OR NOT)


declare
s varchar(50);
c varchar(50);
begin
s:='&s';
c:=strings.palindrom(s);
if s=c then
dbms_output.put_line('The given string is Palindrome');
else
dbms_output.put_line('The given string is Not Palindrome ');
end if;
end;
OUTPUT:

RESULT:
Thus the PL/SQL program has been successfully implemented on TRIGGERS.
EX.NO:16(b)
DATE: PACKAGES
(CALCULATE THE NETSALARY, DISPLAY THE PAY SLIP,RECIPROCAL SUM)

AIM:
To write a PL/SQL program using PACKAGES to calculate the netsalary, display the pay
slip, reciprocal sum.

PROGRAM CODING:
create or replace package con as
function raci(n number) return number;
function netsalary(n number) return number;
procedure display;
end con;

create or replace package body con as


function raci(n number) return number is
a number(10,2):=0;
begin
for i in 1..n
loop
a:=a+1/i;
end loop;
return(a);
end;

function netsalary(n number) return number is


a number(10,2):=0;
d number(10,2);
c number(10,2);
g number(10,2);
no number;
b number(10,2);
cursor c_emp is select eno, basic from emp where eno=n;
begin
open c_emp;
if c_emp%isopen then
loop
fetch c_emp into no, b;
exit when c_emp%notfound;
d:=b*0.59;
c:=b*0.02;
g:=b+c+d;
insert into salpac values(n,d,500,c,g,g-500);
dbms_output.put_line ('Successfully Inserted');
end loop;
else
dbms_output.put_line('Successfully Not Inserted');
end if;
closec_emp;
return(a);
end;

procedure display as
cursor c_sal is select emp.eno,emp.ename,gross,it,net from
emp, salpac where emp.eno=salpac.eno;
no emp.eno%type;
name emp.ename%type;
g salpac.gross%type;
n salpac.net%type;
c salpac.it%type;
tg number(10,2):=0;
tn number(10,2):=0;
begin
open c_sal;
loop
fetch c_sal into no,name,c,g,n;
exit when c_sal%notfound;
tg:=tg+g;
tn:=g+c;
dbms_output.put_line(' '||no ||' '||name||' '||g||' '||n);
end loop;
close c_sal;
dbms_output.put_line('_____________________________________________________________
_________________');
dbms_output.put_line(' Total '||tg ||' '||tn);
end;

end con;

PL/SQL: (RACIPROCAL SUM IE TO FIND 1+1/2+1/3+ . . . . . +1/N)

declare
n number;
a number(10,2);
begin
n:=&n;
a:=con.raci(n);
dbms_output.put_line('The Answer is '||a);
end;
OUTPUT:
PL/SQL: (CALCULATE THE NETSALARY AND DISPLAY THE PAY SLIP )
declare
n number;
a number(10,2);
begin
n:=&n;
a:=con.netsalary(n);
dbms_output.put_line(' Employee No Employee Name GrossSalary Netsalary');
con.display();
end;

Output:

RESULT:
The program has successfully processed using PACKAGE.
EX.NO: 17 MENU EDITIOR-NOTEPAD SIMULATION
DATE:
AIM :
To create a menu editor program using VISUAL BASIC

PRODEDURE :
STEP 1 :
Start visual basic program
STEP 2:
Choose stand.exe
STEP 3:
Place a rich text box by adding rich text box control from windows component.
STEP 4:
Create file, edit, menu using menu editor
STE 5:
Code the following program using vb editor
CODING:
Dim a As Variant
Private Sub mnucolor_Click()
comd.ShowColor
Rich TextBox1.SelColor = comd.Color
End Sub

Private Sub mnucopy_Click()


a = Rich TextBox1.SelText
End Sub

Private Sub mnucut_Click()


a = Rich TextBox1.SelText
RichTextBox1.SelText = ’’ ’’
End Sub

Private Sub mnudateClick()


If Form1.mnudate.Checked=True Then
Form 1.Mnudate.Checked=False
Rich1.Text=’’ ’’
Else
Form1.mnudate.Checked=True
Rich TextBox1.Text = Now
End If
End Sub
Private Sub mnuexit_Click()
End
End Sub()
Private Sub mnunew_Click()
Rich TextBox1.Text = ’’ ’’
End Sub
Private Sub mnufont_Click()
comd.Flags = &H1&
comd.ShowFont
RichTextBox1.Font.Name = comd.FontName
RichTextBox1.Font.Bold = comd.FontBold
RichTextBox1.Font.Italic = comd.FotItalic
RichTextBox1.Font.Size = comd.FontSize
RichTextBox1.Font.Underline = comd.FontUnderline
RichTextBox1.Font.Strikehrough = comd.FontStrikethru
End Sub

Private Sub mnuopen_Clich()


comd.Filter= ‘‘ttextfile(*.txt)||*.txt||all files(*.*)||*.*’’
comd.ShowOpen
RichTextBox1.LoadFile comd.FileName
End Sub

Private Sub mnupast_Click()


a = RichTextBox1.SelText
RichTextBox1.Text = RichTextBox1.Text & a
End Sub

Private Sub mnuSave_click()


RichTextBox1.SaveFile (RichTextBox1.FileName)
End Sub

Private Sub mnusaveas_Click()


comd.Filter = ‘‘text file(*.txt)||*.txt||all files(*.)||*.*’’
comd.ShowSave
RichTextBox1.SaveFile comd.FileName
End Sub
Output:

Result :
The output was successfully verified.
EX.NO:
2 18 ADODC CONNECTIVITY
DATE:
(WITHOUT USING CONTROL)
Aim :
To make connection from front end of visual basic to back end of oracle and to perform
ADODC connection without using control.
Connectivity using ADODatacontrol:
I. Linking ADO Data control
I) Open a new form in visual basic.
II) Project-components select ‘microsoft ADO Data control 6.0 (OLE DB). OK
III) Paste this tool in the form.
II. Connectivity using ADO control :
I) Select ‘connection string’ property of ADO control.
II) Select ‘use connection string’ (Build)
III) Select ‘microsoft OLE DB Provider for Oracle’ on ‘Provider’ tab (Next)
Provide appropriate ‘server name’ and username and password (Test Connection)
(OK).
IV) Select ‘record source’ tab select command type’ as ‘2-ad cmd table’ then select
appropriate on ‘Table or Procedure name’ (OK)
III. Connecting to tools of visual basic
I) Place necessary tools (Labels, Textboxes) on form.
II) Set ‘Datasource’ of all textboxes to ADOBC Name (ADOBCI)
III) Select appropriate link of fields to textbox by selecting from ‘datafield’
IV. Run The Program
I) Click on ‘RUN’ button on standard toolbox
II) Click on appropriate buttons (First, Left, Right, Last) to navigate on records.

ADD CONTROL CONNECTION (WITHOUT USING CONTROL) PROCEDURE


I) Open visual basic
II) Goto to project menu select references
III) Then check Microsoft ActiveX Data Object 2.0 Library
IV) Then write the following coding
CODING
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub Command1_Click()
Rs.MoveFirst
If Not rs.EOF Then
Text1.Text = rs.Fields(0)
Text2.Text = rs.Fields(1)
Text3.Text = rs.Fields(2)
Text4.Text = rs.Fields(3)
Else
Rs.MovePrevious
Text1.Text = rs.Fields(0)
Text2.Text = rs.Fields(1)
Text3.Text = rs.Fields(2)
Text4.Text = rs.Fields(3)
End If
End Sub

Private Sub Command2_Click()


Rs.MovePrevious
If Not rs.EOFThen
Text1.Text = rs.Fields(0)
Text2.Text = rs.Fields(1)
Text3.Text = rs.Fields(2)
Text4.Text = rs.Fields(3)
Else
Rs.MoveLast
Text1.Text = rs.Fields(0)
Text2.Text = rs.Fields(1)
Text3.Text = rs.Fields(2)
Text4.Text = rs.Fields(3)
End if
End Sub

Private Sub Command3_Click()


Rs.MoveNext
If Not rs.EOFThen
Text1.Text = rs.Fields(0)
Text2.Text = rs.Fields(1)
Text3.Text = rs.Fields(2)
Text4.Text = rs.Fields(3)
Else
rs.MoveFirst
Text1.Text = rs.Fields(0)
Text2.Text = rs.Fields(1)
Text3.Text = rs.Fields(2)
Text4.Text = rs.Fields(3)
End If
End Sub
Private Sub Command4_Click()
rs.MoveLast
If Not rs.EOFThen
Text1.Text = rs.Fields(0)
Text2.Text = rs.Fields(1)
Text3.Text = rs.Fields(2)
Text4.Text = rs.Fields(3)
Else
rs.MoveFirst
Text1.Text = rs.Fields(0)
Text2.Text = rs.Fields(1)
Text3.Text = rs.Fields(2)
Text4.Text = rs.Fields(3)
End If
End Sub

Private Sub Command5_Click()


con.Execute ‘‘delete from sti_1 where rollno=’’ & Val(Text1.Text)
MsgBox ‘‘record deleted’’, vbOKOnly + vblnformation, ‘‘information’’
End Sub

Private Sub Command6_Click()


con.Execute ‘‘insert into stu_1 values(‘’ & Val(Text1.Text) & ‘‘,’’ & Text2.Text &
‘‘,’’ & Val(Text3.Text) & ‘‘,’’ & (Text4.Text) & ‘‘)’’
con.Execute ‘‘commit’’
MsgBox ‘‘record inserted’’, vbOKOnly + vbInformation, ‘‘information’’
End Sub

Private Sub Command7_Click()


Set rs = Nothing
Rs.Open ‘‘select * from stu_1 where rollno=’’ &Val(Text1.Text), con, adOpenStatic
ifrs.EOFOrrs.BOF Then
MsgBox ‘’check the value’’
else
Text2.Text = rs.Fields(1)
Text3.Text = rs.Fields(2)
Text4.Text = rs.Fields(3)
End If
End Sub

Private Sub Command8_Click()


Con.Execute ‘‘update stu_1 set branch=’mba’ where rollno=’’ & Val (Text.Text) &’’’’
Text1.Locked = True
Text2.Locked = True
Text3.Locked =True
End Sub

Private Sub Command9_Click()


End
End Sub
Private Sub Form Load()
Con.Open (‘‘Provider=MSDAORA.1;User ID=128024;password=123456;Data
Source=orcl;Persist Security Info=False’’)
rs.Open ‘‘select * from stu_1’’, con, adOpenStatic
Text1.Text = rs.Fields(0)
Text2.Text = rs.Fields(1)
Text3.Text = rs.Fields(2)
Text4.Text = rs.Fields(3)
End Sub

Output:
Result:
Make connection from front end of visual basic to back end of oracle and ADODC
connection without using control perform are verified.
EX.NO: 19 DATA REPORT
DATE:
AIM :
To create a data report which extract the data from back end oracle.

PROCEDURE :
Step1:Open the visual basic 6.0 then open standard ext.
Step 2:Place one command buttons and two text box in the form being added form the
projects.
Step 3:
Right click on project I add data environment, add datareport1.
Step 4:
Go to data environment window right click on connection 1 go to properties mark
the check box besides MS OLEDB PROVIDER for oracle
Click Next
Enter server name :orcl
User name : {Enter your oracle user name)
Password :123456
Click text connection
Text connection succeded
Then click OK
Step 5:
Right click on connection1
Add command1
Add command2
Step 6:
Right click on command1 – properties
Select table among the choice
Select table name from the OLEDB connection
Click Ok
Step 7:
Under command1 we can set the fields of the chosen drag fields
Into page header and page details selection of data reports1
Then click on datareport-goto properties
Setp 8:
Make changes on the following
Data source:Data environment1
Data member:command1
Setp9:
Drag the fields of the table into the datareport2
Click report2 and go to the properties make changes
Data source:Data environment1
Data member:command2
Setp10:
Click command button 1 and goto the coding window
Private Sub Command 1_ Click()
End
End Sub
Step 11:
Private Sub mnuchr_Click()
DataEnvironment1.Command3 Text.Text, Text2.Text
DataReport3.Show
End Sub
Step 12:
Private Sub mnunum_Click()
DataEnvironment1.Command2 Val(Text.Text), Val(Text2.Text)
DataReport2.Show
End Sub
Step 13:
Private Sub mnusel_Click()
DataReport1.Show
End Sub
Step 14:Run the form and the result.

Output:

Result:
A data report which extract the data from back end oracle is successfully.

You might also like