Assignment - 2: Nuzaiff Ather 27181 Bscs - 4 C
Assignment - 2: Nuzaiff Ather 27181 Bscs - 4 C
Assignment - 2: Nuzaiff Ather 27181 Bscs - 4 C
NUZAIFF ATHER
27181
BSCS – 4 C
SUBMITTED TO:
Implicit Cursors:
SQL cursors are managed automatically by PL/SQL. You need not write code to
handle these cursors. However, you can track information about the execution of
an SQL cursor through its attributes.
Using SQL%FOUND
DECLARE
BEGIN
END IF;
END;
/
Using SQL%ROWCOUNT
DECLARE
BEGIN
DBMS_OUTPUT.PUT_LINE
END;
Using SQL%NOTFOUND
When you require exact control over question handling, you can expressly announce a
cursor in the revelatory part of any PL/SQL piece, subprogram, or bundle.
Using SQL%FOUND
DECLARE
CURSOR c1 IS SELECT last_name, salary FROM employees WHERE ROWNUM < 11;
my_ename employees.last_name%TYPE;
my_salary employees.salary%TYPE;
BEGIN
OPEN c1;
LOOP
EXIT;
END IF;
END LOOP;
END;
Declare
name employees.last_name%TYPE;
BEGIN
OPEN c1;
LOOP
IF c1%ROWCOUNT = 5 THEN
END IF;
END LOOP;
CLOSE c1;
END;
Using %NOTFOUND
DECLARE
FROM employees
my_ename employees.last_name%TYPE;
my_salary employees.salary%TYPE;
BEGIN
OPEN c1;
LOOP
EXIT;
DBMS_OUTPUT.PUT_LINE
END IF;
END LOOP;
END;
b. User can only perform DML operations between 9:00AM and 5:00PM .
Q) What is the difference between views and materialized views? Explain with SQL
exmaples.
VIEWS:
View is a logical or virtual memory which is based on select query and the simple view is
the view in which we cannot make DML command if the View is created by multiple
tables.
FROM CUSTOMERS;
Now, you can query CUSTOMERS_VIEW in similar way as you query an actual table. Following is the
example:
+----------+-----+
| name | age |
+----------+-----+
| Ramesh | 32 |
| Khilan | 25 |
| kaushik | 23 |
| Chaitali | 25 |
| Hardik | 27 |
| Komal | 22 |
| Muffy | 24 |
+----------+-----+
Materialized VIEWS:
Materialized view is a concept mainly used in Detaware housing. These views contain
the data itself .Reason being it is easier/faster to access the data. The main purpose of
Materialized view is to do calculations and display data from multiple tables using Joins .
CREATE MATERIALIZED VIEW MV_Test
NOLOGGING
CACHE
BUILD IMMEDIATE
REFRESH FAST ON COMMIT
AS
SELECT V.*, P.*, V.ROWID as V_ROWID, P.ROWID as P_ROWID, (2+1) as Calc1,
'Constant1' as Const1
FROM TPM_PROJECTVERSION V
INNER JOIN TPM_PROJECT P ON P.PROJECTID = V.PROJECTID
Now instead of running this same query everytime you can just run this simpler query against your
new view which will run faster. The really cool thing is that you can also add derived and calculated
columns too.