Q1) By which year the target of 50% GER in Higher Education has to be achieved?
Q35) By which year, the minimum degree qualification for teaching is going to be a 4-year integrated B.Ed. degree?
(maintained by Lakshmi Sarvani Videla, Former Assistant Professor, KLEF and now Computer Science Lecturer, SRR and CVR Government Degree College, Vijayawada
Q1) By which year the target of 50% GER in Higher Education has to be achieved?
The term byte stuf fing refers to
Data stuffing used wi th character oriented
hardware
Data stuffing used wi th bi t oriented hardware
Data stuffing used with both A and B
Data stuffing used wi th byte oriented hardware
_____________________________________________________________________________________
What does the URL need to access documents ?
I. Path name
II. Host name
III. DNS
IV. Retrieval method
V. Server port number
I, II, III
I, III, V
I, II, IV
III, IV, V
_____________________________________________________________________________________
The most popular way to materialize XML document is to use
DTD
XSLT
HTML
SOAP
_____________________________________________________________________________________
Output of XML document can be viewed as
Word processor
Web browser
Notepad
None of the
above
_____________________________________________________________________________________
XML
Can be used as a database
Cannot be used as a database
XML is not a database ,it is
language
None of these
_____________________________________________________________________________________
What is so great about XML?
Easy data exchange
High speed on
network
Both A and B
None of the above
_____________________________________________________________________________________
Let most segment of a name inn DNS represents
Individual
Network
Individual
computer
Domain name
Network type
_____________________________________________________________________________________
How many root element can an XML document have ?
One
Two
Three
As many as the memory
provides
_____________________________________________________________________________________
The tags in XML are
Case insensitive
Case sensitive
Browser
dependent
None of these
_____________________________________________________________________________________
Which of the following attributes below are used for a font name?
Fontnam
e
fn
Font
Face
_____________________________________________________________________________________
Which of the following statement is true?
An XML document can have one root
element.
An XML document can have one child
element.
XML elements have to be in lower case.
All of the above.
_____________________________________________________________________________________
Which of the following statement is true?
All the statements are true.
All XML elements must have closing
tag.
All XML elements must be lower
case.
All XML documents must have a
DTD.
_____________________________________________________________________________________
CIDR stands for
Classified Internet Domain
Routing
Classless Inter Domain Routing
Classless Internet Domain
Routing
Classified Inter Domain Routing
_____________________________________________________________________________________
Which of the following protocol is not used in the internet?
Telnet
WIRL
HTTP
Goph
er
_____________________________________________________________________________________
The XML DOM object is
Entity
Entity reference
Comment
reference
Comment data
_____________________________________________________________________________________
Attributes in XML are
Elements inXML
Child nodes
A way of attaching characteristics or properties to elements of a
document
None of these
_____________________________________________________________________________________
XML uses the features of
HTML
XHTML
VML
SGML
_____________________________________________________________________________________
What are empty elements and is it valid?
No there is no such terms as empty
element
Empty elements are element with no
data
No it is not valid to use empty element
None of these
_____________________________________________________________________________________
Well formed XML document means
It contains a root element
It contain an element
It contains one or more elements
Must contain one or more elements and root element must contain all other
elements
_____________________________________________________________________________________
A header in CGI script can specify
Format of the document
New locat ion of the
document
A and B both
Start of the document
_____________________________________________________________________________________
In HTML URI is used to
Create a frame document
Create a image map in the webpage
Customize the image in the webpage
Identify a name or a resource on the
internet
_____________________________________________________________________________________
The MIME text file is saved with
HMT extension
HTML
extension
THM extension
None of these
_____________________________________________________________________________________
Namespace
Distinguishes one XML vocabulary from
another
Provides the spaces in the names
Is a querying language
None of these
_____________________________________________________________________________________
Microsoft XML schema data types for hexadecimal digits representing octates
UID
UXID
UUID
XXID
_____________________________________________________________________________________
XML DSOs has the property for the number of pages of data the recordset contains
Count
Number
Pagecount
Pagenumb
er
_____________________________________________________________________________________
Which type of web document is run at the client site
Static
Dynamic
Active
All of the
above
_____________________________________________________________________________________
FDDI (Fiber Distributed Data Interconnect) is an example of
Token ring
Token bus
Star topology
Multipoint
network
_____________________________________________________________________________________
Hardware that calculates CRC uses
Shift register
Xor unit
Both A and B
Instruction
register
_____________________________________________________________________________________
DOM is a
A parser
Specificatio
n
Coding style
None of
these
_____________________________________________________________________________________
MSXML is
A Microsoft language
XML parser that ships with
IE5.0
Used for interacting with XML
None of these
_____________________________________________________________________________________
Each list item in an ordered or unordered list has which tag?
List
tag
Is tag
Li tag
Ol tag
_____________________________________________________________________________________
What is XML?
Subset of SGML,Extensible Markup
Language
Superset of SGML,Extensible Markup
Language
Like SGML ,Extended Markup Language
None of these
_____________________________________________________________________________________
www is based on which model?
Local server
Client
server
3 tier
None of
these
_____________________________________________________________________________________
XML is a
Imperative
language
Declarative
language
Standard
None of these
_____________________________________________________________________________________
What is the use of web font in HTML?
That is the core font that is used to develop web pages
That enables to use fonts over the web without installation
That is the special font that is developed by Microsoft
corporation
All of the above
_____________________________________________________________________________________
Which of the following tags below are used for multi line text input control?
Textml tag
Text tag
Textarea
tag
Both a and
b
_____________________________________________________________________________________
Which tags are commonly used by search engines?
Headings
Title
Paragrap
h
All of
these
_____________________________________________________________________________________
The HTML tags are enclosed within
Curly braces
Parentheses
Angle
brackets
Square
brackets
_____________________________________________________________________________________
BCC in the internet refers to
Black carbon copy
Blind carbon copy
Blank carbon copy
Beautiful carbon
copy
_____________________________________________________________________________________
All exceptions in Java are subclasses of built in class called
Exceptio
n
Error
Throwabl
e
Raise
_____________________________________________________________________________________
Which Layer is not present in TCP/ IP model?
Application
Layer
Internet Layer
Transport Layer
Presentation
Layer
_____________________________________________________________________________________
Which of the following identifies a specific web page and its computer on the Web?
Web site
Web site
address
URL
Domain Name
_____________________________________________________________________________________
Node in XML is
Any part of the document whether it is elements ,attributes or
otherwise
Referred only to the attributes
Referred to the top element in the document
None of these
_____________________________________________________________________________________
XML document can be viewed in
IE 3.0
IE 2.0
IE 6.0
IE
X.0
_____________________________________________________________________________________
DMSP stands for
Distributed Mail System Protocol
Distributed Message System
Protocol
Distributed Message System Pool
Distributed Mail System Pool
_____________________________________________________________________________________
The main function of a browser is to
Compile HTML
Interpret HTML
De-compile HTML
Interpret CGI
programs
_____________________________________________________________________________________
Characteristic encoding is
Method used to represent numbers in a
character
Method used to represent character in a
number
Not a method
None of these
_____________________________________________________________________________________
The web standard allows programmers on many different computer platforms to dispersed format and display the information server.These programs are called
Web browsers
HTML
Internet
Explorer
None of these
_____________________________________________________________________________________
XPATH used to
Address your documents by specifying a location
path
Address the server
Store the IP of the server
None of these
_____________________________________________________________________________________
Unl ike Ipv4, Ipv6 does not include the following field in the base header
Next Header field
Field for Fragmentation
information
Flow Label
Kind field
#include <stdio.h> main() { int x=1,y=3; if(x ^ y) printf("x is not equal to y"); else printf("x is equal to y"); }
Questions on Arithmetic operators 1. A computer programming contest requires teams of 5 members each. Write a program that asks for the number of players and then give the number of teams and number of players leftover? 2. Find the number of months and leftover when the number of days are given (assume each month has only 30 days) 3. https://www.hackerrank.com/challenges/combo-meal/submissions/code/112740245 4. Number of questions on modulus operator can be explained
Questions on Assignment operator Explanation: different types of assignments a =10, a =b, a= b+c 1. Swap two variables
Questions on Logical Operators
// Input an integer number and check whether
// it is divisible by 9 or 7. #include <stdio.h> int main() { int num; //input number printf("Enter an integer number: "); scanf("%d", &num); //check the condition if(num%9==0 || num%7==0) printf("%d is divisible by 9 or 7\n",num); else printf("%d is not divisible by 9 or 7\n",num); return 0; }
// Input gender in single character and print full gender // (Ex: if input is 'M' or 'm' - it should print "Male"). #include <stdio.h> int main() { char gender; //input gender printf("Enter gender (m/M/f/F): "); scanf("%c", &gender); //check the condition and print gender if(gender=='m' || gender=='M') printf("Gender is Male"); else if(gender=='f' || gender=='F') printf("Gender is Female"); else printf("Unspecified gender"); return 0; }
#include <stdio.h>
#include<stdlib.h>
int main()
{
FILE *fp1,*fp2;
fp1=fopen("input.txt","r");
fp2=fopen("output.txt","w");
char ch;
fseek(fp1,-1,SEEK_END);
while(1)
{
ch=fgetc(fp1);
fputc(ch,fp2);
if(fseek(fp1,-2,SEEK_CUR) <0)
break;
}
fclose(fp1);
fclose(fp2);
return 0;
}
======(OR) =====
#include <stdio.h>
#include<stdlib.h>
int main()
{
FILE *fp1,*fp2;
fp1=fopen("input.txt","r");
fp2=fopen("output.txt","w");
char ch;
int c,i=1;
fseek(fp1,0,SEEK_END);
for(c=ftell(fp1);i<=c;i++)
{
fseek(fp1,-i,SEEK_END);
ch=fgetc(fp1);
fputc(ch,fp2);
}
fclose(fp1);
fclose(fp2);
return 0;
}
INDEX
S.No. |
Date |
Experiment |
Page No. |
1 |
|
Create
a table employee (empno,empname, address, deptno, salary) Write
the queries for the following (i)
Display all the records of the employee table (ii)
Display empno ,empname, and salary of all the employees
in the employee table (iii)
Display all the records of the employees from
department number 1. (iv)
Display the empno and name of all the employees from
deptno2 (v)
Display empno,empname ,deptno and salary in the
descending order of Salary (vi)
Display the empno and name of employees whose salary
is between 2000 and 5000 (vii)
Change the salary of the employee to 25000 whose salary
is 2000 (viii)
Change the address of a particular employee (ix)
Display the details of all the employee whose name
starts with ‘S’. (x) Display the
details of all the employees whose name ends with ‘a’ |
2-4 |
2 |
|
Create
two tables Student (rollno,
sname, dno) Department (dno,
dname) With
primary key and foreign key relationships and check the integrity constraint.
(i)
Write a query to display the rollno, sname, dno, and
dname for all students. |
5-6 |
3 |
|
Demonstrate
ALTER TABLE statement to add, delete, or modify columns in an existing table.
(First, create a table ‘Products’ with pid, pname attributes – then, add
price and company attributes and work with them) |
7-8 |
4 |
|
Demonstrate
DROP TABLE and TRUNCATE TABLE commands (First, create a table ‘Suppliers’
with sno,sname and location attributes) |
9 |
5 |
|
Demonstrate
the following constraints (i) not null (ii) unique (iii) check (iv) default |
10-11 |
6 |
|
Write SQL queries to demonstrate
aggregate functions |
12-13 |
7 |
|
Write SQL queries to demonstrate set
operations |
14-15 |
8 |
|
Write a PL/SQL programme to find the
biggest of two numbers (use ‘if’ ) |
16 |
9 |
|
Write a PL/SQL programme to display all
the even numbers between 1 and 20 |
16 |
10 |
|
Write a PL/SQL programme to demonstrate
cursors |
17-18 |
11 |
|
Write a PL/SQL programme to demonstrate
procedures. |
19-20 |
12 |
|
Write a PL/SQL programme to demonstrate
functions |
21 |
13 |
|
Write a PL/SQL programme to demonstrate triggers. |
22-23 |
Experiment No: 1
create table employee(empno number(2), empname varchar2(10),
address varchar2(30), deptno number(2), salary number(6), PRIMARY KEY(empno));
Output:
Table Created.
insert
into employee values(01,'Arun','16/a Chittoor',02,2000);
1 row(s) inserted.
insert
into employee values(02,'Ravi','12/b Chittoor',01,2500);
1 row(s) inserted.
insert
into employee values(03,'Asha','18/a Chittoor',02,5000);
1 row(s) inserted.
(i)
Display
all the records of the employee table
Select
* from employee;
EMPNO |
EMPNAME |
ADDRESS |
DEPTNO |
SALARY |
1 |
Arun |
16/a
Chittoor |
2 |
2000 |
2 |
Ravi |
12/b
Chittoor |
1 |
2500 |
3 |
Asha |
18/a
Chittoor |
2 |
5000 |
(ii)
Display
empno ,empname, and salary of all the employees in the employee table
select
empno,empname,salary from employee;
EMPNO |
EMPNAME |
SALARY |
1 |
Arun |
2000 |
2 |
Ravi |
2500 |
3 |
Asha |
5000 |
(iii)
Display
all the records of the employees from department number 1.
select * from employee where deptno =
01;
EMPNO |
EMPNAME |
ADDRESS |
DEPTNO |
SALARY |
2 |
Ravi |
12/b
Chittoor |
1 |
2500 |
(iv)
Display
the empno and name of all the employees from deptno2
select empno,empname from employee
where deptno = 02;
EMPNO |
EMPNAME |
1 |
Arun |
3 |
Asha |
(v)
Display
empno,empname ,deptno and salary in the descending order of Salary
select empno,empname,deptno,salary from employee order by salary
desc;
EMPNO |
EMPNAME |
DEPTNO |
SALARY |
3 |
Asha |
2 |
5000 |
2 |
Ravi |
1 |
2500 |
1 |
Arun |
2 |
2000 |
(vi)
Display
the empno and name of employees whose salary is between 2000 and 5000
select empno,empname from employee where salary between 2000 and
5000;
EMPNO |
EMPNAME |
1 |
Arun |
2 |
Ravi |
3 |
Asha |
(vii)
Change
the salary of the employee to 25000 whose salary is 2000
update employee set salary = 25000 where salary = 2000;
1 row(s) updated.
Select * from employee;
EMPNO |
EMPNAME |
ADDRESS |
DEPTNO |
SALARY |
1 |
Arun |
16/a
Chittoor |
2 |
25000 |
2 |
Ravi |
12/b
Chittoor |
1 |
2500 |
3 |
Asha |
18/a
Chittoor |
2 |
5000 |
(viii)
Change the address of a particular
employee
update employee set address = '15/c Chittoor' where address =
'12/b Chittoor';
1 row(s) updated.
Select * from employee;
EMPNO |
EMPNAME |
ADDRESS |
DEPTNO |
SALARY |
1 |
Arun |
16/a
Chittoor |
2 |
25000 |
2 |
Ravi |
15/c
Chittoor |
1 |
2500 |
3 |
Asha |
18/a
Chittoor |
2 |
5000 |
insert into employee values(4,'Shami','11/a Chittoor',1,34000);
1 row(s) inserted.
Select * from employee;
EMPNO |
EMPNAME |
ADDRESS |
DEPTNO |
SALARY |
1 |
Arun |
16/a
Chittoor |
2 |
25000 |
2 |
Ravi |
15/c
Chittoor |
1 |
2500 |
3 |
Asha |
18/a
Chittoor |
2 |
5000 |
4 |
Shami |
11/a
Chittoor |
1 |
34000 |
(ix)
Display the details of all the employee
whose name starts with ‘S’.
select * from employee where empname like 'S%';
EMPNO |
EMPNAME |
ADDRESS |
DEPTNO |
SALARY |
4 |
Shami |
11/a
Chittoor |
1 |
34000 |
(x)
Display
the details of all the employees whose name ends with ‘a’
select * from employee where empname like '%a';
EMPNO |
EMPNAME |
ADDRESS |
DEPTNO |
SALARY |
3 |
Asha |
18/a
Chittoor |
2 |
5000 |
Experiment No: 2
Create two tables
Student (rollno, sname, dno)
Department (dno, dname)
With
primary key and foreign key relationships and check the integrity constraint.
(i)
Write a query to display the rollno, sname, dno, and
dname for all students.
create table department(dno number(2), dname varchar2(20), PRIMARY KEY(dno));
Table created.
Insert one by one
insert into department values(1,'MATHS');
insert into department values(2,'English');
insert into department values(3,'Computers');
select * from department;
DNO |
DNAME |
1 |
MATHS |
2 |
English |
3 |
Computers |
create table student(rollno number(10), sname varchar2(20), dno number(2),
PRIMARY KEY(rollno), FOREIGN KEY(dno) references department(dno));
Table created.
Insert one by one
insert into student values(1501,'Hari',1);
insert into student values(1601,'Balu',2);
insert into student values(1701,'Siraj',3);
select * from student;
ROLLNO |
SNAME |
DNO |
1501 |
Hari |
1 |
1601 |
Balu |
2 |
1701 |
Siraj |
3 |
insert into student values(1801,'Saini',4);
ORA-02291:
integrity constraint (SYSTEM.SYS_C004050) violated - parent key not found
(i)
Write
a query to display the rollno, sname, dno, and dname for all students.
select student.*, department.dname from department, student where
department.dno = student.dno;
ROLLNO |
SNAME |
DNO |
DNAME |
1501 |
Hari |
1 |
MATHS |
1601 |
Balu |
2 |
English |
1701 |
Siraj |
3 |
Computers |
Experiment No: 3
Demonstrate ALTER
TABLE statement to add, delete, or modify columns in an existing table. (First,
create a table ‘Products’ with pid, pname attributes – then, add price and
company attributes and work with them)
Creating
Table:
create table products(pid number(2), pname varchar2(20));
Table created.
Alter
Command to ADD:
alter table products ADD price number(10);
Table altered.
Description
Command:
desc products;
Table |
Column |
Data Type |
Length |
Precision |
|||||
Number |
- |
2 |
|||||||
|
Varchar2 |
20 |
- |
||||||
|
Number |
- |
10 |
||||||
|
Alter
Command to DROP Column:
alter table
products DROP COLUMN price;
Table
dropped.
desc products;
Alter
Command to modify Column:
alter
table products modify pid varchar2(10);
Table altered.
desc products;
Experiment No: 4
Demonstrate DROP
TABLE and TRUNCATE TABLE commands (First, create a table ‘Suppliers’ with
sno,sname and location attributes)
create table suppliers(sno number(6), sname varchar2(20), location varchar2(30));
Table created.
Insert one by one
insert into suppliers values(01,'Dany','Chennai');
insert into suppliers values(02,'Kane','Mumbai');
insert into suppliers values(03,'Rahul','Bangalore');
select * from suppliers;
SNO |
SNAME |
LOCATION |
1 |
Dany |
Chennai |
2 |
Kane |
Mumbai |
3 |
Rahul |
Bangalore |
desc suppliers;
Table |
Column |
Data Type |
Length |
Precision |
Number |
- |
6 |
||
|
Varchar2 |
20 |
- |
|
|
Varchar2 |
30 |
- |
truncate table suppliers;
Table truncated.
select * from suppliers;
no data found
desc suppliers;
Table |
Column |
Data Type |
Length |
Precision |
Number |
- |
6 |
||
|
Varchar2 |
20 |
- |
|
|
Varchar2 |
30 |
- |
drop table suppliers;
Table dropped.
select * from suppliers;
ORA-00942: table or view does not exist
Experiment No: 5
Demonstrate the
following constraints
1.
not
null
2.
unique
3.
check
4.
default
Create Table Query:
create
table OFFICE(sno number(3) NOT NULL, id number(3) UNIQUE, name varchar2(20),
age number CHECK(age>25), branch varchar2(10) DEFAULT 'CS');
Table created.
insert into OFFICE values(1,101,'Siraj',26,'IT');
1 row(s) inserted.
(1)
NOT NULL
insert into OFFICE values(NULL,102,'Saran',26,'IT');
ORA-01400: cannot
insert NULL into ("SYSTEM"."OFFICE"."SNO")
(2)
UNIQUE
insert
into OFFICE values(02,102,'Saran',26,'IT');
1 row(s) inserted.
insert
into OFFICE values(03,102,'Samad',28,'IT');
ORA-00001: unique constraint
(SYSTEM.SYS_C004053) violated
select
* from OFFICE;
SNO |
ID |
NAME |
AGE |
BRANCH |
1 |
101 |
Siraj |
26 |
IT |
2 |
102 |
Saran |
26 |
IT |
(3)
CHECK
insert
into OFFICE values(03,103,'Samad',24,'DS');
ORA-02290: check
constraint (SYSTEM.SYS_C004052) violated
(4)
DEFAULT
insert
into OFFICE(sno,id,name,age) values(03,103,'Samad',27);
1 row(s) inserted.
select
* from OFFICE;
SNO |
ID |
NAME |
AGE |
BRANCH |
1 |
101 |
Siraj |
26 |
IT |
2 |
102 |
Saran |
26 |
IT |
3 |
103 |
Samad |
27 |
CS |
Experiment No: 6
Write SQL queries to demonstrate aggregate
functions
Create Table Query:
create
table samples(product varchar2(20), price number(5));
Insert one by one
insert
into samples values('rice',56);
insert
into samples values('sugar',36);
insert
into samples values('Salt',18);
select
* from samples;
PRODUCT |
PRICE |
rice |
56 |
sugar |
36 |
Salt |
18 |
COUNT
Function
select
COUNT(*) from samples;
COUNT(*) |
3 |
select
COUNT(product) from samples;
COUNT(PRODUCT) |
3 |
MAX Function
select
MAX(price) from samples;
MAX(PRICE) |
56 |
MIN
Function
select
MIN(price) from samples;
MIN(PRICE) |
18 |
SUM
Function
select
SUM(price) from samples;
SUM(PRICE) |
110 |
AVG
Function
select
AVG(price) from samples;
AVG(PRICE) |
36.6666666666666666666666666666666666667 |
STDDEV
Function
select
STDDEV(price) from samples;
STDDEV(PRICE) |
19.0087699058443372313948904094805429921 |
VARIANCE
Function
select
VARIANCE(price) from samples;
VARIANCE(PRICE) |
361.333333333333333333333333333333333334 |
Experiment No: 7
Write SQL queries to demonstrate set
operations
Create Table Query:
create
table ibm(harddisk varchar2(20), speed varchar2(10), OS varchar2(30));
Table created.
Insert one by one
insert
into ibm values('20gb','500Mhz','Linux');
1 row(s) inserted.
insert
into ibm values('40gb','800Mhz','Windows');
1 row(s) inserted.
insert
into ibm values('80gb','1Ghz','Windows');
1 row(s) inserted.
select
* from ibm;
HARDDISK |
SPEED |
OS |
20gb |
500Mhz |
Linux |
40gb |
800Mhz |
Windows |
80gb |
1Ghz |
Windows |
Create Table Query:
create
table dell(harddisk varchar2(20), speed varchar2(10), OS varchar2(30));
Table created.
Insert one by one
insert
into dell values('20gb','500Mhz','Linux');
1 row(s) inserted.
insert
into dell values('40gb','1Ghz','Windows');
1 row(s) inserted.
select
* from dell;
HARDDISK |
SPEED |
OS |
20gb |
500Mhz |
Linux |
40gb |
1Ghz |
Windows |
SET Operations
(1) UNION
select
* from ibm UNION select * from dell;
HARDDISK |
SPEED |
OS |
20gb |
500Mhz |
Linux |
40gb |
1Ghz |
Windows |
40gb |
800Mhz |
Windows |
80gb |
1Ghz |
Windows |
(2) INTERSECT
select
* from ibm INTERSECT select * from dell;
HARDDISK |
SPEED |
OS |
20gb |
500Mhz |
Linux |
(3) MINUS
select * from
ibm MINUS select * from dell;
HARDDISK |
SPEED |
OS |
40gb |
800Mhz |
Windows |
80gb |
1Ghz |
Windows |
Experiment No: 8
Write a PL/SQL programme to find the
biggest of two numbers (use ‘if’ )
DECLARE
a number;
b number;
BEGIN
a := 100;
b := 20;
IF a>b THEN
dbms_output.put_line(a||' is
bigger');
ELSE
dbms_output.put_line(b||' is
bigger');
END IF;
END;
OUTPUT:
100 is bigger
Statement processed.
Experiment No: 9
Write a PL/SQL programme to display all
the even numbers between 1 and 20
DECLARE
a number;
BEGIN
a := 1;
WHILE a<21 LOOP
IF (mod(a,2) = 0) THEN
dbms_output.put_line(a);
END IF;
a := a + 1;
END LOOP;
END;
OUTPUT:
2
4
6
8
10
12
14
16
18
20
Statement processed.
Experiment No: 10
A
Cursor is a temporary work area created in the memory of the system when a DML
statement is executed.
For
Example, if the user wants data from the database, we execute a query in SQL as
SELECT
eid, ename FROM Employees.
A
Cursor can hold more than one row. The set of all these rows that the cursor
holds is
called
an active set. But... A Cursor can process only one row at a time.
There
are four attributes used with Cursors :
1)
%FOUND
2)
%NOTFOUND
3)
%ROWCOUNT
4)
%ISOPEN
When
these attributes are added to the cursor variable, they return some information
about the
execution
of the SQL Statement.
1)
%FOUND
As the
cursor processes one row at a time, if the cursor variable is appended with
%FOUND
if the
row was fetched successfully---It returns True
Otherwise ----It returns False
Note :
Before the first fetch from an open cursor, %FOUND returns NULL
2.
%ROWCOUNT: It returns the number of records fetched from the cursor at that
particular instance of time.
Note :
When a
cursor is opened, %ROWCOUNT becomes zero . This means before the first fetch
from an open cursor, %ROWCOUNT returns 0.
3.
%ISOPEN: If the cursor is open-----It returns True
Otherwise ----It returns False
Two
Types of Cursors :
1)
Implicit Cursors : Implicit Cursors are created by default by the system when
any DML statement gets executed.
2)
Explicit Cursors : Explicit cursors must be created by us when we execute a
SELECT statement that returns one or more rows.
Uses
of Cursors:
1.
We
can perform Row wise validation
2.
Operations
on each row
Write PL/SQL
program to display id, name and address of each customer using cursors
DECLARE
c_id customers.id%type;
c_name customers.name%type;
c_addr customers.address%type;
CURSOR c_customers is
SELECT id, name, address FROM customers;
BEGIN
OPEN c_customers;
LOOP
FETCH c_customers into c_id, c_name, c_addr;
EXIT WHEN c_customers%notfound;
dbms_output.put_line(c_id || ' ' ||
c_name || ' ' || c_addr);
END LOOP;
CLOSE c_customers;
END;
/
When the above
code is executed at the SQL prompt, it produces the following result −
1 Ramesh
Ahmedabad
2 Khilan
Delhi
3 kaushik
Kota
4 Chaitali
Mumbai
5 Hardik
Bhopal
6 Komal MP
PL/SQL procedure
successfully completed.
Experiment No: 11
PROCEDURE
A
procedure is a module that consists of a group of PL/SQL statements performs a
task; it does not return any value. But, values can be passed into the
procedure or fetched from the procedure through parameters. Procedures cannot
be called directly from SELECT statements. They can be called from another
block or through EXECUTE keyword.
Creating a Procedure
Basic syntax of creating a
procedure in PL/SQL:
CREATE [OR REPLACE ] PROCEDURE procedure_name
(parameter_list)
[IS | AS]
[declaration statements]
BEGIN
[execution statements]
EXCEPTION
[exception handler]
END [procedure_name ];
Where,
CREATE
PROCEDURE instructs the compiler to
create new procedure. Keyword 'OR REPLACE' instructs the compiler to
replace the existing procedure (if any) with the current one.
Procedure name
should be unique.
If the
procedure is standalone then 'AS' will be used. Keyword 'IS' will
be used, when the procedure is written in some other blocks.
Each parameter can be in either IN, OUT,
or INOUT mode. The parameter mode specifies whether a parameter can be
read from or write to.
o IN represents
that value will be passed from outside into the procedure. It is a read-only
parameter. It is the default mode of parameter passing. Parameters are
passed by reference.
o OUT represents
that this parameter will be used to return a value outside of the procedure. It
is a write-only parameter. One can change its value and reference the value
after assigning it. The actual parameter must be variable and it is passed by
value.
o An INOUT parameter
is both readable and writable. The procedure can read and modify it.
Standalone or Stored
Procedure
The procedures that are stored
in a database as database object and can be accessible throughout the database.
Creating a Standalone
Procedure
The following example creates a
simple procedure that displays the string ‘***Welcome to the AP CCE LMS***’ on
the screen when executed.
CREATE OR REPLACE PROCEDURE greetings
AS
BEGIN
DBM S_OUTPUT.PUT_LINE(‘***Welcome to the AP CCE LMS***’);
END;
/
When above code is executed
using SQL prompt, it will produce the following result:
Procedure created.
Executing a Standalone Procedure
A standalone procedure can be
called in two ways:
Using the EXECUTE keyword
Calling the name of the
procedure from a PL/SQL block
The above procedure named
'greetings' can be called with the EXECUTE keyword as:
EXECUTE greetings;
The above call would display:
‘***Welcome to the AP CCE LMS***’
PL/SQL procedure
successfully completed.
Write a PL/SQL program to to create an Oracle
procedure that takes the name as input and prints the welcome message as
output. We are going to use EXECUTE command to call procedure.
CREATE OR REPLACE PROCEDURE welcome_msg (p_name IN VARCHAR2)
IS
BEGIN
dbms_output.put_line (‘Welcome '|| p_name);
END;
/
EXECUTING PROCEDURE:
EXECUTE welcome_msg (‘Guru99’);
OUTPUT:
Welcome Guru99
Experiment No: 12
Functions is a
standalone PL/SQL subprogram. Like PL/SQL procedure, functions have a unique
name by which it can be referred. These are stored as PL/SQL database objects.
Procedure
Vs. Function: Key Differences
Procedure |
Function |
|
|
|
|
|
|
|
|
|
|
|
|
Write a PL/SQL
programme to demonstrate functions.
CREATE OR
REPLACE FUNCTION totalcustomers
RETURN NUMBER IS
total NUMBER(2) := 0;
BEGIN
SELECT COUNT(*) INTO total FROM emp1;
RETURN total;
END;
O/P: Function created.
To use Function:
DECLARE
c NUMBER(2);
BEGIN
c := totalcustomers();
dbms_output.put_line('Total number of customers:'||c);
END;
O/P:
Total number of customers:4
Statement processed.
Experiment No: 13
Triggers in oracle are blocks of PL/SQL code which oracle engine can
execute automatically based on some action or event.
Triggers are automatically and repeatedly called upon by oracle engine
on satisfying certain condition. If triggers are activated then they are
executed implicitly by oracle engine.
Whenever a trigger is created, it contains the following three
sequential parts:
1. Triggering
Event or Statement: The statements due to which a trigger occurs.
2. Trigger
Restriction: The condition or any limitation applied on the trigger. If
condition is TRUE then trigger fires. Not all triggers has conditions.
3. Trigger
Action: The body containing the executable statements that is to be executed
when trigger fires.
Types of Triggers
1)
Level Triggers
a) ROW
LEVEL TRIGGERS: It fires for every record that got affected. It always use a
FOR EACH ROW clause
b) STATEMENT
LEVEL TRIGGERS: It fires once for each statement that is executed.
2)
Event Triggers
a) DDL
EVENT TRIGGER: It fires with the execution of every DDL statement(CREATE,
ALTER, DROP, TRUNCATE).
b) DML
EVENT TRIGGER: It fires with the execution of every DML statement(INSERT,
UPDATE, DELETE).
c) DATABASE
EVENT TRIGGER: It fires with the execution of every database operation which
can be LOGON, LOGOFF, SHUTDOWN, SERVERERROR etc.
3)
Timing Triggers
a) BEFORE
TRIGGER: It fires before executing DML statement.
b) AFTER
TRIGGER: It fires after executing DML statement.
Example : Create a trigger that fires after insert of every
new row in Stu table. The trigger automatically updates total.
create table Stu(id int, subj1 int,subj2
int,subj3 int,total int);
Table created.
Insert values
insert into Stu(id,subj1,subj2,subj3)
values(1,30,25,62);
ID |
SUBJ1 |
SUBJ2 |
SUBJ3 |
1 |
30 |
25 |
62 |
Output:
select * from Stu;
ID |
SUBJ1 |
SUBJ2 |
SUBJ3 |
TOTAL |
1 |
30 |
25 |
62 |
Create Trigger Command:
create or replace trigger stud_marks
after INSERT
on
Stu
for each row
begin
update Stu set total = subj1 + subj2 +
subj3;
end;
/
Output:
select * from Stu;
ID |
SUBJ1 |
SUBJ2 |
SUBJ3 |
TOTAL |
1 |
30 |
25 |
62 |
117 |