Oracle SQL Developer
Oracle SQL Developer
Oracle SQL Developer
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Utilizing the Main Features of PL/<strong>SQL</strong>7.3.13 Working With PL/<strong>SQL</strong> Data StructuresData structure are composite data types that let you work with the essential propertiesof data without being too involved with details. After you design a data structure, youcan focus on designing algorithms that manipulate the data structure.7.3.13.1 Using CursorsA cursor is a name for a specific private <strong>SQL</strong> area in which information for processingthe specific statement is kept. PL/<strong>SQL</strong> uses both implicit and explicit cursors. PL/<strong>SQL</strong>implicitly declares a cursor for all <strong>SQL</strong> data manipulation statements on a set of rows,including queries that return only one row. You can explicitly declare a cursor for onerow, as shown in Example 7–10 on page 7-10 declares an explicit cursor.For queries that return more than one row, you can explicitly declare a cursor toprocess the rows individually. See Example 7–23.Example 7–23 Fetching With a CursorDECLARE -- declare variables and cursorsjobid employees.job_id%TYPE; -- variable for job_idlastname employees.last_name%TYPE; -- variable for last_nameCURSOR c1 IS SELECT last_name, job_id FROM employeesWHERE job_id LIKE '%CLERK';employees employees%ROWTYPE;-- record variable for rowCURSOR c2 is SELECT * FROM employeesWHERE job_id LIKE '%MAN' OR job_id LIKE '%MGR';BEGINOPEN c1; -- open the cursor before fetchingLOOPFETCH c1 INTO lastname, jobid; -- fetches 2 columns into variablesEXIT WHEN c1%NOTFOUND;DBMS_OUTPUT.PUT_LINE( RPAD(lastname, 25, ' ') || jobid );END LOOP;CLOSE c1;DBMS_OUTPUT.PUT_LINE( '-------------------------------------' );OPEN c2;LOOPFETCH c2 INTO employees; -- fetches entire row into the employees recordEXIT WHEN c2%NOTFOUND;DBMS_OUTPUT.PUT_LINE( RPAD(employees.last_name, 25, ' ') ||employees.job_id );END LOOP;CLOSE c2;END;/In Example 7–23, LIKE is used to specify the records to return with the query. Forinformation on LIKE, see Restricting Data Using the WHERE Clause.See Also: PL/<strong>SQL</strong> User's Guide and Reference for information onmanaging cursors with PL/<strong>SQL</strong>7.3.13.2 Using CollectionsPL/<strong>SQL</strong> collection types let you declare high-level data types similar to arrays, sets,and hash tables found in other languages. In PL/<strong>SQL</strong>, array types are known asvarrays (short for variable-size arrays), set types are known as nested tables, and hashtable types are known as associative arrays. Each kind of collection is an orderedgroup of elements, all of the same type. Each element has a unique subscript thatPL/<strong>SQL</strong>: Usage Information 7-17