Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
SRM NAGAR
LAB MANUAL
PREPARED BY:
NAGARAJAN .M
PROGRAMMER / CSE
DBMS MANUAL
EX: NO: 1
ALTER
DROP
TRUNCATE
COMMENT
RENAME
PROCEDURE
STEP 1: Start
STEP 3: Execute different Commands and extract information from the table.
STEP 4: Stop
SQL COMMANDS
1. COMMAND NAME: CREATE
COMMAND DESCRIPTION: CREATE command is used to create objects
in the database.
2. COMMAND NAME: DROP
COMMAND DESCRIPTION: DROP command is used to delete the object
from the database.
3. COMMAND NAME: TRUNCATE
COMMAND DESCRIPTION: TRUNCATE command is used to remove
all the records from the table
4. COMMAND NAME: ALTER
Q1. Write a query to create a table employee with empno, ename, designation, and salary.
QUERY: 01
QUERY: 02
Q2. Write a query to display the column name and datatype of the table employee.
QUERY: 03
Q3. Write a query for create a from an existing table with all the fields
QUERY: 03
QUERY: 04
Q4. Write a query for create a from an existing table with selected fields
QUERY: 04
QUERY: 05
Q5. Write a query for create a new table from an existing table without any record:
Syntax for create a new table from an existing table without any record:
QUERY: 05
SQL> CREATE TABLE EMP3 AS SELECT * FROM EMP WHERE
1>2;
Table created.
QUERY: 06
Q6. Write a Query to Alter the column EMPNO NUMBER (4) TO EMPNO NUMBER
(6).
QUERY: 06
SQL>ALTER TABLE EMP MODIFY EMPNO NUMBER (6);
Table altered.
QUERY: 07
Q7. Write a Query to Alter the table employee with multiple columns (EMPNO,
ENAME.)
QUERY: 07
QUERY: 08
Q8. Write a query to add a new column in to employee
Syntax for add a new column:
SQL> ALTER TABLE <TABLE NAME> ADD (<COLUMN NAME> <DATA
TYPE> <SIZE>);
QUERY: 08
QUERY: 09
QUERY: 09
REMOVE / DROP
QUERY: 10
Q10. Write a query to drop a column from an existing table employee
Syntax for add a new column:
SQL> ALTER TABLE <TABLE NAME> DROP COLUMN <COLUMN NAME>;
QUERY: 10
Table altered.
SQL> DESC EMP;
Name Null? Type
----------------------------------------- -------- -------------
EMPNO NUMBER(7)
ENAME VARCHAR2(12)
DESIGNATIN VARCHAR2(10)
SALARY NUMBER(8,2)
QUALIFICATION VARCHAR2(6)
DOB DATE
QUERY: 11
Q10. Write a query to drop multiple columns from employee
Syntax for add a new column:
SQL> ALTER TABLE <TABLE NAME> DROP <COLUMN
NAME1>,<COLUMN NAME2>,…………………………….. ;
QUERY: 11
REMOVE
QUERY: 12
Q10. Write a query to rename table emp to employee
Syntax for add a new column:
SQL> ALTER TABLE RENAME <OLD NAME> TO <NEW NAME>
QUERY: 12
CONSTRAINTS
Constraints are part of the table definition that limits and restriction on the value
entered into its columns.
TYPES OF CONSTRAINTS:
1) Primary key
2) Foreign key/references
3) Check
4) Unique
5) Not null
6) Null
7) Default
OPERATION ON CONSTRAINT:
i) ENABLE
ii) DISABLE
iii) DROP
Q14. Write a query to create primary constraints with column level with naming
convention
QUERY:14
QUERY: 15
SQL>CREATE TABLE EMPLOYEE (EMPNO NUMBER(6),
ENAME VARCHAR2(20),
JOB VARCHAR2(6),
SAL NUMBER(7),
DEPTNO NUMBER(5),
CONSTRAINT EMP_EMPNO_PK PRIMARY
KEY(EMPNO));
QUERY: 16
SQL>CREATE TABLE EMPLOYEE(EMPNO NUMBER(5),
ENAME VARCHAR2(6),
JOB VARCHAR2(6),
SAL NUMBER(6),
DEPTNO NUMBER(6));
SQL>ALTER TABLE EMP3 ADD CONSTRAINT EMP3_EMPNO_PK PRIMARY
KEY (EMPNO);
Q.17. Write a query to create foreign key constraints with column level
Parent Table:
Syntax for Column level constraints Using Primary key:
SQL:>CREATE <OBJ.TYPE> <OBJ.NAME> (COLUMN NAME.1 <DATATYPE>
(SIZE)<TYPE OF CONSTRAINTS> , COLUMN NAME.1 <DATATYPE> (SIZE)
……………………………);
Child Table:
Syntax for Column level constraints Using foreign key:
SQL:>CREATE <OBJ.TYPE> <OBJ.NAME> (COLUMN NAME.1 <DATATYPE>
(SIZE), COLUMN NAME2 <DATATYPE> (SIZE) REFERENCES <TABLE NAME>
(COLUMN NAME> ……………………………);
QUERY: 17
SQL>CREATE TABLE DEPT(DEPTNO NUMBER(2) PRIMARY
KEY,
DNAME VARCHAR2(20),
LOCATION VARCHAR2(15));
Parent Table:
Syntax for Column level constraints Using Primary key:
Q.18. Write a query to create foreign key constraints with column level
QUERY:18
Parent Table:
SQL:>CREATE <OBJ.TYPE> <OBJ.NAME> (COLUMN NAME.1 <DATATYPE>
(SIZE)<TYPE OF CONSTRAINTS> , COLUMN NAME.1 <DATATYPE> (SIZE)
……………………………);
Child Table:
Syntax for Table level constraints using foreign key:
SQL:>CREATE <OBJ.TYPE> <OBJ.NAME> (COLUMN NAME.1 <DATATYPE>
(SIZE), COLUMN NAME2 <DATATYPE> (SIZE), CONSTRAINT <CONST.
NAME> REFERENCES <TABLE NAME> (COLUMN NAME> );
QUERY: 19
SQL>CREATE TABLE DEPT
(DEPTNO NUMBER(2) PRIMARY KEY,
DNAME VARCHAR2(20),
LOCATION VARCHAR2(15));
Child Table:
Syntax for Table level constraints using foreign key:
SQL:>CREATE <OBJ.TYPE> <OBJ.NAME> (COLUMN NAME.1 <DATATYPE>
(SIZE) , COLUMN NAME2 <DATATYPE> (SIZE));
Check constraint
QUERY:21
QUERY:23
SQL>CREATE TABLE EMP9(EMPNO NUMBER,
ENAME VARCHAR2(20),
DESIGN VARCHAR2(15),
SAL NUMBER(5));
Unique Constraint
QUERY:24
QUERY:25
QUERY:26
Not Null
QUERY: 27
SQL>CREATE TABLE EMP13
(EMPNO NUMBER(4),
ENAME VARCHAR2(20) CONSTRAINT EMP13_ENAME_NN NOT NULL,
DESIGN VARCHAR2(20),
SAL NUMBER(3));
Null
Column Level Constraint
Q.28. Write a query to create Null constraints with column level
Syntax for Column level constraints with Null:
SQL :> CREATE <OBJ.TYPE> <OBJ.NAME> (<COLUMN NAME.1>
<DATATYPE> (SIZE) CONSTRAINT <NAME OF CONSTRAINTS>
<CONSTRAINT TYPE>, (COLUMN NAME2 <DATATYPE> (SIZE)) ;
QUERY:28
Constraint Enable
QUERY:29
SQL>ALTER TABLE EMP13 DISABLE CONSTRAINT EMP13_ENAME_NN
NULL;
QUERY:30
SQL>ALTER TABLE EMP13 ENABLE CONSTRAINT EMP13_ENAME_NN NULL;
EX: NO: 2
To implementation on DML and DCL Commands in RDBMS
AIM:
To execute and verify the DML and TCL Language commands
STEP 1: Start
STEP 2: Create the table with its essential attributes.
STEP 3: Insert the record into table
STEP 4: Update the existing records into the table
STEP 5: Delete the records in to the table
STEP 6: use save point if any changes occur in any portion of the record to undo its
original state.
STEP 7: use rollback for completely undo the records
STEP 6: use commit for permanently save the records.
SQL COMMANDS
1. COMMAND NAME: INSERT
COMMAND DESCRIPTION: INSERT command is used to Insert objects
in the database.
2. COMMAND NAME: SELECT
COMMAND DESCRIPTION: SELECT command is used to SELECT the object from
the database.
3. COMMAND NAME: UPDATE
COMMAND DESCRIPTION: UPDATE command is used to UPDATE
the records from the table
4. COMMAND NAME: DELETE
COMMAND DESCRIPTION: DELETE command is used to DELETE the
Records form the table
5. COMMAND NAME: COMMIT
COMMAND DESCRIPTION: COMMIT command is used to save the
Records.
INSERT
QUERY: 01
QUERY: 01
INSERT A RECORD FROM AN EXISTING TABLE:
SQL>INSERT INTO EMP VALUES(101,'NAGARAJAN','LECTURER',15000);
1 row created.
SELECT
QUERY: 02
QUERY: 02
DISPLAY THE EMP TABLE:
SQL> SELECT * FROM EMP;
QUERY: 03
Q3. Write a query to insert the records in to employee using substitution method.
Syntax for Insert Records into the table:
SQL :> INSERT INTO <TABLE NAME> VALUES< ‘&column name’, ‘&column
name 2’,…..);
QUERY: 03
SQL> INSERT INTO EMP
VALUES(&EMPNO,'&ENAME','&DESIGNATIN','&SALARY');
Enter value for empno: 102
Enter value for ename: SARAVANAN
Enter value for designatin: LECTURER
Enter value for salary: 15000
old 1: INSERT INTO EMP
VALUES(&EMPNO,'&ENAME','&DESIGNATIN','&SALARY')
new 1: INSERT INTO EMP VALUES(102,'SARAVANAN','LECTURER','15000')
1 row created.
SQL> /
Enter value for empno: 103
Enter value for ename: PANNERSELVAM
Enter value for designatin: ASST. PROF
Enter value for salary: 20000
old 1: INSERT INTO EMP
VALUES(&EMPNO,'&ENAME','&DESIGNATIN','&SALARY')
new 1: INSERT INTO EMP VALUES(103,'PANNERSELVAM','ASST.
PROF','20000')
1 row created.
SQL> /
Enter value for empno: 104
Enter value for ename: CHINNI
Enter value for designatin: HOD, PROF
Enter value for salary: 45000
old 1: INSERT INTO EMP
VALUES(&EMPNO,'&ENAME','&DESIGNATIN','&SALARY')
new 1: INSERT INTO EMP VALUES(104,'CHINNI','HOD, PROF','45000')
1 row created.
SQL> SELECT * FROM EMP;
UPDATE
QUERY: 04
QUERY: 04
QUERY: 05
1 row updated.
SQL> SELECT * FROM EMP;
DELETE
QUERY: 06
QUERY: 06
SAVEPOINT:
QUERY: 07
QUERY: 07
Savepoint created.
QUERY: 08
QUERY: 08
COMMIT
QUERY: 09
SQL> COMMIT;
QUERY: 09
SQL> COMMIT;
Commit complete.
CREATING A USER
SQL>CONNECT SYSTEM/MANAGER;
SQL>CONNECT "USERNAME"/"PASSWORD";
EXAMPLE
CREATING A USER
SQL>CONNECT SYSTEM/MANAGER;
SQL>CONNECT CSE2/CSECSE;
6 rows selected.
10 rows selected.
9 rows selected.
14 rows selected.
14 rows selected.
AIM
OBJECTIVE:
Nested Query can have more than one level of nesting in one single query. A SQL nested
query is a SELECT query that is nested inside a SELECT, UPDATE, INSERT, or DELETE SQL
query.
PROCEDURE
STEP 1: Start
STEP 4: Create the Nested query from the above created table.
STEP 6: Stop
SQL COMMANDS
COMMAND DESCRIPTION: SELECT command is used to select records from the table.
Table -1
SYNTAX FOR CREATING A TABLE:
INSERTION
SQL> INSERT INTO EMP2 VALUES(1001,'MAHESH','PROGRAMMER',15000,1560,200);
1 ROW CREATED.
SQL> INSERT INTO EMP2 VALUES(1002,'MANOJ','TESTER',12000,1560,200);
1 ROW CREATED.
SQL> INSERT INTO EMP2 VALUES(1003,'KARTHIK','PROGRAMMER',13000,1400,201);
1 ROW CREATED.
SQL> INSERT INTO EMP2 VALUES(1004,'NARESH','CLERK',1400,1400,201);
1 ROW CREATED.
SQL> INSERT INTO EMP2 VALUES(1005,'MANI','TESTER',13000,1400,200);
1 ROW CREATED.
SQL> INSERT INTO EMP2 VALUES(1006,'VIKI','DESIGNER',12500,1560,201);
1 ROW CREATED.
SQL> INSERT INTO EMP2 VALUES(1007,'MOHAN','DESIGNER',14000,1560,201);
1 ROW CREATED.
SQL> INSERT INTO EMP2 VALUES(1008,'NAVEEN','CREATION',20000,1400,201);
1 ROW CREATED.
SQL> INSERT INTO EMP2 VALUES(1009,'PRASAD','DIR',20000,1560,202);
1 ROW CREATED.
TABLE- 2
SYNTAX FOR CREATING A TABLE:
INSERTION
SQL> INSERT INTO DEPT2 VALUES(107,'DEVELOP','ADYAR');
1 ROW CREATED.
SQL> INSERT INTO DEPT2 VALUES(201,'DEBUG','UK');
1 ROW CREATED.
SQL> INSERT INTO DEPT2 VALUES(200,'TEST','US');
SQL> INSERT INTO DEPT2 VALUES(201,'TEST','USSR');
1 ROW CREATED.
SQL> INSERT INTO DEPT2 VALUES(108,'DEBUG','ADYAR');
1 ROW CREATED.
SQL> INSERT INTO DEPT2 VALUES(109,'BUILD','POTHERI');
1 ROW CREATED.
6 rows selected.
SELECT "COLUMN_NAME1"
FROM "TABLE_NAME1"
WHERE "COLUMN_NAME2" [COMPARISON OPERATOR]
(SELECT "COLUMN_NAME3"
FROM "TABLE_NAME2"
WHERE [CONDITION])
ENAME
----------
MAHESH
MANOJ
KARTHIK
MANI
VIKI
MOHAN
NAVEEN
PRASAD
AGNESH
AIM
OBJECTIVE:
SQL joins are used to query data from two or more tables, based on a relationship
between certain columns in these tables.
PROCEDURE
STEP 1: Start
STEP 4: Execute different Commands and extract information from the table.
STEP 5: Stop
SQL COMMANDS
Table:1 - ORDERS
Orderno number(5),
P_Id number(3));
Table created.
O_ID NUMBER(5)
ORDERNO NUMBER(5)
P_ID NUMBER(3)
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
TABLE SECTION:
1 77895 3
2 44678 3
3 22456 1
4 24562 1
5 34764 15
LASTNAME varchar2(10),
city varchar2(10));
Table created.
1 row created.
1 row created.
1 row created.
FROM table_name1
ON table_name1.column_name=table_name2.column_name
FROM persons
ON persons.p_Id = orders.p_Id
ORDER BY persons.lastname;
OUTPUT
Svendson Tove
1 77895 3
2 44678 3
3 22456 1
4 24562 1
5 34764 15
SQL>SELECT column_name(s)
FROM table_name1
FULL JOIN table_name2
ON table_name1.column_name=table_name2.column_name
FROM persons
ON persons.p_Id = orders.p_Id
ORDER BY persons.lastname;
FROM Persons
RIGHT JOIN Orders
ON Persons.P_Id=Orders.P_Id
ORDER BY Persons.LastName
FROM persons
ON persons.p_Id = orders.p_Id
ORDER BY persons.lastname;
INNER JOIN
SQL>SELECT column_name(s)
FROM table_name1
INNER JOIN table_name2
ON table_name1.column_name=table_name2.column_name
2 FROM persons
4 ON persons.p_Id = orders.p_Id
5 ORDER BY persons.lastname;
6 rows selected.
AIM
OBJECTIVE:
Views Helps to encapsulate complex query and make it reusable.
Provides user security on each view - it depends on your data policy security.
Using view to convert units - if you have a financial data in US currency, you can
create view to convert them into Euro for viewing in Euro currency.
PROCEDURE
STEP 1: Start
STEP 5: Execute different Commands and extract information from the View.
STEP 6: Stop
.SQL COMMANDS
COMMAND DESCRIPTION: INSERT command is used to insert a new row into the view.
COMMAND DESCRIPTION: DELETE command is used to delete a row from the view.
COMMANDS EXECUTION
CREATION OF TABLE
--------------------------------
Table created.
TABLE DESCRIPTION
-------------------------------
SQL> DESC EMPLOYEE;
NAME NULL? TYPE
------------------------------- -------- ------------------------
EMPLOYEE_NAME VARCHAR2(10)
EMPLOYEE_NO NUMBER(8)
DEPT_NAME VARCHAR2(10)
DEPT_NO NUMBER(5)
DATE_OF_JOIN DATE
CREATION OF VIEW
------------------------------
SQL> CREATE VIEW EMPVIEW AS SELECT
EMPLOYEE_NAME,EMPLOYEE_NO,DEPT_NAME,DEPT_NO,DATE_OF_JOIN FROM
EMPLOYEE;
VIEW CREATED.
DESCRIPTION OF VIEW
--------------------------------
SQL> DESC EMPVIEW;
DISPLAY VIEW:
----------------------
1 ROW CREATED.
DELETION OF VIEW:
DELETE STATEMENT:
SYNTAX:
SQL> DELETE <VIEW_NMAE>WHERE <COLUMN NMAE> =’VALUE’;
1 ROW DELETED.
UPDATE STATEMENT:
SYNTAX:
AQL>UPDATE <VIEW_NAME> SET< COLUMN NAME> = <COLUMN NAME> +<VIEW>
WHERE <COLUMNNAME>=VALUE;
1 ROW UPDATED.
DROP A VIEW:
SYNTAX:
SQL> DROP VIEW <VIEW_NAME>
EXAMPLE
VIEW DROPED
EXAMPLE-2:
SQL> CREATE OR REPLACE VIEW EMPL_VIEW1 AS SELECT EMPNO, ENAME,
SALARY FROM EMPL;
EXAMPLE-3:
SQL> CREATE OR REPLACE VIEW EMPL_VIEW2 AS SELECT * FROM EMPL WHERE
DEPTNO=10;
Note:
Replace is the keyboard to avoid the error “ora_0095:name is already used by an existing
abject”.
View created.
View created.
TYPE-2:
SQL> CREATE OR REPLACE VIEW EMP_TOTSAL AS SELECT EMPNO "EID",ENAME
"NAME",SALARY "SAL" FROM EMPL;
View created.
View created.
EXAMPLE-4:
SQL> CREATE OR REPLACE VIEW EMP_CK_OPTION AS SELECT
EMPNO,ENAME,SALARY,DEPTNO FROM EMPL WHERE DEPTNO
=10 WITH CHECK OPTION;
JOIN VIEW:
EXAMPLE-5:
SQL> CREATE OR REPLACE VIEW DEPT_EMP_VIEW AS SELECT A.EMPNO,
A.ENAME, A.DEPTNO, B.DNAME, B.LOC FROM EMPL
A,DEPMT B WHERE A.DEPTNO=B.DEPTNO;
View created.
FORCE VIEW:
EXAMPLE-6:
SQL> CREATE OR REPLACE FORCE VIEW MYVIEW AS SELECT * FROM XYZ;
Table created.
View created.
COMPILING A VIEW:
SYNTAX:
ALTER VIEW <VIEW_NAME> COMPILE;
EXAMPLE:
SQL> ALTER VIEW MYVIEW COMPILE;
RESULT: Thus the SQL commands for View has been verified and executed successfully.
AIM
To write a PL/SQL block using different control (if, if else, for loop, while loop,…)
statements.
OBJECTIVE:
PL/SQL Control Structure provides conditional tests, loops, flow control and branches that
PROCEDURE
STEP 1: Start
STEP 3: Develop the set of statements with the essential operational parameters.
STEP 6: Stop.
SQL> DECLARE
<VARIABLE DECLARATION>;
BEGIN
END;
SQL> declare
a number;
b number;
c number;
begin
a:=&a;
b:=&b;
c:=a+b;
dbms_output.put_line('sum of'||a||'and'||b||'is'||c);
end;
/
INPUT:
OUTPUT:
sum of23and12is35
PROCEDURE
STEP 1: Start
STEP 5: Stop.
SQL> DECLARE
<VARIABLE DECLARATION>;
BEGIN
IF(CONDITION)THEN
<EXECUTABLE STATEMENT >;
END;
DECLARE
b number;
c number;
BEGIN
B:=10;
C:=20;
if(C>B) THEN
dbms_output.put_line('C is maximum');
end if;
end;
/
OUTPUT:
C is maximum
SQL> DECLARE
<VARIABLE DECLARATION>;
BEGIN
IF (TEST CONDITION) THEN
<STATEMENTS>;
ELSE
<STATEMENTS>;
ENDIF;
END;
SQL> declare
n number;
begin
Input
Output:
entered number is less than 5
SQL> DECLARE
<VARIABLE DECLARATION>;
BEGIN
IF (TEST CONDITION) THEN
<STATEMENTS>;
ELSEIF (TEST CONDITION) THEN
<STATEMENTS>;
ELSE
<STATEMENTS>;
ENDIF;
END;
********** GREATEST OF THREE NUMBERS USING IF ELSEIF************
SQL> declare
a number;
b number;
c number;
d number;
begin
a:=&a;
b:=&b;
c:=&b;
if(a>b)and(a>c) then
dbms_output.put_line('A is maximum');
elsif(b>a)and(b>c)then
dbms_output.put_line('B is maximum');
else
dbms_output.put_line('C is maximum');
end if;
end;
/
INPUT:
OUTPUT:
C is maximum
SQL> DECLARE
<VARIABLE DECLARATION>;
BEGIN
LOOP
<STATEMENT>;
END LOOP;
<EXECUTAVLE STATEMENT>;
END;
SQL> declare
n number;
sum1 number default 0;
endvalue number;
begin
endvalue:=&endvalue;
n:=1;
for n in 1..endvalue
loop
if mod(n,2)=1
then
sum1:=sum1+n;
end if;
end loop;
dbms_output.put_line('sum ='||sum1);
end;
/
INPUT:
OUTPUT:
sum =4
SQL> DECLARE
<VARIABLE DECLARATION>;
BEGIN
WHILE <condition>
LOOP
<STATEMENT>;
END LOOP;
<EXECUTAVLE STATEMENT>;
END;
SQL> declare
n number;
sum1 number default 0;
endvalue number;
begin
endvalue:=&endvalue;
n:=1;
while(n<endvalue)
loop
sum1:=sum1+n;
n:=n+2;
end loop;
dbms_output.put_line('sum of odd no. bt 1 and' ||endvalue||'is'||sum1);
end;
/
INPUT:
old 6: endvalue:=&endvalue;
new 6: endvalue:=4;
OUTPUT:
RESULT:
Thus the PL/SQL block for different controls are verified and executed.
AIM
To write a PL/SQL block to display the student name, marks whose average mark is above 60%.
ALGORITHM
STEP1:Start
STEP3:Insert the values into the table and Calculate total and average of each student
STEP4: Execute the procedure function the student who get above 60%.
STEP6: End
EXECUTION
I) PROGRAM:
Output:
Procedure created.
II) PROGRAM:
Output:
Procedure created.
SQL> PRINT T
T
----------
99
III) PROGRAM:
SQL> create or replace procedure pro
is
a number(3);
b number(3);
c number(3);
d number(3);
begin
a:=&a;
b:=&b;
if(a>b) then
c:=mod(a,b);
if(c=0) then
dbms_output.put_line('GCD is');
dbms_output.put_line(b);
else
dbms_output.put_line('GCD is');
dbms_output.put_line(c);
end if;
else
d:=mod(b,a);
if(d=0) then
dbms_output.put_line('GCD is');
dbms_output.put_line(a);
else
dbms_output.put_line('GCD is');
dbms_output.put_line(d);
end if;
end if;
end;
/
Enter value for a: 8
old 8: a:=&a;
new 8: a:=8;
Enter value for b: 16
old 9: b:=&b;
new 9: b:=16;
Procedure created.
Table created
1 row created.
SQL> insert into student values (102,'surya', 99,77,69,81,99);
1 row created.
SQL> insert into student values (103,'suryapriya', 100,90,97,89,91);
1 row created.
SQL> select * from student;
SQL> declare
ave number(5,2);
tot number(3);
cursor c_mark is select*from student where mark1>=40 and mark2>=40 and
mark3>=40 and mark4>=40 and mark5>=40;
begin
dbms_output.put_line('regno name mark1 mark2 mark3 mark4 mark4 mark5 total
average');
dbms_output.put_line('-------------------------------------------------------------');
for student in c_mark
loop
tot:=student.mark1+student.mark2+student.mark3+student.mark4+student.mark5;
ave:=tot/5;
dbms_output.put_line(student.regno||rpad(student.name,15)
||rpad(student.mark1,6)||rpad(student.mark2,6)||rpad(student.mark3,6)
||rpad(student.mark4,6)||rpad(student.mark5,6)||rpad(tot,8)||rpad(ave,5));
end loop;
end;
/
SAMPLE OUTPUT
V) PROGRAM
14 rows selected.
Implicit curscors:
SQL> DECLARE
2 ena EMP.ENAME%TYPE;
3 esa EMP.SAL%TYPE;
4 BEGIN
5 SELECT ENAME,SAL INTO ENA,ESA FROM EMP
6 WHERE EMPNO = &EMPNO;
7 DBMS_OUTPUT.PUT_LINE('NAME :' || ENA);
8 DBMS_OUTPUT.PUT_LINE('SALARY :' || ESA);
9
10 EXCEPTION
11 WHEN NO_DATA_FOUND THEN
12 DBMS_OUTPUT.PUT_LINE('Employee no does not exits');
13 END;
14 /
Output:
Explicit Cursors:
SQL> DECLARE
2 ena EMP.ENAME%TYPE;
3 esa EMP.SAL%TYPE;
4 CURSOR c1 IS SELECT ename,sal FROM EMP;
5 BEGIN
6 OPEN c1;
7 FETCH c1 INTO ena,esa;
8 DBMS_OUTPUT.PUT_LINE(ena || ' salry is $ ' || esa);
9
10 FETCH c1 INTO ena,esa;
11 DBMS_OUTPUT.PUT_LINE(ena || ' salry is $ ' || esa);
12
13 FETCH c1 INTO ena,esa;
14 DBMS_OUTPUT.PUT_LINE(ena || ' salry is $ ' || esa);
15 CLOSE c1;
16 END;
17 /
Output:
RESULT:
Thus the PL/SQL block to display the student name,marks,average is verified and executed.
AIM
PROCEDURE
STEP 1: Start
STEP 4: Frame the searching procedure for both positive and negative searching.
STEP 5: Execute the Function for both positive and negative result .
STEP 6: Stop
EXECUTION
SQL>Declare
n number:=&n;
y number;
begin
y:=fnfact(n);
dbms_output.put_line(y);
end;
/
Function created.
II) PROGRAM
SQL> create table phonebook (phone_no number (6) primary key,username varchar2(30),doorno
varchar2(10),
street varchar2(30),place varchar2(30),pincode char(6));
Table created.
1 row created.
1 row created.
Function created.
SQL>declare
2 address varchar2(100);
3 begin
4 address:=findaddress(20312);
5 dbms_output.put_line(address);
6 end;
7 /
OUTPUT 1:
Vijay,120/5D,bharathi street,NGO colony,629002
SQL> declare
2 address varchar2(100);
3 begin
4 address:=findaddress(23556);
5 dbms_output.put_line(address);
6 end;
7 /
OUTPUT2:
Address not found
RESULT:Thus the Function for searching process has been executed successfully.
AIM
PROCEDURE
STEP 1: Start
STEP 6: Stop
CODING:
End Sub
End Sub
REGISTRATION FORM:
RESULT: Thus the program has been loaded and executed successfully.
AIM
To design a Single Document Interface and Multiple Document Interface forms using
Visual Basic.
PROCEDURE
STEP 1: Start
STEP 6: Stop
EXECUTION
End Sub
End Sub
Output:
SDI MDI MENU:
SDI MENU:
SDI ADDITION:
SDI DIVISION
SDI MULTIPLICATION
SDI SUBRACTION
MDI MENU:
MDI ADD:
MDI MUL:
MDI DIV
MDI SUB
RESULT: Thus the program has been loaded and executed successfully.
AIM
To develop and execute a Trigger for Before and After update, Delete, Insert operations on a
table.
PROCEDURE
STEP 1: Start
STEP 3:Specify the operations (update, delete, insert) for which the trigger has to be
executed.
STEP 4: Execute the Trigger procedure for both Before and After sequences
STEP 5: Carryout the operation on the table to check for Trigger execution.
STEP 6: Stop
EXECUTION
1. Create a Trigger to pop-up the DML operations
Table created.
1 row created.
1 row created.
Trigger created.
1 row created.
1 row updated.
1 row deleted.
2. Create a Trigger to check the age valid or not Using Message Alert
Table created.
NAME CHAR(10)
AGE NUMBER(3)
PROGRAM:
Trigger created.
NAME AGE
---------- ----------
abc 15
xyz -12
3. Create a Trigger to check the age valid and Raise appropriate error code and
error message.
AGE NUMBER(3)
NAME AGE
---------- ----------
abc 10
4. Create a Trigger for EMP table it will update another table SALARY while
inserting values.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
RESULT: Thus the Trigger procedure has been executed successfully for both before
and after sequences.
AIM
PROCEDURE
STEP 1: Start
STEP 2: Create the form with essential controls and insert the menu using menu editor.
STEP 6: Stop
EXECUTION
Coding:
Private Sub ab_Click()
RichTextBox1.SelFontName = "Arial Black"
End Sub
End Sub
RichTextBox1.SelText = Clipboard.GetText
MsgBox Clipboard.GetText
End Sub
Output:
File Menu:
Edit Menu
Format Menu:
RESULT: Thus the program has been loaded and executed successfully.
AIM
PROCEDURE
STEP 1: Start
STEP 2: Create the form with essential controls and insert the menu using menu editor.
STEP 6: Stop
EXECUTION
Unload Me
End Sub
Unload Me
frmLogin.Show
End Sub
ProgressBar1.Value = ProgressBar1.Value + 1
login.Show
Unload Me
End If
End Sub
ProgressBar2.Value = ProgressBar2.Value + 1
MsgBox ("welcome")
login.Show
Unload Me
End If
End Sub
Unload Me
Stock.Show
Else
End If
End Sub
End
End Sub
frmDataEnv.Show
Unload Me
End If
End Sub
Stock Form:
Adodc1.Recordset.AddNew
Text1.Text = a
Text2.Text = B
Text3.Text = C
D = InputBox("ENTER SUPPLIER")
Text4.Text = D
Text5.Text = e
Text6.Text = F
Text7.Text = G
Text8.Text = H
Text8.Text = Val(Text7.Text) / 14
Text9.SetFocus
'Adodc1.Recordset.Save
'MsgBox ("UPDATED")
End Sub
Dim s As String
a = Trim(a)
Adodc1.Recordset.Delete
MsgBox ("deleted")
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
End Sub
Adodc1.Recordset.MoveNext
End Sub
'dodc1.Recordset.MoveNext
Adodc1.Recordset.MoveNext
Else
Adodc1.Recordset.MovePrevious
End If
End Sub
'dodc1.Recordset.MovePrevious
Adodc1.Recordset.MoveFirst
Else '
Adodc1.Recordset.MoveNext
End If
End Sub
Dim a As String
Adodc1.Recordset.MoveFirst
Adodc1.Recordset.Find s
If Adodc1.Recordset.EOF Then
End If
End Sub
Adodc1.Recordset.Update
MsgBox ("UPDATED")
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
End Sub
Adodc1.Recordset.MoveFirst
End Sub
Dim a As String
Adodc1.Recordset.MoveFirst
Adodc1.Recordset.Find s
'Adodc1.Recordset ("select * from t1 where [ITEM_CODE] = " & Text1.Text(0) & "")
DataReport1.Show
If Adodc1.Recordset.EOF Then
End If
End Sub
Adodc1.Recordset.Update
End Sub
Dim s As String
a = Trim(a)
Adodc1.Recordset.Delete
MsgBox ("deleted")
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
End Sub
DataReport1.Show
End Sub
End
End Sub
'Adodc1.Recordset (" * from t1 where [ITEM_CODE] = " & Text1.Text(0) & "")
DataReport1.Show
End Sub
'Adodc2.Refresh
End Sub
DataReport1.Show
End Sub
Output:
Progress Bar
Login
Stock Form:
Report Design:
RESULT: Thus the program has been loaded and executed successfully.