PL/SQL Cursors | PL/SQL Tutorial pdf

PL/SQL Cursors
We can manipulate the information within a SQL statement by means of assigning a name to a "select statement", this concept is known a cursor. A cursor is used for processing individual rows returned as a result for a query.

Oracle PL/SQL  Implicit Cursors Oracle PL/SQL Implicit Cursors
Oracle PL/SQL Explicit Cursors Oracle PL/SQL Explicit Cursors
Oracle PL/SQL Cursor For Loops Oracle PL/SQL Cursor For Loops
Oracle PL/SQL Cursors With Parameters Oracle PL/SQL Cursors With Parameters
Oracle PL/SQL REF Cursors Oracle PL/SQL REF Cursors
Oracle PL/SQL WHERE CURRENT OF & FOR UPDATE Oracle PL/SQL WHERE CURRENT OF & FOR UPDATE
Examples of Oracle PL/SQL Cursors Examples of Oracle PL/SQL Cursors

Examples of Oracle PL/SQL Cursors:
1) Retrieving the records from the emp table and displaying them one by one using cursors:
CREATE OR REPLACE PROCEDURE my_proc IS
var_empno emp.empno%type;
var_ename emp.ename%type;
var_sal emp.sal%type;

//declaring a cursor//
CURSOR EMP_CURSOR IS
select empno, ename, sal from emp;
BEGIN

//opening a cursor//
open EMP_CURSOR;
LOOP

//fetching records from a cursor//
fetch EMP_CURSOR into var_empno, var_ename, var_sal;

//testing exit conditions//
EXIT when EMP_CURSOR%NOTFOUND;
IF (var_sal > 1000) then
DBMS_OUTPUT.put_line(var_empno || ' ' || var_ename || ' ' || var_sal);
ELSE
DBMS_OUTPUT.put_line(var_ename || ' sal is less then 1000');
END IF;
END LOOP;

//closing the cursor//
close EMP_CURSOR;
DBMS_OUTPUT.put_line('DONE');

END;

1 comments:

Unknown said...

Hello Mate,

Your writing shines! There is no room for gibberish here clearly you have explained about Pl/sql. Keep writing!

WITH PlantParameter AS(SELECT regexp_substr('a,b','[^,]+', 1, LEVEL) AS ParameterValue FROM dual
CONNECT BY regexp_substr('a,b','[^,]+', 1, LEVEL) IS NOT NULL)

SELECT * FROM Table1 WHERE td.PLANTID IN (SELECT ParameterValue FROM PlantParameter)) /*Paramater*/

in the above example i am passing multi values to the query and handling them by using CTE which split's the entire string to values and these values are used in the below query.this functionality is reducing query performance and it is taking more time to fetch results is there any ways to improve query execution time .My main goal is to pass multi values and i am doing it by using CTE but this is reducing performance of query is there any other way that can be suggested.






Once again thanks for your tutorial.


Cheers,
Radhey

Post a Comment

Blogger news